summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2012-01-26 16:19:57 +0000
committerPatrick Totzke <patricktotzke@gmail.com>2012-01-26 16:19:57 +0000
commita488e41d4a9145085360df2dbb3129e8b41ca38e (patch)
treeee20062fe6f38da611cf859277d5767d3f4dd4b7
parentb64f9bf0040abaffac9058755bd5d39bd471a752 (diff)
parent5abbcffc61ccdd127bb5cc5863cc8a358e6df0da (diff)
Merge branch 'feature-reply-from' into testing
-rw-r--r--alot/account.py5
-rw-r--r--alot/commands/thread.py48
2 files changed, 39 insertions, 14 deletions
diff --git a/alot/account.py b/alot/account.py
index 8b3607d6..c7f0df89 100644
--- a/alot/account.py
+++ b/alot/account.py
@@ -92,6 +92,11 @@ class Account(object):
self.draft_box = mailbox.MMDF(mburl.path)
self.draft_tags = draft_tags
+ def get_addresses(self):
+ """return all email addresses connected to this account, in order of
+ their importance"""
+ return [self.address] + self.aliases
+
def store_mail(self, mbx, mail, tags=None):
"""
stores given mail in mailbox. If mailbox is maildir, set the S-flag.
diff --git a/alot/commands/thread.py b/alot/commands/thread.py
index 38c0218c..01afc132 100644
--- a/alot/commands/thread.py
+++ b/alot/commands/thread.py
@@ -5,6 +5,7 @@ from twisted.internet.defer import inlineCallbacks
import shlex
import re
import subprocess
+from email.Utils import parseaddr
from alot.commands import Command, registerCommand
from alot.commands.globals import ExternalCommand
@@ -66,24 +67,43 @@ class ReplyCommand(Command):
envelope.add('Subject', subject)
# set From
- my_addresses = ui.accountman.get_addresses()
- matched_address = ''
- in_to = [a for a in my_addresses if a in mail.get('To', '')]
- if in_to:
- matched_address = in_to[0]
- else:
- cc = mail.get('Cc', '') + mail.get('Bcc', '')
- in_cc = [a for a in my_addresses if a in cc]
- if in_cc:
- matched_address = in_cc[0]
- if matched_address:
- account = ui.accountman.get_account_by_address(matched_address)
- fromstring = '%s <%s>' % (account.realname, account.address)
- envelope.add('From', fromstring)
+ realname = None
+ address = None
+ my_accounts = ui.accountman.get_accounts()
+ if not my_accounts:
+ ui.notify('no accounts set', priority='error')
+ return
+
+ # extract list of recipients to check for my address
+ rec_to = filter(lambda x: x, mail.get('To', '').split(','))
+ rec_cc = filter(lambda x: x, mail.get('Cc', '').split(','))
+ delivered_to = mail.get('Delivered-To', None)
+ recipients = rec_to + rec_cc
+ if delivered_to is not None:
+ recipients.append(delivered_to)
+
+ # pick the most important account that has an address in recipients
+ # and use that accounts realname and the found recipient address
+ for acc in my_accounts:
+ acc_addresses = acc.get_addresses()
+ for rec in recipients:
+ _, raddress = parseaddr(rec)
+ raddress = raddress.decode()
+ if raddress in acc_addresses and realname is None:
+ realname = acc.realname
+ address = raddress
+
+ # revert to default account if nothing found
+ if realname is None:
+ realname = my_accounts[0].realname
+ address = my_accounts[0].address
+ # add from string
+ envelope.add('From', '%s <%s>' % (realname, address))
# set To
sender = mail['Reply-To'] or mail['From']
recipients = [sender]
+ my_addresses = ui.accountman.get_addresses()
if self.groupreply:
if sender != mail['From']:
recipients.append(mail['From'])