Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

message DATE problem #146

Open
haider001 opened this issue Jun 20, 2018 · 1 comment
Open

message DATE problem #146

haider001 opened this issue Jun 20, 2018 · 1 comment

Comments

@haider001
Copy link

haider001 commented Jun 20, 2018

I am using s22.imap library from NuGet to move messages from source IMAP server to target IMAP server. Everything is working fine except the library sets new/current DATETIME on the destination server instead of the date at the source IMAP.

e.g. message date is 18-Jun-2018 and when I move message on 20th of June then it will set the date as 20-Jun-2018 instead of 18-Jun-2018.

Here is the code.

MailMessage message = sourceIMAP.GetMessage(uid, FetchOptions.Normal, false, folderName);
var isSeen = seenUids.Contains(uid);
targetIMAP.StoreMessage(message, isSeen, folderName);

@mmoo9154
Copy link

@haider001, the GetMessage() method does not support setting the date/time of the message. This would probably be a great feature request. Even better, you might code up the change and issue a pull request, especially after you see the solution. ;-)

Until someone implements the feature you need, you will need to use the existing client methods to generate your own IMAP APPEND command. Luckiliy, it's pretty simple.

The format of the command is defined in RFC 3501. Here's a link to the page: https://tools.ietf.org/html/rfc3501#page-46

You can look at the implementation of ImapClient.StoreMessage() as a template for your new and improved StoreMessage(). Here is a link to the existing implementation: https://github.com/smiley22/S22.Imap/blob/master/ImapClient.cs#L1270

Notice that smiley22 calls client.SendCommandMessage() at line 1303 with the following string:

tag + "APPEND " + Util.UTF7Encode(mailbox).QuoteString() + (seen ? @" (\Seen)" : "") + " {" + mime822.Length + "}"

It may be a little hard to see, but this string maps to the parts of the APPEND command documented in RFC 3501. All you need to do is insert a valid date/time string in between the "flag parenthesized list" and the curly bracketed MIME length:

string response = targetIMAP.SendCommandGetResponse(tag + "APPEND " +
        Util.UTF7Encode(foldername).QuoteString() +
        (isSeen ? @" (\Seen)" : "") +
        timestamp +
        " {" + mime822.Length + "}");

Then, all you need to do is generate a valid timestamp from your message.Date() and you are done. (Of course, you'll need the rest of the code from the implementation from StoreMessage(), but I'm assuming you can do that.) If it's not clear what you need to do, post a comment.

Now that you've got your new fangled, custom StoreMessage() working, you should see how you can update the existing implementation to add an optional DateTime? timestamp = null parameter to the method so anyone can just call it with message.Date() if they want to preserve the message's timestamp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants