diff options
-rw-r--r-- | alot/command.py | 70 | ||||
-rw-r--r-- | alot/commandfactory.py | 6 | ||||
-rw-r--r-- | alot/envelope.py | 20 | ||||
-rw-r--r-- | alot/settings.py | 1 |
4 files changed, 61 insertions, 36 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): diff --git a/alot/commandfactory.py b/alot/commandfactory.py index f1b314ea..490b6a4b 100644 --- a/alot/commandfactory.py +++ b/alot/commandfactory.py @@ -57,6 +57,7 @@ COMMANDS = { 'retagprompt': (command.RetagPromptCommand, {}), # thread 'reply': (command.ReplyCommand, {}), + 'groupreply': (command.ReplyCommand, {'groupreply': True}), 'bounce': (command.BounceMailCommand, {}), } @@ -112,7 +113,7 @@ ALLOWED_COMMANDS = { 'envelope': ['send', 'reedit', 'to', 'subject'] + globalcomands, 'bufferlist': ['openfocussed', 'closefocussed'] + globalcomands, 'taglist': globalcomands, - 'thread': ['toggletag', 'reply', 'bounce'] + globalcomands, + 'thread': ['toggletag', 'reply', 'groupreply', 'bounce'] + globalcomands, } @@ -145,7 +146,8 @@ def interpret_commandline(cmdline, mode): if cmd in ['exit', 'flush', 'pyshell', 'taglist', 'close', 'compose', 'openfocussed', 'closefocussed', 'bnext', 'bprevious', 'retag', 'refresh', 'bufferlist', 'refineprompt', 'reply', - 'bounce', 'openthread', 'send', 'reedit', 'retagprompt']: + 'groupreply', 'bounce', 'openthread', 'send', 'reedit', + 'retagprompt']: return commandfactory(cmd) else: return None diff --git a/alot/envelope.py b/alot/envelope.py index 7deb62a1..02b85695 100644 --- a/alot/envelope.py +++ b/alot/envelope.py @@ -64,9 +64,15 @@ class EnvelopeBuffer(buffer.Buffer): class EnvelopeEditCommand(command.Command): """re-edits mail in from envelope buffer""" + def __init__(self, mail=None, **kwargs): + self.mail = mail + self.openNew = (mail != None) + command.Command.__init__(self, **kwargs) + def apply(self, ui): Charset.add_charset('utf-8', Charset.QP, Charset.QP, 'utf-8') - self.mail = ui.current_buffer.get_email() + if not self.mail: + self.mail = ui.current_buffer.get_email() def openEnvelopeFromTmpfile(): f = open(tf.name) @@ -91,7 +97,10 @@ class EnvelopeEditCommand(command.Command): f.close() os.unlink(tf.name) - ui.current_buffer.set_email(self.mail) + if self.openNew: + ui.apply_command(command.OpenEnvelopeCommand(email=self.mail)) + else: + ui.current_buffer.set_email(self.mail) # decode header edit_headers = ['Subject', 'To', 'From'] @@ -117,9 +126,9 @@ class EnvelopeEditCommand(command.Command): tf.write(content.encode('utf-8')) tf.flush() tf.close() - ui.apply_command(command.EditCommand(tf.name, - on_success=openEnvelopeFromTmpfile, - refocus=False)) + cmd = command.EditCommand(tf.name, on_success=openEnvelopeFromTmpfile, + refocus=False) + ui.apply_command(cmd) class EnvelopeSetCommand(command.Command): @@ -139,6 +148,7 @@ class EnvelopeSetCommand(command.Command): mail[self.key] = self.value envelope.rebuild() + class SendMailCommand(command.Command): def apply(self, ui): envelope = ui.current_buffer diff --git a/alot/settings.py b/alot/settings.py index 69f1c7a7..1663e94f 100644 --- a/alot/settings.py +++ b/alot/settings.py @@ -316,6 +316,7 @@ MAPPING = { 'thread': { 'a': ('toggletag inbox', ''), 'r': ('reply', ''), + 'g': ('groupreply', ''), }, 'taglist': { # 'enter': ('search', {'query': (lambda: 'tag:' + |