Answer a question

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

In the imapInstance.list() I get the following path IMAP UTF-7 encoded :

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

If I do the following encoding :

(u"[Mails].Testé").encode('utf-7')

I get :

'[Mails].Test+AOk-'

Which is UTF-7 but not IMAP UTF-7 encoded. Test+AOk- instead of Test&AOk- I'd need an official function or library to get the IMAP UTF-7 encoded version.

Answers

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: https://github.com/mjs/imapclient

Example code:

from imapclient import imap_utf7
decoded = imap_utf7.decode(b'&BdAF6QXkBdQ-')

Disclaimer: I'm the original author of the IMAPClient package.

Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐