summaryrefslogtreecommitdiff
path: root/alot/command.py
diff options
context:
space:
mode:
authorpazz <patricktotzke@gmail.com>2011-07-30 00:14:45 +0100
committerpazz <patricktotzke@gmail.com>2011-07-30 00:14:45 +0100
commit71730badf4494dcf77e55ec7ca10723dd9be531f (patch)
tree30dd7fe129789ba9c360a3ba27c13d1503ee966b /alot/command.py
parent7edbb06349b4292c41ab08ad82fb755c66936a9f (diff)
groupreply, pep8 and direct edit after compose
completes issue #54
Diffstat (limited to 'alot/command.py')
-rw-r--r--alot/command.py70
1 files changed, 41 insertions, 29 deletions
diff --git a/alot/command.py b/alot/command.py
index 5e46aab4..d8ccc30b 100644
--- a/alot/command.py
+++ b/alot/command.py
@@ -80,6 +80,7 @@ class OpenThreadCommand(Command):
sb = buffer.SingleThreadBuffer(ui, self.thread)
ui.buffer_open(sb)
+
class SearchCommand(Command):
"""open a new search buffer"""
def __init__(self, query, force_new=False, **kwargs):
@@ -375,7 +376,7 @@ class ComposeCommand(Command):
fromaddress = ui.prompt(prefix='From>', completer=cmpl, tab=1)
validaddresses = [a.address for a in accounts] + [None]
while fromaddress not in validaddresses:
- ui.notify('couldn\'t find a matching account. (<esc> cancels)')
+ ui.notify('no account for this address. (<esc> cancels)')
fromaddress = ui.prompt(prefix='From>', completer=cmpl)
if not fromaddress:
ui.notify('canceled')
@@ -392,7 +393,7 @@ class ComposeCommand(Command):
subject = ui.prompt(prefix='Subject>')
self.mail['Subject'] = encode_header('subject', subject)
- ui.apply_command(OpenEnvelopeCommand(email=self.mail))
+ ui.apply_command(envelope.EnvelopeEditCommand(mail=self.mail))
class RetagPromptCommand(Command):
@@ -458,7 +459,7 @@ class RefinePromptCommand(Command):
class ReplyCommand(Command):
- def __init__(self, groupreply=True, **kwargs):
+ def __init__(self, groupreply=False, **kwargs):
self.groupreply = groupreply
Command.__init__(self, **kwargs)
@@ -482,51 +483,62 @@ class ReplyCommand(Command):
subject = 'Re: ' + subject
reply['Subject'] = Header(subject.encode('utf-8'), 'UTF-8').encode()
- # set to
- reply['To'] = Header(mail['From'].encode('utf-8'), 'UTF-8').encode()
-
- # set In-Reply-To header
- del(reply['In-Reply-To'])
- reply['In-Reply-To'] = msg.get_message_id()
-
- # set References header
- old_references = mail['References']
- if old_references:
- old_references = old_references.split()
- references = old_references[-8:]
- if len(old_references) > 8:
- references = old_references[:1] + references
- references.append(msg.get_message_id())
- reply['References'] = ' '.join(references)
-
- # extract from address from to,cc,bcc fields or leave blank
- # (composeCommand will prompt)
+ # set From
my_addresses = ui.accountman.get_account_addresses()
matched_address = ''
in_to = [a for a in my_addresses if a in mail['To']]
if in_to:
- logging.info('found address in to %s' % in_to)
matched_address = in_to[0]
- logging.info(matched_address)
else:
- cc = mail.get('Cc','') + mail.get('Bcc', '')
+ cc = mail.get('Cc', '') + mail.get('Bcc', '')
in_cc = [a for a in my_addresses if a in cc]
if in_cc:
- logging.info('found address in cc')
matched_address = in_cc[0]
if matched_address:
- logging.info(matched_address)
account = ui.accountman.get_account_by_address(matched_address)
fromstring = '%s <%s>' % (account.realname, account.address)
- logging.info(fromstring)
reply['From'] = encode_header('From', fromstring)
+ # set To
+ #reply['To'] = Header(mail['From'].encode('utf-8'), 'UTF-8').encode()
+ del(reply['To'])
+ if self.groupreply:
+ cleared = self.clear_my_address(my_addresses, mail['To'])
+ if cleared:
+ reply['To'] = mail['From'] + ', ' + cleared
+ else:
+ reply['To'] = mail['From']
+ # copy cc and bcc for group-replies
+ if 'Cc' in mail:
+ reply['Cc'] = self.clear_my_address(my_addresses, mail['Cc'])
+ if 'Bcc' in mail:
+ reply['Bcc'] = self.clear_my_address(my_addresses, mail['Bcc'])
+ else:
+ reply['To'] = mail['From']
+ # set In-Reply-To header
+ del(reply['In-Reply-To'])
+ reply['In-Reply-To'] = msg.get_message_id()
-
+ # set References header
+ old_references = mail['References']
+ if old_references:
+ old_references = old_references.split()
+ references = old_references[-8:]
+ if len(old_references) > 8:
+ references = old_references[:1] + references
+ references.append(msg.get_message_id())
+ reply['References'] = ' '.join(references)
ui.apply_command(ComposeCommand(mail=reply))
+ def clear_my_address(self, my_addresses, value):
+ new_value = []
+ for entry in value.split(','):
+ if not [a for a in my_addresses if a in entry]:
+ new_value.append(entry)
+ return ','.join(new_value)
+
class BounceMailCommand(Command):
def apply(self, ui):