From e1b17942b0ec6fbd351df4c807debd4dc141dcdb Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 6 Sep 2017 14:10:35 -0700 Subject: account: Fix Address comparison to b'' and u'' This uses a try/except because comparing an address to an empty string should be a fairly uncommon event and try/except will be faster than `if '@' not in other` in the case where '@' is in other. This stops alot from crashing if there is no 'From' header in the email. Outlook generates drafts without a 'From' header. Fixes #1050 --- alot/account.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'alot/account.py') diff --git a/alot/account.py b/alot/account.py index a224c109..b1223902 100644 --- a/alot/account.py +++ b/alot/account.py @@ -122,9 +122,15 @@ class Address(object): The intention is to use functions from the operator module. """ if isinstance(other, unicode): - ouser, odomain = other.split(u'@') + try: + ouser, odomain = other.split(u'@') + except ValueError: + ouser, odomain = u'', u'' elif isinstance(other, str): - ouser, odomain = other.decode('utf-8').split(u'@') + try: + ouser, odomain = other.decode('utf-8').split(u'@') + except ValueError: + ouser, odomain = '', '' else: ouser = other.username odomain = other.domainname -- cgit v1.2.3