Shankar Guru
Shankar Guru

Reputation: 1161

Imap select folder in internationalized languages

In IMAP, I am trying to select a folder which is in spanish and french language as below. I know that a folder - Español and also folder Français exists under a user called i18n. But am unable to select the folder for performing fetch and search operations. Please let me know if some one can help me on this.

telnet 0 <Port_num>

. login i18n i18n
. OK User i18n logged in
. select Español
. NO [NONEXISTENT] Mailbox does not exist
. select Français
. NO [NONEXISTENT] Mailbox does not exist

If there is a way in which operation can be performed with python or perl will also be okay.

Upvotes: 0

Views: 425

Answers (1)

EvensF
EvensF

Reputation: 1610

This is because of a quirk of IMAP to enable the representation of characters outside of US-ASCII "encoding" in the folders name. In short, you have to use an modified UTF-7 encoding replacing the character + by &. You can have a more thorough explanation in section 5.1.3 of RFC 3501 which defines the IMAP protocol.

I think the code to get the names of your folders for your use case would be something like:

Python 3.5.2+ (default, Dec 13 2016, 14:16:35) 
[GCC 6.2.1 20161124] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import codecs
>>> codecs.encode("Español", encoding="utf-7").replace(b"+", b"&")
b'Espa&APE-ol'
>>> codecs.encode("Français", encoding="utf-7").replace(b"+", b"&")
b'Fran&AOc-ais'

I have to admit that I haven't worked that much with IMAP so there are maybe rules I don't fully understand. But this should get you going.

Upvotes: 2

Related Questions