diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2017-09-06 10:52:45 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2017-09-06 14:30:13 -0700 |
commit | d4ea14c7f58e2a7c1981f15aec513517d9268918 (patch) | |
tree | 39a3a3eb3bce20bb40dcf4b69abfa092b865463e | |
parent | ed48c4550427bbcf6d2e64258c4724091c29fa01 (diff) |
db/message: Don't set sender to ''
If the message doesn't have a sender, try to come up with one. If the
message has the draft tag we known that the user is the sender, just use
the default account as the from if we can't find one another way. If it
doesn't have the draft tag just set the sending to 'Unknown'.
-rw-r--r-- | alot/db/message.py | 16 | ||||
-rw-r--r-- | tests/db/message_test.py | 2 |
2 files changed, 12 insertions, 6 deletions
diff --git a/alot/db/message.py b/alot/db/message.py index 9d7437eb..72d87f12 100644 --- a/alot/db/message.py +++ b/alot/db/message.py @@ -45,14 +45,22 @@ class Message(object): except ValueError: self._datetime = None self._filename = msg.get_filename() - try: - self._from = decode_header(msg.get_header('From')) - except NullPointerError: - self._from = '' self._email = None # will be read upon first use self._attachments = None # will be read upon first use self._tags = set(msg.get_tags()) + try: + sender = decode_header(msg.get_header('From')) + except NullPointerError: + sender = None + if sender: + self._from = sender + elif 'draft' in self._tags: + acc = settings.get_accounts()[0] + self._from = '"{}" <{}>'.format(acc.realname, unicode(acc.address)) + else: + self._from = '"Unknown" <>' + def __str__(self): """prettyprint the message""" aname, aaddress = self.get_author() diff --git a/tests/db/message_test.py b/tests/db/message_test.py index 2f198759..a50d943e 100644 --- a/tests/db/message_test.py +++ b/tests/db/message_test.py @@ -88,7 +88,6 @@ class TestMessage(unittest.TestCase): MockNotmuchMessage({'Sender': '"User Name" <user@example.com>'})) self.assertEqual(msg.get_author(), ('User Name', 'user@example.com')) - @unittest.expectedFailure def test_get_author_no_name_draft(self): """Message._from is populated from the default account if the draft tag is present. @@ -102,7 +101,6 @@ class TestMessage(unittest.TestCase): mock.Mock(), MockNotmuchMessage(tags=['draft'])) self.assertEqual(msg.get_author(), ('User Name', 'user@example.com')) - @unittest.expectedFailure def test_get_author_no_name(self): """Message._from is set to 'Unkown' if there is no relavent header and the message is not a draft. |