public void MoveMessageToFolder(string folderName, string messageTitle, string destenationFolder) { _client.SelectFolder(folderName); MessageIndexCollection uids = _client.Search(true, string.Format("SUBJECT {0}", messageTitle), null); if (uids.Count > 0) { _client.MoveMessages(uids.ToString(), true, destenationFolder); } }
private void SyncMailMessagesInFolder(string crmFolder, string rawName, Func <MailMessage, Envelope, bool, string, bool> syncAction) { _log.Info(string.Format("------ [{0}] | Mail synchronization in folder {1} STARTED. ------", _currentMailboxName, rawName)); bool getCurrentMailboxFoldersResult; _currentFolder = GetsCurrentMailboxFoldersCorrespondence(rawName, CurrentMailboxSettingsId.ToString(), out getCurrentMailboxFoldersResult); if (!getCurrentMailboxFoldersResult) { throw new ImapException(LocCanNotReadFolder.ToString()); } MessageIndexCollection msgIndexes = Strategy.GetUnsyncedMsgIndexes(_client, rawName); _log.Info(string.Format("[{0}] - [{1}] Sync query {2} - found {3} unsynchronized messages headers for ActivityFolderId {4}", _currentMailboxName, rawName, Strategy.GetUnsyncMsgSearchQuery(), msgIndexes.Count, _currentFolder.ActivityFolderId)); if (msgIndexes.Count > 0) { try { var remoteChangesCount = 0; decimal totalSize = 0m; var msgEnvelopes = _client.DownloadEnvelopes(msgIndexes.ToString(), true); _log.Info(string.Format("[{0}] - [{1}] | Load {2} unsynchronized messages", _currentMailboxName, rawName, msgEnvelopes.Count)); foreach (Envelope envelope in msgEnvelopes) { totalSize = SyncEnvelope(envelope, syncAction, crmFolder, totalSize); remoteChangesCount++; } _log.Info(string.Format("[{0}] - [{1}] | Processed {2} messages", _currentMailboxName, rawName, msgEnvelopes.Count)); _remoteChangesCount = remoteChangesCount; } catch (Exception ex) { _log.Error(string.Format("[{0}] - [{1}] | Error on folder sync: {2}", _currentMailboxName, rawName, ex.ToString())); } } List <long> messageIndexList = GetMsgIndexesList(msgIndexes); messageIndexList.Sort(); if (_currentFolder != null && messageIndexList.Count > 0) { _currentFolder.UId = messageIndexList.Last().ToString(); _log.Error($"[{_currentMailboxName}] - [{_currentFolder}] | Update folder UId '{_currentFolder.UId}' start." + $"ActivityFolderId = '{_currentFolder.ActivityFolderId}'"); SaveCurrentFolder(_currentFolder); _log.Error($"[{_currentMailboxName}] - [{_currentFolder}] | Update folder UId '{_currentFolder.UId}' end." + $"ActivityFolderId = '{_currentFolder.ActivityFolderId}'"); } _log.Info(string.Format("------ [{0}] | Mail synchronization in folder {1} COMPLETED. ------", _currentMailboxName, rawName)); }