I'm working writing a script to migrate emails from one account to another. I'm having two issues.
The messages are moving over, but the mail client is showing their received date as the date/time it was moved (in the list of messages view), not the date/time that's showing in the message header. I'm guessing a file date isn't being retained?
The message flags aren't being copied over. Such as the message being read already. I'd like to see all of the flags being passed...basically I need to move the message as it exists on the previous account.
protected void CopyBtn_Click(object sender, EventArgs e) { try { ImapClient Client = new ImapClient(); ImapClient Client2 = new ImapClient(); Client.Connect(SourceHostBox.Text.Trim(), 993, SecureSocketOptions.SslOnConnect); Client.Authenticate(SourceUsernameBox.Text.Trim(), SourcePasswordBox.Text.Trim()); Client.Inbox.Open(FolderAccess.ReadWrite); Client2.Connect(DestinationHostBox.Text.Trim(), 993, SecureSocketOptions.SslOnConnect); Client2.Authenticate(DestinationUsernameBox.Text.Trim(), DestinationPasswordBox.Text.Trim()); Client2.Inbox.Open(FolderAccess.ReadWrite); var folders = Client.GetFolders(Client.PersonalNamespaces[0]); //move all messages in folders & create folders if necessary foreach (var folder in folders) { folder.Open(FolderAccess.ReadWrite); var uids = folder.Search(SearchQuery.All); foreach (var uid in uids) { var folders2 = Client2.GetFolders(Client2.PersonalNamespaces[0]); var message = folder.GetMessage(uid); string currentFolder = folder.ToString().Replace("INBOX.", ""); //Remove the 'INBOX.' text that's getting prepended by cPanel/Dovecot var toplevel = Client2.GetFolder(Client2.PersonalNamespaces[0]); var folderExists = FindFolder(toplevel, currentFolder); if (folderExists == null) toplevel.Create(currentFolder, true); Client2.GetFolder(currentFolder).Append(message); } } //move inbox messages Client.Inbox.Open(FolderAccess.ReadWrite); Client2.Inbox.Open(FolderAccess.ReadWrite); var inboxuids = Client.Inbox.Search(SearchQuery.All); foreach (var uid in inboxuids) { var message = Client.Inbox.GetMessage(uid); Client2.Inbox.Append(message); } label1.Text = "Finished Successfully."; label1.ForeColor = System.Drawing.Color.Green; } catch (Exception ex) { label1.Text = ex.Message; label1.ForeColor = System.Drawing.Color.Red; } }