Archived Forum Post

Index of archived forum posts

Question:

Backslash Character in IMAP Password?

Aug 03 '12 at 14:47

I do have a question though as a user is experiencing a bug: their password has a backslash in it and the library is not able to connect to the IMAP server because the string is not properly escaped. Is there a best practice for this?


Answer

I did some testing and found that if I send a double-backslash, then the IMAP login succeeds. For example, in C++ code, I did the following:

    success = imap.Login("test@testemail.net","xyz\\xyz");
Each double-backslash in the C++ literal string results in a single backslash char, and therefore two backslashes are sent for the password. This results in a successful authentication.


Answer

From the IMAP RFC:

Certain characters, currently the double-quote and the backslash, may
not be sent as-is inside a quoted string. These characters must be
preceded by the escape character if they are in a quoted string, or
else the string must be sent as a literal. Both clients and servers
must handle this, both on output (they must send these characters
properly) and on input (they must be able to receive escaped characters in quoted strings).

Chilkat will be modified to automatically add the backslash if the password string contains a backslash or double-quote. This change will take effect in v9.3.2