summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2012-09-20 10:44:38 +0100
committerPatrick Totzke <patricktotzke@gmail.com>2012-09-22 10:40:29 +0100
commit7536499f30542e3d2119732aaa99fc226131b544 (patch)
treedccced3df75c55fa1a4bef5e3a16b1b7d115fe7e /alot
parent4bf2bb9c88c25fab54613dcce78de46ef8bbefdf (diff)
more flexible construction of "From" headers
... when replying/forwarding mails. This now respects the new reply_force_realname and reply_force_address config options and uses regex to match recipients with ones own addresses. This way one can define aliases matching "plussed" recipient addresses like this: [accounts] [[gmail]] realname = Patrick Totzke address = patricktotzke@gmail.com aliases = patricktotzke@googlemail.com, patricktotzke\+.*@gmail.com cf issue #515
Diffstat (limited to 'alot')
-rw-r--r--alot/commands/thread.py35
1 files changed, 24 insertions, 11 deletions
diff --git a/alot/commands/thread.py b/alot/commands/thread.py
index 58f6b4ef..43d6e9c8 100644
--- a/alot/commands/thread.py
+++ b/alot/commands/thread.py
@@ -2,6 +2,7 @@
# This file is released under the GNU GPL, version 3 or a later revision.
# For further details see the COPYING file
import os
+import re
import logging
import tempfile
from twisted.internet.defer import inlineCallbacks
@@ -54,22 +55,36 @@ def recipient_to_from(mail, my_accounts):
if delivered_to is not None:
recipients.append(delivered_to)
+ logging.debug('recipients: %s' % recipients)
# 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
+ for alias_re in acc_addresses:
+ if realname is not None:
+ break
+ regex = re.compile(alias_re)
+ for rec in recipients:
+ seen_name, seen_address = parseaddr(rec)
+ if regex.match(seen_address):
+ logging.debug("match!: '%s' '%s'" % (seen_address, alias_re))
+ if settings.get('reply_force_realname'):
+ realname = acc.realname
+ else:
+ realname = seen_name
+ if settings.get('reply_force_address'):
+ address = acc.address
+ else:
+ address = seen_address
# revert to default account if nothing found
if realname is None:
realname = my_accounts[0].realname
address = my_accounts[0].address
- return realname, address
+ logging.debug('using realname: "%s"' % realname)
+ logging.debug('using address: %s' % address)
+
+ return address if realname == '' else '%s <%s>' % (realname, address)
@registerCommand(MODE, 'reply', arguments=[
@@ -135,8 +150,7 @@ class ReplyCommand(Command):
envelope.add('Subject', subject)
# set From
- realname, address = recipient_to_from(mail, my_accounts)
- envelope.add('From', '%s <%s>' % (realname, address))
+ envelope.add('From', recipient_to_from(mail, my_accounts))
# set To
sender = mail['Reply-To'] or mail['From']
@@ -258,8 +272,7 @@ class ForwardCommand(Command):
envelope.add('Subject', subject)
# set From
- realname, address = recipient_to_from(mail, my_accounts)
- envelope.add('From', '%s <%s>' % (realname, address))
+ envelope.add('From', recipient_to_from(mail, my_accounts))
# continue to compose
ui.apply_command(ComposeCommand(envelope=envelope,