I was always wondering, why folders on an Exchange server, containing special characters in the name, show up that "different" in the IMAP protocol (e.g. using Mail::IMAPClient in Perl scripts).
But now I understand, this is just the result of the IMAP specification, that uses a modified UTF-7 encoding for non-ASCII characters (see RFC 2060, section 5.1.3).
If you ever need to automatically convert folder names into that modified UTF-7, the Perl module Encode::IMAPUTF7 may render useful.
The German Umlauts are encode in the following way:
| Umlaut | IMAP-UTF-7 |
|---|---|
| ä | &AOQ- |
| ö | &APY- |
| ü | &APw- |
| Ä | &AMQ- |
| Ö | &ARN- |
| Ü | &ANw- |
| ß | &AN8- |
Comments
Encode::IMAPUTF7
After I finally got a Debian package of Encode::IMAPUTF7 using
dh-make-perlin the contents of the manually downloaded archive on my Ubuntu installation, the following lines are working at last:perl -e '
use encoding "iso-8859-1";
use Encode; use Encode::IMAPUTF7;
print encode("IMAP-UTF-7", "Gel\366schte Objekte"), "\n";
'
Output: Gel&APY-schte Objekte
In contrast to the man page of Encode::IMAPUTF7 I also had to introduce the IMAPUTF7 module.
Encode::IMAPUTF7
It is not really documented in the Encode::IMAPUTF7 package but you have to teach Encode.pm about the IMAPUTF7 encoding before the example in the synopsis works out of the box. This is done by issuing an 'enc2xs -C' command.
Pingback
[...] character in the folder names, e.g. german umlaute. Luckily Holger found a solution for this special character in IMAP folder [...]
List Folders using Perl Module Mail::IMAPClient
The following lines with just list all available folders for an IMAP account, most probably showing ASCII-encoding of special characters:
use Mail::IMAPClient;
print join("\n", Mail::IMAPClient->new(
Server => "imap.example.org",
User => "USER_NAME", Password => "YOUR_PASSWORD"
)->folders), "\n";