Reformat offlineimap/imaputil.py
Add some spaces, remove lines,... now format is better (lintian).
This commit is contained in:
parent
b6a686e56f
commit
2969f36663
@ -21,7 +21,6 @@ import binascii
|
|||||||
import codecs
|
import codecs
|
||||||
from offlineimap.ui import getglobalui
|
from offlineimap.ui import getglobalui
|
||||||
|
|
||||||
|
|
||||||
## Globals
|
## Globals
|
||||||
|
|
||||||
# Message headers that use space as the separator (for label storage)
|
# Message headers that use space as the separator (for label storage)
|
||||||
@ -37,6 +36,7 @@ def __debug(*args):
|
|||||||
msg.append(str(arg))
|
msg.append(str(arg))
|
||||||
getglobalui().debug('imap', " ".join(msg))
|
getglobalui().debug('imap', " ".join(msg))
|
||||||
|
|
||||||
|
|
||||||
def dequote(s):
|
def dequote(s):
|
||||||
"""Takes string which may or may not be quoted and unquotes it.
|
"""Takes string which may or may not be quoted and unquotes it.
|
||||||
|
|
||||||
@ -49,6 +49,7 @@ def dequote(s):
|
|||||||
s = s.replace('\\\\', '\\')
|
s = s.replace('\\\\', '\\')
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
def quote(s):
|
def quote(s):
|
||||||
"""Takes an unquoted string and quotes it.
|
"""Takes an unquoted string and quotes it.
|
||||||
|
|
||||||
@ -59,6 +60,7 @@ def quote(s):
|
|||||||
s = s.replace('\\', '\\\\')
|
s = s.replace('\\', '\\\\')
|
||||||
return '"%s"' % s
|
return '"%s"' % s
|
||||||
|
|
||||||
|
|
||||||
def flagsplit(s):
|
def flagsplit(s):
|
||||||
"""Converts a string of IMAP flags to a list
|
"""Converts a string of IMAP flags to a list
|
||||||
|
|
||||||
@ -71,6 +73,7 @@ def flagsplit(s):
|
|||||||
raise ValueError("Passed s '%s' is not a flag list" % s)
|
raise ValueError("Passed s '%s' is not a flag list" % s)
|
||||||
return imapsplit(s[1:-1])
|
return imapsplit(s[1:-1])
|
||||||
|
|
||||||
|
|
||||||
def __options2hash(list):
|
def __options2hash(list):
|
||||||
"""convert list [1,2,3,4,5,6] to {1:2, 3:4, 5:6}"""
|
"""convert list [1,2,3,4,5,6] to {1:2, 3:4, 5:6}"""
|
||||||
|
|
||||||
@ -85,6 +88,7 @@ def __options2hash(list):
|
|||||||
__debug("__options2hash returning:", retval)
|
__debug("__options2hash returning:", retval)
|
||||||
return retval
|
return retval
|
||||||
|
|
||||||
|
|
||||||
def flags2hash(flags):
|
def flags2hash(flags):
|
||||||
"""Converts IMAP response string from eg IMAP4.fetch() to a hash.
|
"""Converts IMAP response string from eg IMAP4.fetch() to a hash.
|
||||||
|
|
||||||
@ -93,6 +97,7 @@ def flags2hash(flags):
|
|||||||
|
|
||||||
return __options2hash(flagsplit(flags))
|
return __options2hash(flagsplit(flags))
|
||||||
|
|
||||||
|
|
||||||
def imapsplit(imapstring):
|
def imapsplit(imapstring):
|
||||||
"""Takes a string from an IMAP conversation and returns a list containing
|
"""Takes a string from an IMAP conversation and returns a list containing
|
||||||
its components. One example string is:
|
its components. One example string is:
|
||||||
@ -146,12 +151,14 @@ def imapsplit(imapstring):
|
|||||||
break
|
break
|
||||||
return retval
|
return retval
|
||||||
|
|
||||||
|
|
||||||
flagmap = [('\\Seen', 'S'),
|
flagmap = [('\\Seen', 'S'),
|
||||||
('\\Answered', 'R'),
|
('\\Answered', 'R'),
|
||||||
('\\Flagged', 'F'),
|
('\\Flagged', 'F'),
|
||||||
('\\Deleted', 'T'),
|
('\\Deleted', 'T'),
|
||||||
('\\Draft', 'D')]
|
('\\Draft', 'D')]
|
||||||
|
|
||||||
|
|
||||||
def flagsimap2maildir(flagstring):
|
def flagsimap2maildir(flagstring):
|
||||||
"""Convert string '(\\Draft \\Deleted)' into a flags set(DR)."""
|
"""Convert string '(\\Draft \\Deleted)' into a flags set(DR)."""
|
||||||
|
|
||||||
@ -162,6 +169,7 @@ def flagsimap2maildir(flagstring):
|
|||||||
retval.add(maildirflag)
|
retval.add(maildirflag)
|
||||||
return retval
|
return retval
|
||||||
|
|
||||||
|
|
||||||
def flagsimap2keywords(flagstring):
|
def flagsimap2keywords(flagstring):
|
||||||
"""Convert string '(\\Draft \\Deleted somekeyword otherkeyword)' into a
|
"""Convert string '(\\Draft \\Deleted somekeyword otherkeyword)' into a
|
||||||
keyword set (somekeyword otherkeyword)."""
|
keyword set (somekeyword otherkeyword)."""
|
||||||
@ -170,6 +178,7 @@ def flagsimap2keywords(flagstring):
|
|||||||
serverflagset = set([flag for (flag, c) in flagmap])
|
serverflagset = set([flag for (flag, c) in flagmap])
|
||||||
return imapflagset - serverflagset
|
return imapflagset - serverflagset
|
||||||
|
|
||||||
|
|
||||||
def flagsmaildir2imap(maildirflaglist):
|
def flagsmaildir2imap(maildirflaglist):
|
||||||
"""Convert set of flags ([DR]) into a string '(\\Deleted \\Draft)'."""
|
"""Convert set of flags ([DR]) into a string '(\\Deleted \\Draft)'."""
|
||||||
|
|
||||||
@ -179,6 +188,7 @@ def flagsmaildir2imap(maildirflaglist):
|
|||||||
retval.append(imapflag)
|
retval.append(imapflag)
|
||||||
return '(' + ' '.join(sorted(retval)) + ')'
|
return '(' + ' '.join(sorted(retval)) + ')'
|
||||||
|
|
||||||
|
|
||||||
def uid_sequence(uidlist):
|
def uid_sequence(uidlist):
|
||||||
"""Collapse UID lists into shorter sequence sets
|
"""Collapse UID lists into shorter sequence sets
|
||||||
|
|
||||||
@ -319,6 +329,7 @@ def decode_mailbox_name(name):
|
|||||||
|
|
||||||
Returns: decoded UTF-8 string.
|
Returns: decoded UTF-8 string.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def demodify(m):
|
def demodify(m):
|
||||||
s = m.group()
|
s = m.group()
|
||||||
if s == '+':
|
if s == '+':
|
||||||
@ -332,6 +343,7 @@ def decode_mailbox_name(name):
|
|||||||
except (UnicodeDecodeError, UnicodeEncodeError):
|
except (UnicodeDecodeError, UnicodeEncodeError):
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
|
||||||
# Functionality to convert folder names encoded in IMAP_utf_7 to utf_8.
|
# 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.
|
# This is achieved by defining 'imap4_utf_7' as a proper encoding scheme.
|
||||||
|
|
||||||
@ -341,21 +353,25 @@ def IMAP_utf8(foldername):
|
|||||||
"""Convert IMAP4_utf_7 encoded string to utf-8"""
|
"""Convert IMAP4_utf_7 encoded string to utf-8"""
|
||||||
return foldername.decode('imap4-utf-7').encode('utf-8')
|
return foldername.decode('imap4-utf-7').encode('utf-8')
|
||||||
|
|
||||||
|
|
||||||
def utf8_IMAP(foldername):
|
def utf8_IMAP(foldername):
|
||||||
"""Convert utf-8 encoded string to IMAP4_utf_7"""
|
"""Convert utf-8 encoded string to IMAP4_utf_7"""
|
||||||
return foldername.decode('utf-8').encode('imap4-utf-7')
|
return foldername.decode('utf-8').encode('imap4-utf-7')
|
||||||
|
|
||||||
|
|
||||||
# Codec definition
|
# Codec definition
|
||||||
|
|
||||||
def modified_base64(s):
|
def modified_base64(s):
|
||||||
s = s.encode('utf-16be')
|
s = s.encode('utf-16be')
|
||||||
return binascii.b2a_base64(s).rstrip('\n=').replace('/', ',')
|
return binascii.b2a_base64(s).rstrip('\n=').replace('/', ',')
|
||||||
|
|
||||||
|
|
||||||
def doB64(_in, r):
|
def doB64(_in, r):
|
||||||
if _in:
|
if _in:
|
||||||
r.append('&%s-' % modified_base64(''.join(_in)))
|
r.append('&%s-' % modified_base64(''.join(_in)))
|
||||||
del _in[:]
|
del _in[:]
|
||||||
|
|
||||||
|
|
||||||
def encoder(s):
|
def encoder(s):
|
||||||
r = []
|
r = []
|
||||||
_in = []
|
_in = []
|
||||||
@ -372,11 +388,13 @@ def encoder(s):
|
|||||||
doB64(_in, r)
|
doB64(_in, r)
|
||||||
return (str(''.join(r)), len(s))
|
return (str(''.join(r)), len(s))
|
||||||
|
|
||||||
|
|
||||||
# decoding
|
# decoding
|
||||||
def modified_unbase64(s):
|
def modified_unbase64(s):
|
||||||
b = binascii.a2b_base64(s.replace(',', '/') + '===')
|
b = binascii.a2b_base64(s.replace(',', '/') + '===')
|
||||||
return str(b, 'utf-16be')
|
return str(b, 'utf-16be')
|
||||||
|
|
||||||
|
|
||||||
def decoder(s):
|
def decoder(s):
|
||||||
r = []
|
r = []
|
||||||
decode = []
|
decode = []
|
||||||
@ -399,14 +417,17 @@ def decoder(s):
|
|||||||
bin_str = ''.join(r)
|
bin_str = ''.join(r)
|
||||||
return (bin_str, len(s))
|
return (bin_str, len(s))
|
||||||
|
|
||||||
|
|
||||||
class StreamReader(codecs.StreamReader):
|
class StreamReader(codecs.StreamReader):
|
||||||
def decode(self, s, errors='strict'):
|
def decode(self, s, errors='strict'):
|
||||||
return decoder(s)
|
return decoder(s)
|
||||||
|
|
||||||
|
|
||||||
class StreamWriter(codecs.StreamWriter):
|
class StreamWriter(codecs.StreamWriter):
|
||||||
def decode(self, s, errors='strict'):
|
def decode(self, s, errors='strict'):
|
||||||
return encoder(s)
|
return encoder(s)
|
||||||
|
|
||||||
|
|
||||||
def imap4_utf_7(name):
|
def imap4_utf_7(name):
|
||||||
if name == 'imap4-utf-7':
|
if name == 'imap4-utf-7':
|
||||||
return (encoder, decoder, StreamReader, StreamWriter)
|
return (encoder, decoder, StreamReader, StreamWriter)
|
||||||
|
Loading…
Reference in New Issue
Block a user