0 votes

I have a corporate Google Apps account and am trying to access my IMAP folders. As the documentation states, the best practice is to use the CommonFolders class, because Google has localized names for all system folders. Unfortunately I can't get it to work. When using new CommonFolders(imap.GetFolders()) all system folder properties, like CommonFolders.Inbox or CommonFolders.AllMail contain the localized name. And when using these CommomFolders properties to select a specific system folder, I get an error saying the selected folder does not exist:

  • [NONEXISTENT] Unknown Mailbox: Postvak IN (Failure)
  • [NONEXISTENT] Unknown Mailbox: [gmail]/alle berichten (Failure)

These errors are to be expected, as the folders names should be:

  • Inbox
  • [Gmail]/All Mail

When selecting Inbox, I won;t get an error and the messages in that folder can be retrieved successfully. But when selecting [Gmail]/All Mail, I stil get an error:

  • [NONEXISTENT] Unknown Mailbox: [Gmail]/All Mail (Failure)

This is very strange, 'cause this should be the right name for the "All Mail" folder.

I also tried my personal Gmail account, but the same errors occur there. And when changing my Gmail display language from Dutch to English (US), the Inbox folder selection works, but all other folders return the [NONEXISTENT] Unknown Mailbox error.

What could be going wrong here?

by (200 points)

1 Answer

0 votes

When using new CommonFolders(imap.GetFolders()) all system folder properties, like CommonFolders.Inbox or CommonFolders.AllMail contain the localized name.

This is expected and correct behavior.

These errors are to be expected, as the folders names should be:
Inbox
[Gmail]/All Mail

No, localized names should be used. Only INBOX folder name should not be localized, as Google doesn't allow selecting INBOX folder by using its localized name. Mail.dll recognizes that and always uses "INBOX" name.

When selecting Inbox, I won;t get an error and the messages in that folder can be retrieved successfully. But when selecting [Gmail]/All Mail, I stil get an error

Localized names must be used for all folders except INBOX. Folder named 'All Mail' doesn't exists on the Gmail's IMAP server, if it uses a different language than English. Localized version of 'All Mail' is the only correct name.

Please turn on logging, use new CommonFolders(imap.GetFolders()) and try selecting AllMail and Inbox.

by (301k points)
edited by
When using the special properties of the CommonFolders class I won't get an error. But neither the CommonFolders class nor the FolderInfo classes contain properties that represent the system folder name, do they? How should I pass the selected folder in my QueryString and select the IMAP folder based on this QueryString parameter?
CommonFolders contains properties, that represent system folders like AllMail, Inbox, etc. Those properties are of type FolderInfo. To select a folder you use Imap.Select method and pass FolderInfo instance or a folder name represented as string. What QueryString are you talking about?
I use the CommonFolders(imap.GetFolders()) to create a list of all available folders. When I select a folder in that list I go to e.g. mail.aspx?folder={IMAPFOLDERNAME}. So on the mail.aspx page I need to select the IMAP folder represented in the folder QueryString parameter. What property of the FolderInfo should I use for this querystring parameter, in order for me to successfully select that IMAP folder? FolderInfo.Name will contain the localized name and can't be used to select an IMAP folder. And I can't use CommonFolder.Inbox or any other of the special FolderInfo properties of the CommonFolders class, 'cause I don't know what folder is passed through the querystring parameter and there doesn't seem to be a way to compare this value to one of these special properties.
Your first problem is most likely with proper characters encoding in the url you create. Use FolderInfo.Name. FolderInfo.Name can be used to select a folder. Remember that for inbox folder (and only for inbox folder) you must use "INBOX" name instead of the localized folder name. You could probably use FolderInfo GetImapName() method as it returns UTF7 encoded folder name and also returns "INBOX" name for inbox folder.
Encoding is handled properly, but the GetImapName() method sounds like the one I would and should use. Unfortunately I don't have this method on my FolderInfo class. I installed the latest version of Mail.dll using Nuget: 3.0.14228.1107.
You can download the latest version here:
https://www.limilabs.com/mail/download
If you handle url encoding correctly, you can use Name and only check for this inbox problem Gmail has.
The .GetImapName() method returns the exact same value as the .Name property: a localized value. So when clicking the all mail folder, the querystring parameter will contain (for reading purposes not encoded) [gmail]/alle berichten. And calling imap.Select() with this value will return [NONEXISTENT] Unknown Mailbox: [gmail]/alle berichten (Failure). So please tell me what property or method I should use to be able to select an IMAP folder based on that value.
You must use a localized name to select a folder!

For example:

C: 71f26035591743e1 XLIST "" "*"
S: * XLIST (\HasNoChildren \Inbox) "/" "Posteingang"
S: * XLIST (\Noselect \HasChildren) "/" "[Gmail]"
S: * XLIST (\AllMail \HasNoChildren) "/" "[Gmail]/Alle Nachrichten"
S: * XLIST (\Drafts \HasNoChildren) "/" "[Gmail]/Entw&APw-rfe"
S: * XLIST (\Sent \HasNoChildren) "/" "[Gmail]/Gesendet"
S: * XLIST (\Starred \HasNoChildren) "/" "[Gmail]/Markiert"
S: * XLIST (\HasNoChildren \Trash) "/" "[Gmail]/Papierkorb"
S: * XLIST (\Spam \HasNoChildren) "/" "[Gmail]/Spam"
S: * XLIST (\Important \HasNoChildren) "/" "[Gmail]/Wichtig"
S: 71f26035591743e1 OK Success
C: 7c85757af7b44096 SELECT "[Gmail]/Alle Nachrichten"
S: * FLAGS (\Answered ...
S: * OK [PERMANENTFLAGS ...
S: * OK [UIDVALIDITY 627130625] UIDs valid.
S: * 0 EXISTS
S: * 0 RECENT
S: * OK [UIDNEXT 26242] Predicted next UID.
S: * OK [HIGHESTMODSEQ 1009036]
S: 7c85757af7b44096 OK [READ-WRITE] [Gmail]/Alle Nachrichten selected. (Success)
But I AM using the localized name: [gmail]/alle berichten. This is the value returned by both the FolderInfo.Name property and the FolderInfo.GetImapName() method. But when using this string value when calling Imap.Select, so Imap.Select("[gmail]/alle berichten"), I get the non existent error.
This is why I already told you, that your problem is with url encoding utf8 characters, and also asked for the logs.
Using another form of encoding indeed solved my problem. Thanks. Just one more question: the FolderInfo class has the GetImapName method, but the FolderStatus class does not. Is there any way to find out the ImapName for a FolderStatus class? Or might the GetImapName method be added to this class in the near future?
FoldersStatus class contains Name property only.
...