Archived Forum Post

Index of archived forum posts


IMAP ExamineMailbox manipulating the inputted string?

Apr 10 '13 at 18:33

This one is a challenge. Seems GMAIL allows for some damn crazy mailbox values, as such I've been working on properly escaping the string values used by Gmail.

Here's an example:


So we escape this properly (as per IMAP RFC):


And use ExamineMailbox..

It fails, so I pull the session log and see:

----IMAP REQUEST---- aaaq EXAMINE "AnyCharsWeCan&AFw-'tUse?!@#$%&-*()_+{}|[]&AFwAXA-;:&AFw-'&AFw-"" ----IMAP RESPONSE---- aaaq BAD Could not parse command

Any idea what is going on here?


Ok, I've done a lot more digging, here's what I've uncovered.

First I switched everything to the Unicode version, just to avoid any ANSI/Utf8 mis-calculations. Next, I opened up Thunderbird and dumped the entire IMAP traffic, I noticed it was issuing the following:

select "AnyCharsWeCan'tUse?!@#$%&-*()_+{}|[]\;:'""

The key there is the "dash" value. When I run the same command (SelectMailbox) using the unicode output of ListMailboxes I get the following in the Session Log.

SELECT "AnyCharsWeCan'tUse?!@#$%&*()_+{}|[]\;:'""

Notice the "-" is gone? GMAIL returns that this is an invalid UTf7 string..

So I go back to ListMailboxes and dump the Session log immediately upon completion.


So I'm getting good values from the ListMailboxes, however I'm not getting that same value when I iterate through the CkMailboxesW object. Calling ->getName(i) gives me a wchar_t * that is missing the "-" value.

Any ideas?



You shouldn't need to escape any chars in the mailbox name -- other than possibly escaping characters according to the syntax of a given programming language when it comes to literal strings. In the IMAP protocol, the mailbox names are encoded to utf-7 as per the IMAP protocol specification. (It's not exactly utf-7, because the IMAP protocol defines a few differences, and Chilkat adheres to the IMAP specifications.) Also, there should be no need to worry about ANSI/utf-8/Unicode. As long as you're passing the string correctly, then Chilkat automatically handles any necessary conversions (from ANSI, or utf-8, or Unicode) to the utf-7 required.