/// <summary> /// Stores message to specified stream. /// </summary> /// <param name="stream">Stream where to store message.</param> /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception> /// <exception cref="ArgumentNullException">Is raised when argument <b>stream</b> value is null.</exception> /// <exception cref="InvalidOperationException">Is raised when message is marked for deletion and this method is accessed.</exception> /// <exception cref="POP3_ClientException">Is raised when POP3 serveer returns error.</exception> public void MessageToStream(Stream stream) { if (this.IsDisposed) { throw new ObjectDisposedException(this.GetType().Name); } if (stream == null) { throw new ArgumentNullException("Argument 'stream' value can't be null."); } if (this.IsMarkedForDeletion) { throw new InvalidOperationException("Can't access message, it's marked for deletion."); } m_Pop3Client.GetMessage(this.SequenceNumber, stream); }
/// <summary> /// Starts messages fetching. /// </summary> public void StartFetching() { if(m_Fetching){ return; } m_Fetching = true; try{ DataView dvUsers = m_pApi.GetUsers("ALL"); using(DataView dvServers = m_pApi.GetUserRemoteServers("")){ foreach(DataRowView drV in dvServers){ try{ if(!ConvertEx.ToBoolean(drV["Enabled"])){ continue; } // Find user name from user ID string userName = ""; dvUsers.RowFilter = "UserID='" + drV["UserID"] + "'"; if(dvUsers.Count > 0){ userName = dvUsers[0]["UserName"].ToString(); } else{ continue; } string server = drV.Row["RemoteServer"].ToString(); int port = Convert.ToInt32(drV.Row["RemotePort"]); string user = drV.Row["RemoteUserName"].ToString(); string passw = drV.Row["RemotePassword"].ToString(); bool useSSL = ConvertEx.ToBoolean(drV["UseSSL"]); // Connect and login to pop3 server using(POP3_Client clnt = new POP3_Client()){ clnt.SessionLog += new LogEventHandler(clnt_SessionLog); clnt.LogCommands = LogCommands; clnt.Connect(server,port,useSSL); clnt.Authenticate(user,passw,false); POP3_MessagesInfo messagesInfo = clnt.GetMessagesInfo(); foreach(POP3_MessageInfo messageInfo in messagesInfo.Messages){ // Download message byte[] message = clnt.GetMessage(messageInfo.MessageNumber); // Store message m_pServer.ProcessUserMsg("","",userName,"Inbox",new MemoryStream(message),null); // Delete message clnt.DeleteMessage(messageInfo.MessageNumber); } } } catch{ } } } m_LastFetch = DateTime.Now; } catch(Exception x){ Error.DumpError(m_pServer.Name,x); } m_Fetching = false; }