summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2017-09-06 14:10:35 -0700
committerDylan Baker <dylan@pnwbakers.com>2017-09-06 14:28:23 -0700
commite1b17942b0ec6fbd351df4c807debd4dc141dcdb (patch)
treea3f70118d78999eb99beb9fbc4b18286c31c5a3b
parent994320a2750bf6a765cc80d6d8e7ee44927ea3f7 (diff)
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
-rw-r--r--alot/account.py10
-rw-r--r--tests/account_test.py1
2 files changed, 8 insertions, 3 deletions
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
diff --git a/tests/account_test.py b/tests/account_test.py
index 5761e62f..cfc51bf8 100644
--- a/tests/account_test.py
+++ b/tests/account_test.py
@@ -164,7 +164,6 @@ class TestAddress(unittest.TestCase):
addr = account.Address(u'user', u'éxample.com', case_sensitive=True)
self.assertEqual(addr, u'user@Éxample.com')
- @unittest.expectedFailure
def test_cmp_empty(self):
addr = account.Address(u'user', u'éxample.com')
self.assertNotEqual(addr, u'')