From 24b3f27e5f5dd7f643c3dc7694009cf125b32ace Mon Sep 17 00:00:00 2001 From: Urs Liska Date: Tue, 26 Sep 2017 11:26:33 +0200 Subject: [PATCH] utf8: Add utf-7/8 conversion functions This commit adds two functions - imaputil.IMAP_utf8() - imaputil.utf8_IMAP() as an interface to the new imap4_utf_7 codec. Signed-off-by: Urs Liska Signed-off-by: Nicolas Sebrecht --- offlineimap/imaputil.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/offlineimap/imaputil.py b/offlineimap/imaputil.py index 1299cdd..39bd8d4 100644 --- a/offlineimap/imaputil.py +++ b/offlineimap/imaputil.py @@ -376,6 +376,18 @@ def decode_mailbox_name(name): # Functionality to convert folder names encoded in IMAP_utf_7 to utf_8. # This is achieved by defining 'imap4_utf_7' as a proper encoding scheme. +# Public API, to be used in repository definitions + +def IMAP_utf8(foldername): + """Convert IMAP4_utf_7 encoded string to utf-8""" + return foldername.decode('imap4-utf-7').encode('utf-8') + +def utf8_IMAP(foldername): + """Convert utf-8 encoded string to IMAP4_utf_7""" + return foldername.decode('utf-8').encode('imap4-utf-7') + +# Codec definition + def modified_base64(s): s = s.encode('utf-16be') return binascii.b2a_base64(s).rstrip('\n=').replace('/', ',')