diff options
author | patrick <p.totzke@ed.ac.uk> | 2011-07-26 14:18:30 +0100 |
---|---|---|
committer | patrick <p.totzke@ed.ac.uk> | 2011-07-26 14:18:30 +0100 |
commit | d64475a92e472865d50f5ac6b7c0c39c6654ff5c (patch) | |
tree | 05896b770d6f7976606793e64b09ba8362772fc4 | |
parent | 475b65bde3ee4a331676a8ac8ebbd2f91d049e22 (diff) |
reply command
-rw-r--r-- | alot/commandfactory.py | 6 | ||||
-rw-r--r-- | alot/commands.py | 38 |
2 files changed, 41 insertions, 3 deletions
diff --git a/alot/commandfactory.py b/alot/commandfactory.py index 80d321d0..985583be 100644 --- a/alot/commandfactory.py +++ b/alot/commandfactory.py @@ -54,6 +54,8 @@ COMMANDS = { 'open_envelope': (commands.OpenEnvelopeCommand, {}), 'retag': (commands.RetagCommand, {}), 'retagprompt': (commands.RetagPromptCommand, {}), + # thread + 'reply': (commands.ReplyCommand, {}), } @@ -108,7 +110,7 @@ ALLOWED_COMMANDS = { 'envelope': ['send', 'reedit', 'to', 'subject'] + globalcomands, 'bufferlist': ['openfocussed', 'closefocussed'] + globalcomands, 'taglist': globalcomands, - 'thread': ['toggletag'] + globalcomands, + 'thread': ['toggletag', 'reply'] + globalcomands, } @@ -140,7 +142,7 @@ def interpret_commandline(cmdline, mode): if not params: # commands that work without parameter if cmd in ['exit', 'flush', 'pyshell', 'taglist', 'close', 'compose', 'openfocussed', 'closefocussed', 'bnext', 'bprevious', - 'retag', 'refresh', 'bufferlist', 'refineprompt', + 'retag', 'refresh', 'bufferlist', 'refineprompt', 'reply', 'openthread', 'send', 'reedit', 'retagprompt']: return commandfactory(cmd) else: diff --git a/alot/commands.py b/alot/commands.py index 6324988a..dde5fdf4 100644 --- a/alot/commands.py +++ b/alot/commands.py @@ -73,7 +73,7 @@ class OpenThreadCommand(Command): # in case the thread is yet unread, remove this tag if 'unread' in self.thread.get_tags(): - self.thread.remove_tags(['unread']) + self.thread.remove_tags(['unread'], sync_maildir_flags=True) ui.apply_command(FlushCommand()) self.thread.refresh() @@ -429,6 +429,42 @@ class ComposeCommand(Command): refocus=False)) +class ReplyCommand(Command): + + def __init__(self, groupreply=True, **kwargs): + self.groupreply = groupreply + Command.__init__(self, **kwargs) + + def apply(self, ui): + msg = ui.current_buffer.get_selected_message() + mail = msg.get_email() + mailcontent = '' + # set In-Reply-To header + mailcontent += 'In-Reply-To: %s' % 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()) + mailcontent += 'References: %s' % ' '.join(references) + + # extract from address from to,cc,bcc fields or leave blank + # (composeCommand will prompt) + + # set body text + mailcontent += '\nOn %s, %s wrote' % (msg.get_datestring(), + msg.get_author()[0]) + for line in msg.accumulate_body().split(): + mailcontent += '>' + line + '\n' + + reply = email.message_from_string(mailcontent) + ui.apply_command(ComposeCommand(mail=reply)) + + class RetagPromptCommand(Command): """start a commandprompt to retag selected threads' tags""" |