0 votes

When I select Drafts folder and then get messages, GmailLabels is empty for all emails.

FolderInfo drafts = new CommonFolders(imap.GetFolders()).Drafts;
imap.Select(drafts);

List<long> uids = imap.Search(Flag.All);            
var messages = imap.GetMessageInfoByUID(uids);

But if I select 'AllMail' folder, draft messages contain label '\Draft'.

FolderInfo all = new CommonFolders(imap.GetFolders()).AllMail;

Isn't it a bug?

by

1 Answer

0 votes
 
Best answer

My experience with Gmail is that you should only use 'All Mail' folder and apply/read Gmail labels. Don't select any other folder - it's not needed as each folder has a Gmail label representing it. That is the easiest and safest way.

This works correctly (search, get labels):

client.Select(new CommonFolders(client.GetFolders()).AllMail);
long uid = client.Search(Expression.GmailLabel(@"DRAFT"))[0];
CollectionAssert.Contains(client.GmailGetLabelsByUID(uid), @"\Draft");

After selecting "[Gmail]/Drafts" folder, @"\Draft" Gmail label is not returned:

client.Select(new CommonFolders(client.GetFolders()).Drafts);
long uid = client.Search(Expression.GmailLabel(@"DRAFT"))[0];
CollectionAssert.Contains(client.GmailGetLabelsByUID(uid), @"\Draft"); // fails

Log shows that X-GM-LABELS is empty for this message:

C: 14dfa8432ddf4d0c SELECT "[Gmail]/Drafts"
S: ...
S: 14dfa8432ddf4d0c OK [READ-WRITE] [Gmail]/Drafts selected. (Success)
C: 99a636acf3f64074 UID SEARCH RETURN (ALL) X-GM-LABELS DRAFT
S: * ESEARCH (TAG "99a636acf3f64074") UID ALL 19824,27423
S: 99a636acf3f64074 OK SEARCH completed (Success)
C: b22caad19a8049b9 UID FETCH 19824 (UID X-GM-LABELS)
S: * 1 FETCH (X-GM-LABELS () UID 19824)
S: b22caad19a8049b9 OK Success

As a side note it's worth mentioning that regular \Draft flag is not working. Gmail's IMAP server simply doesn't return it:

C: 7ec5e9eb85084c99 SELECT "[Gmail]/Drafts"
S: ...
S: 7ec5e9eb85084c99 OK [READ-WRITE] [Gmail]/Drafts selected. (Success)
C: 2a0d60aa54c349e9 UID FETCH 17290 (UID FLAGS)
S: * 1 FETCH (FLAGS (\Seen))
S: 2a0d60aa54c349e9 OK Success

It doesn't work for 'All Mail' IMAP folder as well:

C: 79ad0ec3d5554b56 SELECT "[Gmail]/All Mail"
S: ...
C: c3a8431ea2d640bd UID SEARCH RETURN (ALL) BODY "test in draft"
S: * ESEARCH (TAG "c3a8431ea2d640bd") UID ALL 119322
S: c3a8431ea2d640bd OK SEARCH completed (Success)
C: cd8ea2cf4c6e450d UID FETCH 119322 (UID FLAGS)
S: * 12500 FETCH (UID 119322 FLAGS (\Seen))
S: cd8ea2cf4c6e450d OK Success

Search using \Draft flag doesn't work either:

C: 8807cd6a9a204bc8 SELECT "[Gmail]/All Mail"
S: ...
S: 8807cd6a9a204bc8 OK [READ-WRITE] [Gmail]/All Mail selected. (Success)
C: 9e2109fd821844f1 UID SEARCH RETURN (ALL) DRAFT
S: * ESEARCH (TAG "9e2109fd821844f1") UID
S: 9e2109fd821844f1 OK SEARCH completed (Success)
by (301k points)
edited by
...