public void PlayEmailAutomation(IMailClient client, string username, string password, bool isProtocolImap, string mailbox) { string retValue = string.Empty; int countMail = 0; retValue = client.LogIn(username, password); if (string.IsNullOrEmpty(retValue)) { retValue = client.GetTotalMail(out countMail, mailbox); if (string.IsNullOrEmpty(retValue)) { if (countMail > 0) { var _messagesIndexs = GetMailIndex(client, mailbox); //: GetPopMailIndex(countMail); _messagesIndexs = (from p in _messagesIndexs orderby p descending select p).ToList(); PerformAction(client, _messagesIndexs); } else { client.LogOut(); ((IDisposable)client).Dispose(); } } } if (!string.IsNullOrEmpty(retValue)) { throw new Exception(retValue); } }
public void PlayEmailAutomation(IMailClient client, string username, string password, string searchCriteria, string mailbox) { string retValue = string.Empty; int countMail = 0; retValue = client.LogIn(username, password); if (string.IsNullOrEmpty(retValue)) { retValue = client.GetTotalMail(out countMail, mailbox); if (string.IsNullOrEmpty(retValue)) { if (countMail > 0) { var _messagesIndexs = GetMailIndex(client, searchCriteria, mailbox); _messagesIndexs = (from p in _messagesIndexs orderby p descending select p).ToList(); PerformAction(client, _messagesIndexs, mailbox); } else { client.LogOut(); ((IDisposable)client).Dispose(); } } } if (!string.IsNullOrEmpty(retValue)) { throw new Exception(retValue); } }
public void PlayEmailAutomation() { retValue = new StringBuilder("--------Start--------\r\n\r\n"); int countMail = 0; ((ITraceable)client).LogTrace += new TraceEventHandler(TraceLog); ProgressValueChangeEventArgs pvce = new ProgressValueChangeEventArgs() { MinValue = 0, MaxValue = 4 }; StatusChangeEventArgs sce = new StatusChangeEventArgs() { CurrentStatus = "Connecting " + client.GetHostName() + "...", PreviousStatus = "--------Start--------" }; OnStatusChanged(sce); var result = client.Login(username, password); if (string.IsNullOrEmpty(result)) { pvce.Value = 1; OnProgressValueChanged(pvce); sce.CurrentStatus = "Authenticating client..."; sce.PreviousStatus = retValue.ToString(); OnStatusChanged(sce); pvce.Value = 2; OnProgressValueChanged(pvce); sce.CurrentStatus = "Selecting Inbox..."; sce.PreviousStatus = retValue.ToString(); OnStatusChanged(sce); if (string.IsNullOrEmpty(result)) { pvce.Value = 3; OnProgressValueChanged(pvce); sce.CurrentStatus = "Getting total mail from Inbox..."; sce.PreviousStatus = retValue.ToString(); OnStatusChanged(sce); result = client.GetTotalMail(out countMail); if (string.IsNullOrEmpty(result)) { if (countMail > 0) { sce.CurrentStatus = "Getting mail detail from Inbox..."; sce.PreviousStatus = retValue.ToString(); OnStatusChanged(sce); IEnumerable <int> msgIds = null; result = client.GetAllMessageFlags(MailFlag.All, out msgIds); if (!string.IsNullOrEmpty(result)) { TerminateEmailAutomation("Problem in getting mail(s).", retValue.ToString()); } } pvce.Value = 4; OnProgressValueChanged(pvce); sce.CurrentStatus = "Logout from Inbox..."; sce.PreviousStatus = retValue.ToString(); OnStatusChanged(sce); client.LogOut(); sce.CurrentStatus = "Logout completed..."; sce.PreviousStatus = retValue.ToString(); OnStatusChanged(sce); } else { TerminateEmailAutomation("Problem in getting mail count.", retValue.ToString()); } } else { TerminateEmailAutomation("Problem in getting mail count.", retValue.ToString()); } ((IDisposable)client).Dispose(); ((ITraceable)client).LogTrace -= new TraceEventHandler(TraceLog); } }