/// <summary> /// Copies the specified message to the specified folder /// </summary> /// <param name="msg">The message to copy</param> /// <param name="destFolder">The folder to copy the message to</param> public void CopyMessageToFolder(IMAPMessage msg, IMAPFolder destFolder) { if (_client.OfflineMode) { _client.Log(IMAPBase.LogTypeEnum.WARN, "Cannot copy messages in offline mode."); return; } string cmd = "UID COPY {0} \"{1}\"\r\n"; ArrayList result = new ArrayList(); _client._imap.SendAndReceive(String.Format(cmd, msg.Uid, destFolder.FolderPath), ref result); foreach (string s in result) { if (s.Contains("OK")) { // if the copy was successful, tell the destination folder to refresh its message UID list. destFolder.GetMessageIDs(false); int msgCount = destFolder.Messages.Count; // the copy function puts the new message at the end of the folder so lets automatically // load the data for the copy. If for some reason during the folder refresh another new message // was found and added making the copied message not the last one in the folder, thats ok // because as soon as the content is accessed the data will be loaded automatically if (msgCount > 0) { destFolder.Messages[msgCount - 1].RefreshData(msg.ContentLoaded, true); } _client.UpdateCache(true); _client.Log(IMAPBase.LogTypeEnum.INFO, String.Format("Message with UID {0} successfully copied to folder \"{1}\"", msg.Uid, destFolder.FolderName)); break; } } }
/// <summary> /// Copies all messages in this folder to the specified folder /// </summary> /// <param name="destFolder">The destination folder all the messages should be copied to</param> public void CopyAllMessagesToFolder(IMAPFolder destFolder) { if (_client.OfflineMode) { _client.Log(IMAPBase.LogTypeEnum.WARN, "Cannot copy messages in offline mode."); return; } if (!this.IsCurrentlySelected) { this.Select(); } string cmd = "UID COPY {0}:{1} \"{2}\"\r\n"; ArrayList result = new ArrayList(); int firstMsg = _messages[0].Uid; int lastMsg = _messages[_messages.Count - 1].Uid; cmd = String.Format(cmd, firstMsg, lastMsg, destFolder.FolderPath); _client._imap.SendAndReceive(cmd, ref result); // TODO: Need to find a way to determine what the UIDs of the copies are and instead of having // to pull the same messages from the server again, just copy the IMAPMessage objects and update // the UID to the new value. This is possible if copying one message at a time, but is not as // easy when copying messages in bulk. foreach (string s in result) { if (s.Contains("OK")) { destFolder.GetMessageIDs(false); _client.UpdateCache(true); _client.Log(IMAPBase.LogTypeEnum.INFO, String.Format("All Messages from {0} successfully copied to {1}.", this.FolderName, destFolder.FolderName)); break; } } }