Mibou Mibou - 6 months ago 110
Python Question

IMAP folder path encoding (IMAP UTF-7) for Python

I would like to know if any "official" function/library existed in Python for IMAP4 UTF-7 folder path encoding.

In the

I get the following path IMAP UTF-7 encoded :

'(\\HasNoChildren) "." "[Mails].Test&AOk-"',

If I do the following encoding :


I get :


Which is UTF-7 but not IMAP UTF-7 encoded.
instead of

I'd need an official function or library to get the IMAP UTF-7 encoded version.

Answer Source

The IMAPClient package has functionality for encoding and decoding using IMAP's modified UTF-7. Have a look in the IMAPClient.imap_utf7 module. This module could be used standalone or you could just use IMAPClient which handles doing the encoding and decoding of folder names transparently.

The project's home page is: http://imapclient.freshfoo.com/

Example code:

from imapclient import imap_utf7
decoded = imap_utf7.decode('&BdAF6QXkBdQ-')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download