public void OnRetrieveNewMessage(MailQueueItem account, ActiveUp.Net.Mail.Message message, int folder_id, string uidl, string md5_hash, bool has_parse_error, bool unread, int[] tags_ids) { MailMessageItem message_item; if (_mailBoxManager.MailReceive(account.Account, message, folder_id, uidl, md5_hash, has_parse_error, unread, tags_ids, out message_item) < 1) throw new Exception("MailReceive() returned id < 1;"); if (message_item == null) return; foreach (var handler in _messageHandlers) { try { handler.HandleRetrievedMessage(account.Account, message, message_item, folder_id, uidl, md5_hash, unread, tags_ids); } catch (Exception ex) { _log.Error(ex, "MailItemManager::OnRetrieveNewMessage"); } } }
public void OnRetrieveNewMessage(MailQueueItem account, ActiveUp.Net.Mail.Message message, int folder_id, string uidl, string md5_hash, bool has_parse_error, bool unread, int[] tags_ids) { MailMessageItem message_item; if (_mailBoxManager.MailReceive(account.Account, message, folder_id, uidl, md5_hash, has_parse_error, unread, tags_ids, out message_item) < 1) { throw new Exception("MailReceive() returned id < 1;"); } if (message_item == null) { return; } foreach (var handler in _messageHandlers) { try { handler.HandleRetrievedMessage(account.Account, message, message_item, folder_id, uidl, md5_hash, unread, tags_ids); } catch (Exception ex) { _log.Error(ex, "MailItemManager::OnRetrieveNewMessage"); } } }
private bool Equals(MailQueueItem other) { if (ReferenceEquals(null, other)) { return(false); } return(ReferenceEquals(this, other) || Equals(other.Account, Account)); }
public void SaveMessage(string user_id, int tenant_id, string email, string uidl) { var n_attempts = 0; do { try { if (string.IsNullOrEmpty(user_id)) { throw new Exception("user_id is empty"); } if (tenant_id < 0) { throw new Exception("tenant_id must have non-negative value"); } if (string.IsNullOrEmpty(email)) { throw new Exception("email is empty"); } if (string.IsNullOrEmpty(uidl)) { throw new Exception("uidl is empty"); } _log.Debug("user_id:\t'{0}'", user_id); _log.Debug("tenant_id:\t'{0}'", tenant_id); _log.Debug("email:\t\t'{0}'", email); _log.Debug("uidl:\t\t'{0}'", uidl); _log.Debug("Search for mailbox"); var mailbox = _manager.GetMailBox(tenant_id, user_id, new System.Net.Mail.MailAddress(email)); if (mailbox != null) { var s_message_path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format("message_{0}.eml", uidl)); _log.Debug("download path:\t'{0}'", s_message_path); var loader = new MailQueueItem(mailbox); loader.DownloadMessage(uidl, s_message_path); } else { _log.Info("Mailbox was not found!"); } return; } catch (Exception ex) { _log.Error("SaveMessage() Exception:\r\n{0}\r\n", ex.ToString()); _log.Debug("Attemp {0}/3", ++n_attempts); } } while (n_attempts < 4); }
public static MailQueueItem CreateItemForAccount(MailBox account, MailItemManager manager) { var item = new MailQueueItem(account); item.GetStoredMessagesUidlMd5 += manager.GetStoredMessagesUIDL_MD5; item.OnRetrieveNewMessage += manager.OnRetrieveNewMessage; item.OnUpdateUidl += manager.OnUpdateUidl; item.OnAuthSucceed += manager.OnAuthSucceed; item.OnAuthFailed += manager.OnAuthFailed; item.OnDone += manager.OnDone; item.OnTimeCheckedUpdate += manager.OnCheckedTimeUpdate; item.OnGetOrCreateTags += manager.OnGetOrCreateTags; item.OnUpdateMessagesTags += manager.OnUpdateMessagesTags; return item; }
public static MailQueueItem CreateItemForAccount(MailBox account, MailItemManager manager) { var item = new MailQueueItem(account); item.GetStoredMessagesUidlMd5 += manager.GetStoredMessagesUIDL_MD5; item.OnRetrieveNewMessage += manager.OnRetrieveNewMessage; item.OnUpdateUidl += manager.OnUpdateUidl; item.OnAuthSucceed += manager.OnAuthSucceed; item.OnAuthFailed += manager.OnAuthFailed; item.OnDone += manager.OnDone; item.OnTimeCheckedUpdate += manager.OnCheckedTimeUpdate; item.OnGetOrCreateTags += manager.OnGetOrCreateTags; item.OnUpdateMessagesTags += manager.OnUpdateMessagesTags; return(item); }
public void SaveMessage(string user_id, int tenant_id, string email, string uidl) { var n_attempts = 0; do { try { if (string.IsNullOrEmpty(user_id)) throw new Exception("user_id is empty"); if (tenant_id < 0) throw new Exception("tenant_id must have non-negative value"); if (string.IsNullOrEmpty(email)) throw new Exception("email is empty"); if (string.IsNullOrEmpty(uidl)) throw new Exception("uidl is empty"); _log.Debug("user_id:\t'{0}'", user_id); _log.Debug("tenant_id:\t'{0}'", tenant_id); _log.Debug("email:\t\t'{0}'", email); _log.Debug("uidl:\t\t'{0}'", uidl); _log.Debug("Search for mailbox"); var mailbox = _manager.GetMailBox(tenant_id, user_id, new System.Net.Mail.MailAddress(email)); if (mailbox != null) { var s_message_path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format("message_{0}.eml", uidl)); _log.Debug("download path:\t'{0}'", s_message_path); var loader = new MailQueueItem(mailbox); loader.DownloadMessage(uidl, s_message_path); } else _log.Info("Mailbox was not found!"); return; } catch (Exception ex) { _log.Error("SaveMessage() Exception:\r\n{0}\r\n", ex.ToString()); _log.Debug("Attemp {0}/3", ++n_attempts); } } while (n_attempts < 4); }
public void ItemCompleted(MailQueueItem item) { try { _log.Info("MailboxProcessingCompleted(MailBoxId: {0} Email: '{1}')\r\n", item.Account.MailBoxId, item.Account.EMail.Address); _manager.MailboxProcessingCompleted(item.Account); } catch (Exception e) { _log.Fatal("Collector.ItemCompleted(MailBoxId: {0} Email: '{1}') Exception: {2}\r\n", item.Account.MailBoxId, item.Account.EMail.Address, e.ToString()); } }
public void ItemError(MailQueueItem item, Exception exception) { try { _log.Info("MailboxProcessingError(MailBoxId: {0} Email: '{1}' Tenant: {2} User: '******' Exception:\r\n{4})\r\n", item.Account.MailBoxId, item.Account.EMail.Address, item.Account.TenantId, item.Account.UserId, exception.ToString()); _manager.MailboxProcessingError(item.Account, exception); } catch (Exception e) { _log.Fatal("Collector.ItemError(MailBoxId: {0} Email: '{1}' Tenant: {2} User: '******' ExceptionMessage: {4}) Exception:\r\n{5}\r\n", item.Account.MailBoxId, item.Account.EMail.Address, item.Account.TenantId, item.Account.UserId, exception.ToString(), e.ToString()); } }
public void OnDone(MailQueueItem item, bool quota_error) { _mailBoxManager.SetMailboxQuotaError(item.Account, quota_error); }
public DateTime GetFolderModifyDate(MailQueueItem account, int folder_id) { return(_mailBoxManager.GetMailboxFolderModifyDate(account.Account.MailBoxId, folder_id)); }
public void GetStoredMessagesUIDL_MD5(MailQueueItem account, Dictionary <int, string> uidl_list, Dictionary <int, string> md5_list) { _mailBoxManager.GetStoredMessagesUIDL_MD5(account.Account.MailBoxId, uidl_list, md5_list); }
public DateTime GetFolderModifyDate(MailQueueItem account, int folder_id) { return _mailBoxManager.GetMailboxFolderModifyDate(account.Account.MailBoxId, folder_id); }
public void GetStoredMessagesUIDL_MD5(MailQueueItem account, Dictionary<int, string> uidl_list, Dictionary<int, string> md5_list) { _mailBoxManager.GetStoredMessagesUIDL_MD5(account.Account.MailBoxId, uidl_list, md5_list); }
public MailQueueItem GetItem() { MailQueueItem result = null; try { while (true) { if (!_noTasks) { _log.Debug("Getting new Item..."); } MailBox mbox = null; var locked_in_this_thread = false; lock (SyncObject) { if (!_isGetMailboxRunning) { _isGetMailboxRunning = true; locked_in_this_thread = true; } } try { if (locked_in_this_thread && _isGetMailboxRunning) { mbox = _manager.GetMailboxForProcessing(_settings.ActivityTimeout); } } finally { if (locked_in_this_thread && _isGetMailboxRunning) { _isGetMailboxRunning = false; } } if (mbox == null) { if (!_noTasks) { _log.Debug("Nothing to do."); } _noTasks = true; break; } var absence = false; var type = HttpRuntime.Cache.Get(mbox.TenantId.ToString(CultureInfo.InvariantCulture)); if (type == null) { absence = true; try { type = _manager.GetTariffType(mbox.TenantId); } catch (Exception e) { _log.Error("Collector.GetItem() -> GetTariffType Exception: {0}", e.ToString()); type = MailBoxManager.TariffType.Active; } } else if (mbox.Active && (MailBoxManager.TariffType)type != MailBoxManager.TariffType.Active) { HttpRuntime.Cache.Remove(mbox.TenantId.ToString(CultureInfo.InvariantCulture)); absence = true; type = MailBoxManager.TariffType.Active; } TimeSpan delay; switch ((MailBoxManager.TariffType)type) { case MailBoxManager.TariffType.LongDead: delay = _settings.LongDeadAccountDelay; break; case MailBoxManager.TariffType.Overdue: delay = _settings.OverdueAccountDelay; break; default: delay = TimeSpan.FromDays(1); break; } if (absence) { HttpRuntime.Cache.Insert(mbox.TenantId.ToString(CultureInfo.InvariantCulture), type, null, DateTime.UtcNow.Add(delay), Cache.NoSlidingExpiration); } _noTasks = false; _log.Info("MailboxId: {0} is being processed. EMail: '{1}' User: '******' TenanntId: {3} ", mbox.MailBoxId, mbox.EMail.Address, mbox.UserId, mbox.TenantId); if ((MailBoxManager.TariffType)type == MailBoxManager.TariffType.LongDead || (MailBoxManager.TariffType)type == MailBoxManager.TariffType.Overdue) { _log.Info("Tenant {0} is not paid. Stop processing MailboxId: {1} EMail: '{2}'.", mbox.TenantId, mbox.MailBoxId, mbox.EMail.Address); _manager.SetNextLoginDelayedFor(mbox, delay); } else { _log.Debug("CreateItemForAccount()..."); result = MailItemQueueFactory.CreateItemForAccount(mbox, _itemManger); break; } } } catch (Exception e) { _log.Error("Collector.GetItem() Exception: {0}", e.ToString()); } return(result); }
private bool Equals(MailQueueItem other) { if (ReferenceEquals(null, other)) { return false; } return ReferenceEquals(this, other) || Equals(other.Account, Account); }