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:


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

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


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

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:


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

One thought on “Gmail IMAP Folders in Different Languages

  1. ffcitatos says:

    Great, helped me a lot! Thank you 🙂

Leave a Reply

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