Gmail IMAP Folders in Different Languages

I had a project where I needed to retrieve messages from my IMAP mailbox of my Bulgarian gmail.  The problem is that I didn’t know what to call it or how to figure out what to call it.  I tried the equivilent in English “All Mail”, folder not found.  I tried the name of the mailbox in Bulgarian in UTF-8 “Цялата поща”, that just gave an error.  I found out that there is some sort of encoding for IMAP for international boxes from a bug report for Thunderbird, a great open-source email client.  It said that I needed to look at RFC3501 to see the standard for how the mailbox should be encoded.  It turns out that it’s a variant of UTF-7, the 7-bit universal format.  It took a while to get a converter going, but it looks a little like this:

</p>
<p>echo &lt;UTF-8 string&gt; | iconv -f utf-8 -t utf-7 | sed -e 's/+/\&amp;/g' -e 's/\&gt;\([^-]\)/-\1/g' -e 's#/#,#g'</p>
<p>

so, for my “All Mail” box, which is Цялата поща in Bulgarian, I would do:

</p>
<p>echo Цялата поща | iconv -f utf-8 -t utf-7 | sed -e 's/+/\&amp;/g' -e 's/\&gt;/-/g' -e 's#/#,#g'</p>
<p>

So, I needed to update my getmail configuration, replacing “All Mail” with the string that resulted: “&BCYETwQ7BDAEQgQw- &BD8EPgRJBDA-“.  This turned out to have some weird issues since the characters that the modified UTF-7 was using were control characters in sed, so my sed command became a little more complicated:

</p>
<p>sed -i -e "s/All Mail/$(echo -n Цялата поща | iconv -f utf-8 -t utf-7 | sed -e 's/+/\\\&amp;/g' -e 's/\&gt;\([^-]\)/\\-\1/g' -e 's#/#,#g')/g" getmail_clashthebunny</p>
<p>

One Reply to “Gmail IMAP Folders in Different Languages”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.