summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2018-04-24 09:20:22 -0700
committerDylan Baker <dylan@pnwbakers.com>2018-04-24 09:20:22 -0700
commitecb5d076b52089638c85330655cdb9755fd876e6 (patch)
tree5a4ec3d6a4f23b4049da2c0877af138e986c690c /alot
parentbd7a5051e4aefb8ad1a8eea7f7b477d4038fd7de (diff)
parent1708fd59ed2a44bd543d510a4895aa95e30c9af3 (diff)
Merge remote-tracking branch 'bignose/wip/issue/python3-codeclimate' into py3k
One small conflict caused by "db/utils: correctly handle 8bit encoded mail"
Diffstat (limited to 'alot')
-rw-r--r--alot/account.py8
-rw-r--r--alot/commands/globals.py21
-rw-r--r--alot/commands/thread.py46
-rw-r--r--alot/crypto.py5
-rw-r--r--alot/db/envelope.py14
-rw-r--r--alot/db/manager.py11
-rw-r--r--alot/db/utils.py11
-rw-r--r--alot/helper.py4
-rw-r--r--alot/ui.py11
9 files changed, 80 insertions, 51 deletions
diff --git a/alot/account.py b/alot/account.py
index 461d2bbf..fe304ac6 100644
--- a/alot/account.py
+++ b/alot/account.py
@@ -213,9 +213,11 @@ class Account(object):
replied_tags = replied_tags or []
passed_tags = passed_tags or []
- self.address = Address.from_string(address, case_sensitive=case_sensitive_username)
- self.aliases = [Address.from_string(a, case_sensitive=case_sensitive_username)
- for a in (aliases or [])]
+ self.address = Address.from_string(
+ address, case_sensitive=case_sensitive_username)
+ self.aliases = [
+ Address.from_string(a, case_sensitive=case_sensitive_username)
+ for a in (aliases or [])]
self.alias_regexp = alias_regexp
self.realname = realname
self.encrypt_to_self = encrypt_to_self
diff --git a/alot/commands/globals.py b/alot/commands/globals.py
index d335e8cf..4e272b8e 100644
--- a/alot/commands/globals.py
+++ b/alot/commands/globals.py
@@ -271,9 +271,10 @@ class ExternalCommand(Command):
def thread_code(*_):
try:
- proc = subprocess.Popen(self.cmdlist, shell=self.shell,
- stdin=subprocess.PIPE if stdin else None,
- stderr=subprocess.PIPE)
+ proc = subprocess.Popen(
+ self.cmdlist, shell=self.shell,
+ stdin=subprocess.PIPE if stdin else None,
+ stderr=subprocess.PIPE)
except OSError as e:
return str(e)
@@ -623,8 +624,8 @@ class HelpCommand(Command):
globalmaps, modemaps = settings.get_keybindings(ui.mode)
# build table
- maxkeylength = len(max(list(modemaps.keys()) + list(globalmaps.keys()),
- key=len))
+ maxkeylength = len(
+ max(list(modemaps.keys()) + list(globalmaps.keys()), key=len))
keycolumnwidth = maxkeylength + 2
linewidgets = []
@@ -689,10 +690,12 @@ class HelpCommand(Command):
class ComposeCommand(Command):
"""compose a new email"""
- def __init__(self, envelope=None, headers=None, template=None, sender=u'',
- tags=None, subject=u'', to=None, cc=None, bcc=None, attach=None,
- omit_signature=False, spawn=None, rest=None, encrypt=False,
- **kwargs):
+ def __init__(
+ self,
+ envelope=None, headers=None, template=None, sender=u'',
+ tags=None, subject=u'', to=None, cc=None, bcc=None, attach=None,
+ omit_signature=False, spawn=None, rest=None, encrypt=False,
+ **kwargs):
"""
:param envelope: use existing envelope
:type envelope: :class:`~alot.db.envelope.Envelope`
diff --git a/alot/commands/thread.py b/alot/commands/thread.py
index a6380ac9..5d8a7939 100644
--- a/alot/commands/thread.py
+++ b/alot/commands/thread.py
@@ -72,30 +72,34 @@ def determine_sender(mail, action='reply'):
# pick the most important account that has an address in candidates
# and use that accounts realname and the address found here
for account in my_accounts:
- acc_addresses = [re.escape(str(a)) for a in account.get_addresses()]
+ acc_addresses = [
+ re.escape(str(a)) for a in account.get_addresses()]
if account.alias_regexp is not None:
acc_addresses.append(account.alias_regexp)
for alias in acc_addresses:
regex = re.compile(
u'^' + str(alias) + u'$',
- flags=re.IGNORECASE if not account.address.case_sensitive else 0)
+ flags=(
+ re.IGNORECASE if not account.address.case_sensitive
+ else 0))
for seen_name, seen_address in candidate_addresses:
- if regex.match(seen_address):
- logging.debug("match!: '%s' '%s'", seen_address, alias)
- if settings.get(action + '_force_realname'):
- realname = account.realname
- else:
- realname = seen_name
- if settings.get(action + '_force_address'):
- address = account.address
- else:
- address = seen_address
-
- logging.debug('using realname: "%s"', realname)
- logging.debug('using address: %s', address)
-
- from_value = formataddr((realname, str(address)))
- return from_value, account
+ if not regex.match(seen_address):
+ continue
+ logging.debug("match!: '%s' '%s'", seen_address, alias)
+ if settings.get(action + '_force_realname'):
+ realname = account.realname
+ else:
+ realname = seen_name
+ if settings.get(action + '_force_address'):
+ address = account.address
+ else:
+ address = seen_address
+
+ logging.debug('using realname: "%s"', realname)
+ logging.debug('using address: %s', address)
+
+ from_value = formataddr((realname, str(address)))
+ return from_value, account
# revert to default account if nothing found
account = my_accounts[0]
@@ -241,7 +245,11 @@ class ReplyCommand(Command):
# Reply-To is standart reply target RFC 2822:, RFC 1036: 2.2.1
# X-BeenThere is needed by sourceforge ML also winehq
# X-Mailing-List is also standart and is used by git-send-mail
- to = mail['Reply-To'] or mail['X-BeenThere'] or mail['X-Mailing-List']
+ to = (
+ mail['Reply-To']
+ or mail['X-BeenThere']
+ or mail['X-Mailing-List']
+ )
# Some mail server (gmail) will not resend you own mail, so you
# have to deal with the one in sent
if to is None:
diff --git a/alot/crypto.py b/alot/crypto.py
index 247dbd19..e7e0bd36 100644
--- a/alot/crypto.py
+++ b/alot/crypto.py
@@ -112,8 +112,9 @@ def get_key(keyid, validate=False, encrypt=False, sign=False,
else:
raise e # pragma: nocover
if signed_only and not check_uid_validity(key, keyid):
- raise GPGProblem('Cannot find a trusworthy key for "{}".'.format(keyid),
- code=GPGCode.NOT_FOUND)
+ raise GPGProblem(
+ 'Cannot find a trusworthy key for "{}".'.format(keyid),
+ code=GPGCode.NOT_FOUND)
return key
diff --git a/alot/db/envelope.py b/alot/db/envelope.py
index b742ba81..89a99ffa 100644
--- a/alot/db/envelope.py
+++ b/alot/db/envelope.py
@@ -223,9 +223,10 @@ class Envelope(object):
# wrap signature in MIMEcontainter
stype = 'pgp-signature; name="signature.asc"'
- signature_mime = MIMEApplication(_data=signature_str.decode('ascii'),
- _subtype=stype,
- _encoder=encode_7or8bit)
+ signature_mime = MIMEApplication(
+ _data=signature_str.decode('ascii'),
+ _subtype=stype,
+ _encoder=encode_7or8bit)
signature_mime['Content-Description'] = 'signature'
signature_mime.set_charset('us-ascii')
@@ -255,9 +256,10 @@ class Envelope(object):
_encoder=encode_7or8bit)
encryption_mime.set_charset('us-ascii')
- encrypted_mime = MIMEApplication(_data=encrypted_str.decode('ascii'),
- _subtype='octet-stream',
- _encoder=encode_7or8bit)
+ encrypted_mime = MIMEApplication(
+ _data=encrypted_str.decode('ascii'),
+ _subtype='octet-stream',
+ _encoder=encode_7or8bit)
encrypted_mime.set_charset('us-ascii')
outer_msg.attach(encryption_mime)
outer_msg.attach(encrypted_mime)
diff --git a/alot/db/manager.py b/alot/db/manager.py
index cbde9c88..057c72d0 100644
--- a/alot/db/manager.py
+++ b/alot/db/manager.py
@@ -160,15 +160,14 @@ class DBManager(object):
for msg in query.search_messages():
msg.freeze()
if cmd == 'tag':
- for tag in tags:
- msg.add_tag(tag, sync_maildir_flags=sync)
+ strategy = msg.add_tag
if cmd == 'set':
msg.remove_all_tags()
- for tag in tags:
- msg.add_tag(tag, sync_maildir_flags=sync)
+ strategy = msg.add_tag
elif cmd == 'untag':
- for tag in tags:
- msg.remove_tag(tag, sync_maildir_flags=sync)
+ strategy = msg.remove_tag
+ for tag in tags:
+ strategy(tag, sync_maildir_flags=sync)
msg.thaw()
logging.debug('ended atomic')
diff --git a/alot/db/utils.py b/alot/db/utils.py
index ef51a8b5..e4eedf1c 100644
--- a/alot/db/utils.py
+++ b/alot/db/utils.py
@@ -359,6 +359,17 @@ def extract_body(mail, types=None, field_key='copiousoutput'):
cte = str(part.get('content-transfer-encoding', '7bit')).lower()
payload = part.get_payload()
if cte == '8bit':
+ if cte == 'quoted-printable':
+ raw_payload = quopri.decodestring(payload.encode('ascii'))
+ elif cte == 'base64':
+ raw_payload = base64.b64decode(payload)
+ else:
+ raise Exception(
+ 'Unknown Content-Transfer-Encoding {}'.format(cte))
+ # message.get_payload(decode=True) also handles a number of unicode
+ # encodindigs. maybe those are useful?
+ payload = raw_payload.decode(enc)
+ elif cte == '8bit':
# Python's mail library may decode 8bit as raw-unicode-escape, so
# we need to encode that back to bytes so we can decode it using
# the correct encoding, or it might not, in which case assume that
diff --git a/alot/helper.py b/alot/helper.py
index 4d8d782e..e621f751 100644
--- a/alot/helper.py
+++ b/alot/helper.py
@@ -640,7 +640,9 @@ def email_as_bytes(mail):
# If we get here and the assert triggers it means that different
# parts of the email are encoded differently. I don't think we're
# likely to see that, but it's possible
- assert {'utf-8', 'ascii', 'us-ascii'}.issuperset(charsets), charsets
+ if not {'utf-8', 'ascii', 'us-ascii'}.issuperset(charsets):
+ raise RuntimeError(
+ "different encodings detected: {}".format(charsets))
charset = 'utf-8' # It's a strict super-set
else:
charset = 'utf-8'
diff --git a/alot/ui.py b/alot/ui.py
index deec3ab1..b3430e07 100644
--- a/alot/ui.py
+++ b/alot/ui.py
@@ -103,11 +103,12 @@ class UI(object):
self._recipients_hist_file, size=size)
# set up main loop
- self.mainloop = urwid.MainLoop(self.root_widget,
- handle_mouse=settings.get('handle_mouse'),
- event_loop=urwid.TwistedEventLoop(),
- unhandled_input=self._unhandled_input,
- input_filter=self._input_filter)
+ self.mainloop = urwid.MainLoop(
+ self.root_widget,
+ handle_mouse=settings.get('handle_mouse'),
+ event_loop=urwid.TwistedEventLoop(),
+ unhandled_input=self._unhandled_input,
+ input_filter=self._input_filter)
# Create a defered that calls the loop_hook
loop_hook = settings.get_hook('loop_hook')