Search The ForumSearch   RegisterRegister  LoginLogin

MailBee.NET IMAP

 AfterLogic Forum : MailBee.NET IMAP
Subject Topic: How to get SystemFlags from MailMessage? Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
hmuscroft
Groupie
Groupie


Joined: 29 December 2009
Location: United Kingdom
Online Status: Offline
Posts: 72
Posted: 02 February 2017 at 1:11am | IP Logged Quote hmuscroft

I have implemented the ability in my client app to move emails from one IMAP account to another.

To accomplish this, I first use "DownloadEntireMessage" to get the whole message from the OLD server, then "UploadMessage" to upload it to the NEW server.

However, when calling "UploadMessage" I realised that I should also be sending in the "SystemMessageFlags" as a parameter so that the flags are consistent when the move operation is complete.

So the question is: how can I get at the "SystemMessageFlags" from the MailMessage object which I downloeded from "DownloadEntireMessage"?

As far as I can see, the flags are a property of the ENVELOPE object, but I can't see how to get them from the MailMessage object, so at the moment I have the additional overhead of a second call to download the envelope too.

Many thanks!
Back to Top View hmuscroft's Profile Search for other posts by hmuscroft
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6038
Posted: 02 February 2017 at 1:39am | IP Logged Quote Igor

Flags are not a part of MailMessage object, you would need to download IMAP envelopes to obtain flags as described here. It's not necessary to make an extra call for downloading envelopes though; instead, you can request EnvelopeParts.MessagePreview with bodyPreviewSize set to -1, that will get you entire message upon DownloadEnvelopes call.

Hope this helps.

--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
hmuscroft
Groupie
Groupie


Joined: 29 December 2009
Location: United Kingdom
Online Status: Offline
Posts: 72
Posted: 02 February 2017 at 1:47am | IP Logged Quote hmuscroft

That does indeed help - many thanks!

On a related subject, after sending a new email, I call "imap.UploadMessage" to store a copy in the SENT ITEMS folder (apart from on Hotmail accounts which does it for you).

The odd thing is that the uploaded message is marked as UNREAD on the server.

Here's my code :-
Code:
imap.UploadMessage(msg, imap.FOLDER_SENT, SystemMessageFlags.Seen);


Should I be setting a different flag?

Thanks.
Back to Top View hmuscroft's Profile Search for other posts by hmuscroft
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6038
Posted: 02 February 2017 at 1:53am | IP Logged Quote Igor

I would assume setting flags upon uploading message isn't implemented on specific IMAP server, try setting some other flag and see if it works, also try checking if this works on another server. Analyzing IMAP logs can help understanding what exactly is going wrong.

--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
hmuscroft
Groupie
Groupie


Joined: 29 December 2009
Location: United Kingdom
Online Status: Offline
Posts: 72
Posted: 02 February 2017 at 3:26am | IP Logged Quote hmuscroft

Thanks again!
Back to Top View hmuscroft's Profile Search for other posts by hmuscroft
 
hmuscroft
Groupie
Groupie


Joined: 29 December 2009
Location: United Kingdom
Online Status: Offline
Posts: 72
Posted: 03 February 2017 at 1:28am | IP Logged Quote hmuscroft

So just further to this, I'm finding that on Gmail, Hotmail and 1&1, calling UploadMessage with SystemMessageFlags.Seen has no effect and the uploaded messages are always UNREAD in the "Sent Items" folder.

Here's my code :-
Code:
imap.UploadMessage(msg, imap.FOLDER_SENT, SystemMessageFlags.Seen);


Here's the log :-
Code:
[09:22:09.63] [INFO] Assembly version: 10.0.45.551.
[09:22:09.63] [INFO] Will resolve host "imap.1and1.co.uk".
[09:22:09.67] [INFO] Host "imap.1and1.co.uk" resolved to IP address(es) 212.227.15.154, 212.227.15.138.
[09:22:09.67] [INFO] Will connect to host "imap.1and1.co.uk" on port 143.
[09:22:09.74] [INFO] Socket connected to IP address 212.227.15.154 on port 143.
[09:22:09.80] [RECV] * OK [CAPABILITY IMAP4rev1 CHILDREN ENABLE ID IDLE LIST-EXTENDED LIST-STATUS LITERAL+ MOVE NAMESPACE QUOTA SASL-IR SORT SPECIAL-USE THREAD=ORDEREDSUBJECT UIDPLUS UNSELECT WITHIN STARTTLS AUTH=LOGIN AUTH=PLAIN] IMAP server ready H mieue142 2651323638 IMAP-0LmXvz-1c1LIQ3rRz-00ZoFb\r\n [Total 281 bytes received.]
[09:22:09.81] [INFO] Connected to mail service at host "imap.1and1.co.uk" on port 143 and ready.
[09:22:09.82] [INFO] Notify server that we are ready to start TLS/SSL negotiation.
[09:22:09.82] [SEND] MBN00000001 STARTTLS\r\n
[09:22:09.88] [RECV] MBN00000001 OK Begin TLS negotiation now\r\n [Total 42 bytes received.]
[09:22:09.88] [INFO] Will start TLS/SSL negotiation sequence.
[09:22:10.01] [INFO] TLS/SSL negotiation completed.
[09:22:10.01] [INFO] Get the list of IMAP4 capabilities via CAPABILITY command.
[09:22:10.01] [SEND] MBN00000002 CAPABILITY\r\n
[09:22:10.06] [RECV] * CAPABILITY IMAP4rev1 CHILDREN ENABLE ID IDLE LIST-EXTENDED LIST-STATUS LITERAL+ MOVE NAMESPACE QUOTA SASL-IR SORT SPECIAL-USE THREAD=ORDEREDSUBJECT UIDPLUS UNSELECT WITHIN AUTH=LOGIN AUTH=PLAIN\r\n [Total 197 bytes received.]
[09:22:10.06] [RECV] MBN00000002 OK CAPABILITY completed\r\n [Total 37 bytes received.]
[09:22:10.07] [INFO] Will login as "xxxxxxxxxxxxxxxxxxx".
[09:22:10.07] [INFO] Will try SASL LOGIN authentication method.
[09:22:10.07] [SEND] MBN00000003 AUTHENTICATE LOGIN\r\n
[09:22:10.12] [RECV] + VXNlcm5hbWU6\r\n [Total 16 bytes received.]
[09:22:10.12] [SEND] ********\r\n
[09:22:10.20] [RECV] + UGFzc3dvcmQ6\r\n [Total 16 bytes received.]
[09:22:10.21] [SEND] ********\r\n
[09:22:10.27] [RECV] MBN00000003 OK AUTHENTICATE completed\r\n [Total 39 bytes received.]
[09:22:10.27] [INFO] Logged in as "xxxxxxxxxxxxxxxxxxx".
[09:22:10.28] [INFO] Will download list of sub-folders of "" folder matching "" condition.
[09:22:10.28] [SEND] MBN00000004 LIST "" "*"\r\n
[09:22:10.34] [RECV] * LIST (\Archive \HasNoChildren) "/" Archive\r\n [Total 46 bytes received.]
[09:22:10.34] [RECV] * LIST (\Drafts \HasNoChildren) "/" Drafts\r\n [Total 44 bytes received.]
[09:22:10.34] [RECV] * LIST (\HasChildren) "/" INBOX\r\n [Total 33 bytes received.]
[09:22:10.35] [RECV] * LIST (\HasNoChildren) "/" INBOX/Private\r\n [Total 43 bytes received.]
[09:22:10.35] [RECV] * LIST (\Sent \HasChildren) "/" Sent\r\n [Total 38 bytes received.]
[09:22:10.35] [RECV] * LIST (\HasNoChildren) "/" Sent/Private\r\n [Total 42 bytes received.]
[09:22:10.35] [RECV] * LIST (\Junk \HasNoChildren) "/" Spam\r\n [Total 40 bytes received.]
[09:22:10.36] [RECV] * LIST (\Trash \HasNoChildren) "/" Trash\r\n [Total 42 bytes received.]
[09:22:10.36] [RECV] MBN00000004 OK LIST completed\r\n [Total 31 bytes received.]
[09:22:10.36] [INFO] Folder list downloaded.
[09:22:25.97] [INFO] Will upload message to folder "Sent".
[09:22:25.98] [SEND] MBN00000005 APPEND "Sent" (Seen) "03-Feb-2017 09:22:07 +0000" {3229+}\r\n
[09:22:25.98] [SEND] MIME-Version: 1.0\r\nX-Mailer: MailBee.NET 10.0.45.551\r\nFrom: "Hed ... ody>\r\n</html>\r\n\r\n------=_NextPart_000_535A_14A93BE0.C2B80499--\r\n [Data chunk of 3229 bytes sent.]
[09:22:25.98] [SEND] \r\n
[09:22:26.07] [RECV] MBN00000005 OK [APPENDUID 1377160154 80] APPEND completed\r\n [Total 59 bytes received.]
[09:22:26.08] [INFO] Message uploaded.


Am I doing something wrong, or do I always need to explicitly send an additional command to mark the email as read after uploading to the SEND folder?
Back to Top View hmuscroft's Profile Search for other posts by hmuscroft
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2206
Posted: 03 February 2017 at 2:04am | IP Logged Quote Alex

When I try to reproduce this, I'm getting this in the logs (Dovecot mail server):

Quote:

[12:45:41.96] [SEND] MBN00000002 APPEND "Sent" (\Seen) "03-Feb-2017 12:45:41 +0300" {145+}\r\n


Notice \Seen, not Seen.

The code was:
Quote:

imp.UploadMessage(msg, "Sent", SystemMessageFlags.Seen);


Using 551 build.

I also checked with Gmail, \Seen flag gets actually set:

Quote:

[12:55:59.23] [SEND] MBN00000005 APPEND "[Gmail]/Sent Mail" (\Seen) "03-Feb-2017 12:55:59 +0300" {145}\r\n
[12:55:59.31] [RECV] + go ahead\r\n [Total 12 bytes received.]
[12:55:59.31] [SEND] MIME-Version: 1.0\r\nX-Mailer: ... charset="utf-8"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n [Data chunk of 145 bytes sent.]
[12:55:59.31] [SEND] \r\n
[12:55:59.73] [RECV] * 450 EXISTS\r\n [Total 14 bytes received.]
[12:55:59.73] [RECV] MBN00000005 OK [APPENDUID 4 2772] (Success)\r\n [Total 45 bytes received.]
[12:55:59.73] [INFO] Message uploaded.
[12:55:59.73] [INFO] Will download envelopes.
[12:55:59.74] [SEND] MBN00000006 FETCH 450 (UID FLAGS INTERNALDATE RFC822.SIZE ENVELOPE BODY.PEEK[HEADER.FIELDS (CONTENT-TYPE)])\r\n
[12:55:59.83] [RECV] * 450 FETCH (UID 2772 RFC822.SIZE 145 INTERNALDATE "03-Feb-2017 09:55:59 +0000" FLAGS (\Seen) ENVELOPE ("Fri, 3 Feb 2017 01:55:59 -0800 (PST)" NIL ((NIL NIL NIL NIL)) ((NIL NIL NIL NIL)) ((NIL NIL NIL NIL)) NIL NIL NIL NIL "<303466867717159344@unknownmsgid>") BODY[HEADER.FIELDS (CONTENT-TYPE)] {45}\r\n


Regards,
Alex
Back to Top View Alex's Profile Search for other posts by Alex
 
hmuscroft
Groupie
Groupie


Joined: 29 December 2009
Location: United Kingdom
Online Status: Offline
Posts: 72
Posted: 03 February 2017 at 2:14am | IP Logged Quote hmuscroft

Ah... I've just re-examined my code and the particular "UploadMessage" call in question is actually using a different overload :-

Code:
m_imap.UploadMessage(Msg, ToFolder, (Flags != null ? Flags.ToString() : null), ImapUtils.GetImapDateTimeString(MsgDateTime.Value), true, res);


I have to use this overload because I need to get the UIDPLUS result.

Flags is a "SystemMessageFlags?". I suspect the problem is how I'm converting it to a string - Flags.Value.ToString() which becomes "Seen" and not "\Seen".

What is the correct way to convert SystemMessageFlags to an IMAP text representation?
Back to Top View hmuscroft's Profile Search for other posts by hmuscroft
 
hmuscroft
Groupie
Groupie


Joined: 29 December 2009
Location: United Kingdom
Online Status: Offline
Posts: 72
Posted: 03 February 2017 at 2:25am | IP Logged Quote hmuscroft

Got it

Code:
MessageFlagSet.SystemFlagsToString(Flags.Value)


It's all working beautifully now!
Back to Top View hmuscroft's Profile Search for other posts by hmuscroft
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump

Powered by Web Wiz Forums version 7.9
Copyright ©2001-2004 Web Wiz Guide