IMAP folder names conversion utility

July 11, 2019
imap utf8

If you’ve encountered folder names like A5EDwQPHA7UDrwO,- in your mailbox after a mail server migration, you can convert them back with this shell pipe:

echo 'FOLDER_NAME' | tr "&" "+" | tr "," "/" | iconv -f UTF-7 -t UTF-8

Obviously, you’ll have to change the FOLDER_NAME string. e.g.:

echo '&A5EDwQPHA7UDrwO,-' | tr "&" "+" | tr "," "/" | iconv -f UTF-7 -t UTF-8

I’ve also created a PHP Script that does the same thing utilizing the mb_convert_encoding() function:

    <title>IMAP UTF7 to UTF8 converter</title>
<form method="POST" action="">
    <input type="text" name="imap7">
    <input type="submit" value="Convert">

    if (isset($_POST['imap7'])) {
        echo mb_convert_encoding($_POST['imap7'], "UTF8", "UTF7-IMAP");