public virtual object[] GetOldMessagesUids(int daysCount) { Folder fld = GetFolder(FolderType.Inbox); WebMailMessageCollection coll = _dbMan.SelectMessagesOlderThanXDays(daysCount, fld); return(coll.ToUidsCollection(true)); }
private void GetNewMessagesFromServerAndSaveToDb(DbStorage dbStorage, Folder fld, int[] Indexes, out bool errorOccured, ref ArrayList pop3Uids) { _folderName = Utils.GetLocalizedFolderNameByType(fld); _msgNumber = 1; _msgsCount = Indexes.Length; MailMessageCollection mailMessageCollection = new MailMessageCollection(); // const int maxMsgsPersession = Constants.DownloadChunk; try { foreach (int index in Indexes) { // int downloadMsgsCount = ((_msgsCount) > maxMsgsPersession) ? maxMsgsPersession : _msgsCount; if ((_msgsCount) > 0) { if ((fld.SyncType == FolderSyncType.NewEntireMessages) || (fld.SyncType == FolderSyncType.AllEntireMessages)) { mailMessageCollection.Add(_pop3Obj.DownloadEntireMessage(index)); // mailMessageCollection = _pop3Obj.DownloadEntireMessages(newMsgStartIndex + 1, downloadMsgsCount); } if ((fld.SyncType == FolderSyncType.NewHeadersOnly) || (fld.SyncType == FolderSyncType.AllHeadersOnly)) { mailMessageCollection.Add(_pop3Obj.DownloadMessageHeader(index)); // mailMessageCollection = _pop3Obj.DownloadMessageHeaders(newMsgStartIndex + 1, downloadMsgsCount); } if (!_updatedFolders.ContainsKey(fld.ID)) { _updatedFolders.Add(fld.ID, fld.FullPath); } } } WebMailMessageCollection coll = new WebMailMessageCollection(_account, mailMessageCollection, true, fld); ApplyXSpam(coll); ApplyFilters(coll, dbStorage, fld, ref pop3Uids); if (_account.MailMode == MailMode.DeleteMessagesFromServer) { if ((fld.SyncType == FolderSyncType.AllHeadersOnly) || (fld.SyncType == FolderSyncType.NewHeadersOnly)) { Log.WriteLine("GetNewMessagesFromServerAndSaveToDb", "Incorrect Settings: " + _account.MailMode.ToString() + " + " + fld.SyncType.ToString()); } else { DeleteMessages(coll.ToUidsCollection(true), null); } } errorOccured = false; } catch (Exception ex) { errorOccured = true; Log.WriteException(ex); throw new WebMailException(ex); } _folderName = ""; _msgNumber = 0; _msgsCount = 0; }
public override WebMailMessageCollection LoadMessages(object[] messageIndexSet, Folder fld) { WebMailMessageCollection msgsColl = new WebMailMessageCollection(); foreach (string uid in messageIndexSet) { int index = _pop3Obj.GetMessageIndexFromUid(uid); if (index > 0) { try { WebMailMessage webMsg = new WebMailMessage(_account); webMsg.Init(_pop3Obj.DownloadEntireMessage(index), true, fld); msgsColl.Add(webMsg); } catch (MailBeeException ex) { Log.WriteException(ex); throw new WebMailMailBeeException(ex); } } else { continue; } } return(msgsColl); }
public override WebMailMessageCollection LoadMessages(Folder fld) { WebMailMessageCollection returnColl = new WebMailMessageCollection(); MailMessageCollection messages; try { messages = _pop3Obj.DownloadEntireMessages(); } catch (MailBeeException ex) { Log.WriteException(ex); throw new WebMailMailBeeException(ex); } if (messages != null) { foreach (MailMessage msg in messages) { WebMailMessage webMsg = new WebMailMessage(_account); webMsg.Init(msg, true, fld); returnColl.Add(webMsg); } } return(returnColl); }
public override WebMailMessageCollection LoadMessageHeaders(object[] messageIndexSet, Folder fld) { WebMailMessageCollection msgsColl = new WebMailMessageCollection(); foreach (object uid in messageIndexSet) { int index = _pop3Obj.GetMessageIndexFromUid(Convert.ToString(uid)); if (index > 0) { try { WebMailMessage webMsg = new WebMailMessage(_account); webMsg.Init(_pop3Obj.DownloadMessageHeader(index), true, fld); if (fld.SyncType == FolderSyncType.DirectMode) { webMsg.Seen = true; } msgsColl.Add(webMsg); } catch (MailBeeException ex) { Log.WriteException(ex); throw new WebMailMailBeeException(ex); } } else { continue; } } return(msgsColl); }
protected void DeleteFolderAndRelatedMessages(Folder fld) { WebMailMessageCollection msgs = _dbMan.SelectMessages(fld); _dbMan.DeleteMessages(ObjectsToInts32(msgs.ToIDsCollection())); _dbMan.DeleteFolder(fld.ID); }
public virtual WebMailMessage LoadMessage(object index, Folder fld, bool body_structure, MessageMode mode) { WebMailMessageCollection coll = LoadMessages(new object[] { index }, fld, body_structure, mode); if ((coll != null) && (coll.Count > 0)) { return(coll[0]); } return(null); }
public virtual WebMailMessage LoadMessage(object index, Folder fld) { WebMailMessageCollection coll = LoadMessages(new object[] { index }, fld, false, MessageMode.None); if ((coll != null) && (coll.Count > 0)) { return(coll[0]); } return(null); }
public override WebMailMessageCollection LoadMessageHeaders(int pageNumber, Folder fld) { WebMailMessageCollection result = null; if (_account != null) { result = _dbMan.SelectMessages(pageNumber, _account.DefaultOrder, fld); } else { Log.WriteLine("GetMessageHeaders", "Account is NULL"); } return(result); }
public override WebMailMessageCollection LoadMessageHeaders(int pageNumber, Folder fld) { object[] indexes = GetIndexesFromPageNumber(pageNumber); WebMailMessageCollection coll = LoadMessageHeaders(indexes, fld); if (fld.SyncType == FolderSyncType.DirectMode) { CollectionBase cb = coll as CollectionBase; if (cb != null) { Utils.ReverseCollection(ref cb); } } return(coll); }
protected void ApplyXVirus(WebMailMessageCollection messageCollection) { foreach (WebMailMessage webMsg in messageCollection) { MailMessage msg = webMsg.MailBeeMessage; if (msg != null) { HeaderCollection xvirusHeaders = msg.Headers.Items("x-virus"); if ((xvirusHeaders != null) && (xvirusHeaders.Count > 0)) { Header xvirus = xvirusHeaders[0]; if (string.Compare(xvirus.Value, "infected", false, CultureInfo.InvariantCulture) == 0) { webMsg.XVirus = true; } else { webMsg.XVirus = false; } } } } }
protected void ApplyXSpam(WebMailMessageCollection messageCollection) { foreach (WebMailMessage webMsg in messageCollection) { MailMessage msg = webMsg.MailBeeMessage; if (msg != null) { HeaderCollection xspamHeaders = msg.Headers.Items("x-spam"); if ((xspamHeaders != null) && (xspamHeaders.Count > 0)) { Header xspam = xspamHeaders[0]; if ((string.Compare(xspam.Value, "probable spam", false, CultureInfo.InvariantCulture) == 0) || (string.Compare(xspam.Value, "suspicious", false, CultureInfo.InvariantCulture) == 0)) { webMsg.XSpam = true; } else { webMsg.XSpam = false; } } } } }
protected void ApplyFilters(WebMailMessageCollection messageCollection, DbStorage dbStorage, Folder fld, ref ArrayList arr) { Filter[] filters = dbStorage.GetFilters(); if (_account.MailIncomingProtocol == IncomingMailProtocol.WMServer) { ArrayList allFiltersArr = new ArrayList(); Folder virusFolder = dbStorage.GetFolder(FolderType.Quarantine); if (virusFolder != null) { Filter fltVirus = new Filter(0, _account.ID, FilterField.XVirusHeader, FilterCondition.BeginsWithSubstring, "infected", FilterAction.MoveToFolder, virusFolder.ID, true); allFiltersArr.Add(fltVirus); } Folder spamFolder = dbStorage.GetFolder(FolderType.Spam); if (spamFolder != null) { Filter flt = new Filter(0, _account.ID, FilterField.XSpamHeader, FilterCondition.BeginsWithSubstring, "spam", FilterAction.MoveToFolder, spamFolder.ID, true); allFiltersArr.Add(flt); } if (filters.Length > 0) { foreach (Filter flt in filters) { allFiltersArr.Add(flt); } } Filter[] allFilters = (Filter[])allFiltersArr.ToArray(typeof(Filter)); // if (filters.Length > 0) filters.CopyTo(allFilters, 0); filters = allFilters; } int id_msg = dbStorage.GetLastMsgID(); foreach (WebMailMessage webMsg in messageCollection) { id_msg = Utils.RandMsgID(++id_msg); bool needToSave = true; if (fld.Type == FolderType.Inbox) { foreach (Filter flt in filters) { if (flt.Applied == false) { continue; } FilterAction action = flt.GetActionToApply(webMsg); switch (action) { case FilterAction.DeleteFromServerImmediately: { object[] messageIndexSet = new object[] { -1 }; if (_account.MailIncomingProtocol != IncomingMailProtocol.Imap4) { messageIndexSet[0] = webMsg.StrUid; } else if (_account.MailIncomingProtocol == IncomingMailProtocol.Imap4) { messageIndexSet[0] = webMsg.IntUid; } DeleteMessages(messageIndexSet, fld); needToSave = false; break; } case FilterAction.MoveToFolder: if (needToSave) { Folder toFld = dbStorage.GetFolder(flt.IDFolder); if (toFld != null) { if (fld.FullPath != toFld.FullPath) { if (_account.MailIncomingProtocol == IncomingMailProtocol.WMServer) { WmServerFS wmserverFS = new WmServerFS(_account); webMsg.StrUid = wmserverFS.MoveMessage(webMsg.StrUid, fld.FullPath, toFld.FullPath); } } dbStorage.SaveMessage(id_msg, webMsg, toFld); if (!_updatedFolders.ContainsKey(toFld.ID)) { _updatedFolders.Add(toFld.ID, toFld.FullPath); } } needToSave = false; } break; case FilterAction.MarkGrey: webMsg.Grayed = true; break; } } } if (needToSave) { dbStorage.SaveMessage(id_msg, webMsg, fld); } arr.Add((webMsg.IntUid > 0) ? (object)webMsg.IntUid : webMsg.StrUid); } }
public virtual void SaveMessages(WebMailMessageCollection messages, Folder fld) { }
public override void SaveMessages(WebMailMessageCollection messages, Folder fld) { _dbMan.SaveMessages(messages, fld); }
public override Dictionary <long, string> Synchronize(FolderCollection foldersTree) { DbStorage dbStorage = DbStorageCreator.CreateDatabaseStorage(_account); FolderCollection folders = new FolderCollection(); FolderCollection.CreateFolderListFromTree(ref folders, foldersTree); ArrayList pop3Uids = new ArrayList(); bool downloadErrorOccured = false; Folder fld = folders[FolderType.Inbox]; if (fld != null) { if (fld.SyncType == FolderSyncType.DirectMode) { if (!_updatedFolders.ContainsKey(fld.ID)) { _updatedFolders.Add(fld.ID, fld.FullPath); } return(_updatedFolders); } if (fld.SyncType == FolderSyncType.DontSync) { return(_updatedFolders); } try { dbStorage.Connect(); // get new messages start index string[] pop3DbUids = dbStorage.GetUids(); string[] pop3ServerUids = _pop3Obj.GetMessageUids(); ArrayList dbUidsToDelete = new ArrayList(); ArrayList pop3ServerIndexesToDownload = new ArrayList(); foreach (string pop3DbUid in pop3DbUids) { if (Array.IndexOf(pop3ServerUids, pop3DbUid) == -1) { dbUidsToDelete.Add(pop3DbUid); } } foreach (string pop3ServerUid in pop3ServerUids) { if (Array.IndexOf(pop3DbUids, pop3ServerUid) == -1) { pop3ServerIndexesToDownload.Add(_pop3Obj.GetMessageIndexFromUid(pop3ServerUid)); } } if ((_account.MailMode == MailMode.KeepMessagesOnServer) || (_account.MailMode == MailMode.KeepMessagesOnServerAndDeleteMessageWhenItsRemovedFromTrash)) { object[] serverUidsToDelete = dbStorage.GetOldMessagesUids(_account.MailsOnServerDays); // delete from server if (serverUidsToDelete.Length > 0) { DeleteMessages(serverUidsToDelete, fld); } } // retrieve new messages GetNewMessagesFromServerAndSaveToDb(dbStorage, fld, (int[])pop3ServerIndexesToDownload.ToArray(typeof(int)), out downloadErrorOccured, ref pop3Uids); if ((fld.SyncType == FolderSyncType.NewEntireMessages) || (fld.SyncType == FolderSyncType.NewHeadersOnly)) { return(_updatedFolders); } // delete messages from db if (dbUidsToDelete.Count > 0) { WebMailMessageCollection msgsToDelete = dbStorage.LoadMessagesByUids((string[])dbUidsToDelete.ToArray(typeof(string)), fld, false); dbStorage.DeleteMessages(msgsToDelete.ToIDsCollection(), fld); if (!_updatedFolders.ContainsKey(fld.ID)) { _updatedFolders.Add(fld.ID, fld.FullPath); } } } finally { if (!downloadErrorOccured) { // get all uids and save it to db pop3Uids = ArrayList.Adapter(_pop3Obj.GetMessageUids()); dbStorage.ReplaceUids(pop3Uids.ToArray()); } else { dbStorage.SaveUids(pop3Uids.ToArray()); } dbStorage.Disconnect(); } } return(_updatedFolders); }