protected override void Poll() { bool emailDownloaded = false; Exception error = null; try { PollBegin(); using (Pop3 pop3 = new Pop3()) { switch (_sslType) { case SSLType.None: pop3.Connect(_host, _port); break; case SSLType.SSL: pop3.ConnectSSL(_host, _port); break; case SSLType.TLS: pop3.Connect(_host, _port); pop3.STLS(); break; } pop3.UseBestLogin(_username, _password); List <string> serverUids = pop3.GetAll(); MessageStoreCollection localMessageStore = MessageStoreManager.LoadLocalMessageStore(_username, _host); if (localMessageStore != null) { MessageStoreManager.RemoveMessagesNoLongerOnServer(ref localMessageStore, serverUids); List <string> uidsToCheck = MessageStoreManager.GetMessagesToCheck(localMessageStore, serverUids); foreach (string uid in uidsToCheck) { //string fileName; byte[] eml = pop3.GetMessageByUID(uid); IMail email = new MailBuilder().CreateFromEml(eml); //SpoolEmlViaDisk(pop3.GetMessageByUID(uid), out fileName); MessageStoreMessage theMessage = new MessageStoreMessage(uid); if (ProcessEmailAttachments(email) > 0) { emailDownloaded = true; //Only populate the extra data for game emails if (email.From.Count > 0) { theMessage.From = email.From[0].Address; } theMessage.Subject = email.Subject; if (email.Date.HasValue) { theMessage.Date = email.Date.Value.ToString(); theMessage.DateTicks = email.Date.Value.Ticks.ToString(); } //In case the email doesn't come down with a good date if (string.IsNullOrEmpty(theMessage.Date)) { DateTime stamp = DateTime.Now; theMessage.Date = stamp.ToString(); theMessage.DateTicks = stamp.Ticks.ToString(); } theMessage.FileName = GetAttachmentsString(email); } localMessageStore.Messages.Add(theMessage); //ClearSpooledEml(fileName); } } else { //New message store, add all currently on server localMessageStore = new MessageStoreCollection(serverUids); } MessageStoreManager.SaveLocalMessageStore(_username, _host, localMessageStore); localMessageStore.Dispose(); localMessageStore = null; pop3.Close(); } } catch (Exception ex) { error = ex; Trace.TraceError(ex.ToString()); Trace.Flush(); } finally { PollEnd(emailDownloaded, error); } }
protected override void Poll() { bool emailDownloaded = false; Exception error = null; try { PollBegin(); using (Imap imap = new Imap()) { switch (_sslType) { case SSLType.None: imap.Connect(_host, _port); break; case SSLType.SSL: imap.ConnectSSL(_host, _port); break; case SSLType.TLS: imap.Connect(_host, _port); imap.StartTLS(); break; } imap.UseBestLogin(_username, _password); imap.SelectInbox(); List <long> serverUids = imap.Search(Flag.Unseen); MessageStoreCollection localMessageStore = MessageStoreManager.LoadLocalMessageStore(_username, _host); if (localMessageStore != null) { MessageStoreManager.RemoveMessagesNoLongerOnServer(ref localMessageStore, serverUids); List <long> uidsToCheck = MessageStoreManager.GetMessagesToCheck(localMessageStore, serverUids); foreach (long uid in uidsToCheck) { //string fileName; byte[] eml = imap.GetMessageByUID(uid); IMail email = new MailBuilder().CreateFromEml(eml); //SpoolEmlViaDisk(imap.GetMessageByUID(uid), out fileName); if (ProcessEmailAttachments(email) > 0) { //We want the user to be able to go Mark as Unread > Poll > Redownload //So just mark as read but don't add to local message store emailDownloaded = true; imap.MarkMessageSeenByUID(uid); } else { localMessageStore.Messages.Add(new MessageStoreMessage(uid)); imap.MarkMessageUnseenByUID(uid); } //ClearSpooledEml(fileName); } } else { //New message store, add all unread currently on server localMessageStore = new MessageStoreCollection(serverUids); } MessageStoreManager.SaveLocalMessageStore(_username, _host, localMessageStore); localMessageStore.Dispose(); localMessageStore = null; imap.Close(); } } catch (Exception ex) { error = ex; Trace.TraceError(ex.ToString()); Trace.Flush(); } finally { PollEnd(emailDownloaded, error); } }