public bool Equals(EmailMessage email) { if (email.GetHashCode().Equals(this.GetHashCode())) { return(true); } else { return(false); } }
public void retrieveMail(String mailbox = "INBOX") { currentMailBox = mailbox; MailList.Clear(); if (imapHost.Equals(null) || imapHost.Equals(null) || password.Equals(null)) { ALSMessageBox mb = new ALSMessageBox("Not logged in"); mb.Show(); return; } try { // The default port for IMAP over SSL is 993. using (ImapClient client = new ImapClient(imapHost, 993, username, password, AuthMethod.Login, true)) { folders = client.ListMailboxes(); Console.WriteLine("We are connected!"); // Returns a collection of identifiers of all mails matching the specified search criteria. IEnumerable<uint> uids = null; uids = client.Search(SearchCondition.All(), mailbox); // Download mail messages from the default mailbox. uint[] uidArray = uids.ToArray(); Array.Reverse(uidArray); uids = uids.Reverse(); if (uidArray.Length > DOWNLOAD_COUNT) Array.Resize(ref uidArray, DOWNLOAD_COUNT); IEnumerable<MailMessage> messages = client.GetMessages(uidArray, FetchOptions.NoAttachments, true, mailbox); IEnumerator<MailMessage> messageList = messages.GetEnumerator(); IEnumerator<uint> uidList = uids.GetEnumerator(); while (messageList.MoveNext()) { uidList.MoveNext(); string toAddress; try { toAddress = messageList.Current.To[0].Address; } catch { toAddress = "None"; } EmailMessage temp = new EmailMessage(messageList.Current.Subject, messageList.Current.Body, toAddress, messageList.Current.From.Address, EmailClient.Date(messageList.Current), uidList.Current); int hash = temp.GetHashCode(); bool contains = false; foreach (EmailMessage m in MailList) { if (m.GetHashCode().Equals(hash)) contains = true; } if (!contains) { bool added = false; int index = 0; if (MailList.Count == 0) { MailList.Add(temp); } else { while (!added && index < MailList.Count) { switch (MailList[index].CompareTo(temp)) { case -1: MailList.Insert(index, temp); added = true; break; case 0: MailList.Insert(index, temp); added = true; break; case 1: index++; break; case -99: //error code break; } } if (!added) MailList.Add(temp); } } } } MailList.Reverse(); } catch (InvalidCredentialsException) { }catch(System.Net.Sockets.SocketException e) { ALSMessageBox mb = new ALSMessageBox("Not connected to internet"); mb.Show(); }catch(Exception e) { ALSMessageBox mb = new ALSMessageBox("Unknown error occurred"); mb.Show(); } }
public bool Equals(EmailMessage email) { if (email.GetHashCode().Equals(this.GetHashCode())) return true; else return false; }
public void retrieveMail(String mailbox = "INBOX") { currentMailBox = mailbox; MailList.Clear(); if (imapHost.Equals(null) || imapHost.Equals(null) || password.Equals(null)) { ALSMessageBox mb = new ALSMessageBox("Not logged in"); mb.Show(); return; } try { // The default port for IMAP over SSL is 993. using (ImapClient client = new ImapClient(imapHost, 993, username, password, AuthMethod.Login, true)) { folders = client.ListMailboxes(); Console.WriteLine("We are connected!"); // Returns a collection of identifiers of all mails matching the specified search criteria. IEnumerable <uint> uids = null; uids = client.Search(SearchCondition.All(), mailbox); // Download mail messages from the default mailbox. uint[] uidArray = uids.ToArray(); Array.Reverse(uidArray); uids = uids.Reverse(); if (uidArray.Length > DOWNLOAD_COUNT) { Array.Resize(ref uidArray, DOWNLOAD_COUNT); } IEnumerable <MailMessage> messages = client.GetMessages(uidArray, FetchOptions.NoAttachments, true, mailbox); IEnumerator <MailMessage> messageList = messages.GetEnumerator(); IEnumerator <uint> uidList = uids.GetEnumerator(); while (messageList.MoveNext()) { uidList.MoveNext(); string toAddress; try { toAddress = messageList.Current.To[0].Address; } catch { toAddress = "None"; } EmailMessage temp = new EmailMessage(messageList.Current.Subject, messageList.Current.Body, toAddress, messageList.Current.From.Address, EmailClient.Date(messageList.Current), uidList.Current); int hash = temp.GetHashCode(); bool contains = false; foreach (EmailMessage m in MailList) { if (m.GetHashCode().Equals(hash)) { contains = true; } } if (!contains) { bool added = false; int index = 0; if (MailList.Count == 0) { MailList.Add(temp); } else { while (!added && index < MailList.Count) { switch (MailList[index].CompareTo(temp)) { case -1: MailList.Insert(index, temp); added = true; break; case 0: MailList.Insert(index, temp); added = true; break; case 1: index++; break; case -99: //error code break; } } if (!added) { MailList.Add(temp); } } } } } MailList.Reverse(); } catch (InvalidCredentialsException) { }catch (System.Net.Sockets.SocketException e) { ALSMessageBox mb = new ALSMessageBox("Not connected to internet"); mb.Show(); }catch (Exception e) { ALSMessageBox mb = new ALSMessageBox("Unknown error occurred"); mb.Show(); } }