diff options
author | pazz <patricktotzke@gmail.com> | 2011-07-28 09:10:29 +0100 |
---|---|---|
committer | pazz <patricktotzke@gmail.com> | 2011-07-28 09:10:29 +0100 |
commit | ba3f0df9785efcbbcd9e0a30e9c9d849e1f76470 (patch) | |
tree | 46f6ab6ea2db46f292800fae894bedb61a431c23 | |
parent | f9335d9e1302809ac6ff08266304a5940904c18f (diff) |
fix reply
-rw-r--r-- | alot/buffer.py | 32 | ||||
-rw-r--r-- | alot/command.py (renamed from alot/commands.py) | 206 | ||||
-rw-r--r-- | alot/commandfactory.py | 65 | ||||
-rw-r--r-- | alot/message.py | 3 |
4 files changed, 89 insertions, 217 deletions
diff --git a/alot/buffer.py b/alot/buffer.py index 06c2986f..6c01023d 100644 --- a/alot/buffer.py +++ b/alot/buffer.py @@ -225,35 +225,3 @@ class TagListBuffer(Buffer): (attrwidget, pos) = self.taglist.get_focus() tagwidget = attrwidget.original_widget return tagwidget.get_tag() - - -class EnvelopeBuffer(Buffer): - def __init__(self, ui, email): - self.ui = ui - self.email = email - self.rebuild() - Buffer.__init__(self, ui, self.body, 'envelope') - self.autoparms = {'email': self.get_email} - - def __str__(self): - return "to: %s" % decode_header(self.email['To']) - - def get_email(self): - return self.email - - def set_email(self, mail): - self.email = mail - self.rebuild() - - def rebuild(self): - displayed_widgets = [] - dh = config.getstringlist('general', 'displayed_headers') - self.header_wgt = widgets.MessageHeaderWidget(self.email, - displayed_headers=dh) - displayed_widgets.append(self.header_wgt) - self.body_wgt = widgets.MessageBodyWidget(self.email) - displayed_widgets.append(self.body_wgt) - self.body = urwid.ListBox(displayed_widgets) - - -from commandfactory import commandfactory diff --git a/alot/commands.py b/alot/command.py index a643b827..97191304 100644 --- a/alot/commands.py +++ b/alot/command.py @@ -29,7 +29,6 @@ from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email import Charset from email.header import Header -import tempfile import buffer import settings @@ -279,7 +278,7 @@ class OpenEnvelopeCommand(Command): Command.__init__(self, **kwargs) def apply(self, ui): - ui.buffer_open(buffer.EnvelopeBuffer(ui, email=self.email)) + ui.buffer_open(envelope.EnvelopeBuffer(ui, email=self.email)) class CommandPromptCommand(Command): @@ -351,25 +350,6 @@ class ToggleThreadTagCommand(Command): pass -class SendMailCommand(Command): - - def apply(self, ui): - envelope = ui.current_buffer - mail = envelope.get_email() - sname, saddr = email.Utils.parseaddr(mail.get('From')) - account = settings.accounts.get_account_by_address(saddr) - if account: - success, reason = account.sender.send_mail(mail) - if success: - cmd = BufferCloseCommand(buffer=envelope) - ui.apply_command(cmd) - ui.notify('mail send successful') - else: - ui.notify('failed to send: %s' % reason) - else: - ui.notify('failed to send: no account set up for %s' % saddr) - - class ComposeCommand(Command): def __init__(self, mail=None, **kwargs): if not mail: @@ -412,64 +392,6 @@ class ComposeCommand(Command): ui.apply_command(OpenEnvelopeCommand(email=self.mail)) -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() - # set body text - mailcontent = '\nOn %s, %s wrote:\n' % (msg.get_datestring(), - msg.get_author()[0]) - for line in msg.accumulate_body().splitlines(): - mailcontent += '>' + line + '\n' - - Charset.add_charset('utf-8', Charset.QP, Charset.QP, 'utf-8') - bodypart = MIMEText(mailcontent.encode('utf-8'), 'plain', 'UTF-8') - reply = MIMEMultipart() - reply.attach(bodypart) - - # copy subject - subject = mail['Subject'] - if not subject.startswith('Re:'): - 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) - - #TODO - # extract from address from to,cc,bcc fields or leave blank - # (composeCommand will prompt) - - ui.apply_command(ComposeCommand(mail=reply)) - - -class BounceMailCommand(Command): - def apply(self, ui): - msg = ui.current_buffer.get_selected_message() - mail = msg.get_email() - del(mail['To']) - ui.apply_command(ComposeCommand(mail=mail)) - - class RetagPromptCommand(Command): """start a commandprompt to retag selected threads' tags""" @@ -532,79 +454,59 @@ class RefinePromptCommand(Command): ui.commandprompt('refine ' + oldquery) -class EnvelopeEditCommand(Command): - """re-edits mail in from envelope buffer""" - def apply(self, ui): - self.mail = ui.current_buffer.get_email() - - def openEnvelopeFromTmpfile(): - f = open(tf.name) - editor_input = f.read().decode('utf-8') - - #split editor out - headertext, bodytext = editor_input.split('\n\n', 1) - - #reply = MIMEText(mailcontent.encode('utf-8'), 'plain', 'UTF-8') - for line in headertext.splitlines(): - logging.debug(line) - key, value = line.split(':', 1) - value = value.strip().encode('utf-8') - del self.mail[key] # ensure there is only one - self.mail[key] = Header(value, 'UTF-8').encode() - - Charset.add_charset('utf-8', Charset.QP, Charset.QP, 'utf-8') - if self.mail.is_multipart(): - for part in self.mail.walk(): - if part.get_content_maintype() == 'text': - part.set_payload(bodytext, 'utf-8') - break - - f.close() - os.unlink(tf.name) - ui.current_buffer.set_email(self.mail) - - # decode header - edit_headers = ['Subject', 'To', 'From'] - headertext = u'' - for key in edit_headers: - value = u'' - if key in self.mail: - value = decode_header(self.mail[key]) - headertext += '%s: %s\n' % (key, value) - - if self.mail.is_multipart(): - for part in self.mail.walk(): - if part.get_content_maintype() == 'text': - bodytext = decode_to_unicode(part) - break - else: - bodytext = decode_to_unicode(self.mail) - - #write stuff to tempfile - tf = tempfile.NamedTemporaryFile(delete=False) - content = '%s\n\n%s' % (headertext, - bodytext) - tf.write(content.encode('utf-8')) - tf.flush() - tf.close() - ui.apply_command(EditCommand(tf.name, - on_success=openEnvelopeFromTmpfile, - refocus=False)) - - -class EnvelopeSetCommand(Command): - """sets header fields of mail open in envelope buffer""" - - def __init__(self, key='', value='', **kwargs): - self.key = key - self.value = value +class ReplyCommand(Command): + def __init__(self, groupreply=True, **kwargs): + self.groupreply = groupreply Command.__init__(self, **kwargs) def apply(self, ui): - envelope = ui.current_buffer - mail = envelope.get_email() - if self.key in mail: - mail.replace_header(self.key, self.value) - else: - mail[self.key] = self.value - envelope.rebuild() + msg = ui.current_buffer.get_selected_message() + mail = msg.get_email() + # set body text + mailcontent = '\nOn %s, %s wrote:\n' % (msg.get_datestring(), + msg.get_author()[0]) + for line in msg.accumulate_body().splitlines(): + mailcontent += '>' + line + '\n' + + Charset.add_charset('utf-8', Charset.QP, Charset.QP, 'utf-8') + bodypart = MIMEText(mailcontent.encode('utf-8'), 'plain', 'UTF-8') + reply = MIMEMultipart() + reply.attach(bodypart) + + # copy subject + subject = mail['Subject'] + if not subject.startswith('Re:'): + 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) + + #TODO + # extract from address from to,cc,bcc fields or leave blank + # (composeCommand will prompt) + + ui.apply_command(ComposeCommand(mail=reply)) + + +class BounceMailCommand(Command): + def apply(self, ui): + msg = ui.current_buffer.get_selected_message() + mail = msg.get_email() + del(mail['To']) + ui.apply_command(ComposeCommand(mail=mail)) +import envelope diff --git a/alot/commandfactory.py b/alot/commandfactory.py index e12eb7ec..f1b314ea 100644 --- a/alot/commandfactory.py +++ b/alot/commandfactory.py @@ -21,42 +21,43 @@ import os from settings import hooks -import commands +import command +import envelope COMMANDS = { - 'bnext': (commands.BufferFocusCommand, {'offset': 1}), - 'bprevious': (commands.BufferFocusCommand, {'offset': -1}), - 'bufferlist': (commands.OpenBufferListCommand, {}), - 'close': (commands.BufferCloseCommand, {}), - 'closefocussed': (commands.BufferCloseCommand, {'focussed': True}), - 'openfocussed': (commands.BufferFocusCommand, {}), - 'commandprompt': (commands.CommandPromptCommand, {}), - 'compose': (commands.ComposeCommand, {}), - 'edit': (commands.EditCommand, {}), - 'exit': (commands.ExitCommand, {}), - 'flush': (commands.FlushCommand, {}), - 'openthread': (commands.OpenThreadCommand, {}), - 'prompt': (commands.PromptCommand, {}), - 'pyshell': (commands.PythonShellCommand, {}), - 'refine': (commands.RefineCommand, {}), - 'refineprompt': (commands.RefinePromptCommand, {}), - 'refresh': (commands.RefreshCommand, {}), - 'search': (commands.SearchCommand, {}), - 'shellescape': (commands.ExternalCommand, {}), - 'taglist': (commands.TagListCommand, {}), - 'toggletag': (commands.ToggleThreadTagCommand, {'tag': 'inbox'}), + 'bnext': (command.BufferFocusCommand, {'offset': 1}), + 'bprevious': (command.BufferFocusCommand, {'offset': -1}), + 'bufferlist': (command.OpenBufferListCommand, {}), + 'close': (command.BufferCloseCommand, {}), + 'closefocussed': (command.BufferCloseCommand, {'focussed': True}), + 'openfocussed': (command.BufferFocusCommand, {}), + 'commandprompt': (command.CommandPromptCommand, {}), + 'compose': (command.ComposeCommand, {}), + 'edit': (command.EditCommand, {}), + 'exit': (command.ExitCommand, {}), + 'flush': (command.FlushCommand, {}), + 'openthread': (command.OpenThreadCommand, {}), + 'prompt': (command.PromptCommand, {}), + 'pyshell': (command.PythonShellCommand, {}), + 'refine': (command.RefineCommand, {}), + 'refineprompt': (command.RefinePromptCommand, {}), + 'refresh': (command.RefreshCommand, {}), + 'search': (command.SearchCommand, {}), + 'shellescape': (command.ExternalCommand, {}), + 'taglist': (command.TagListCommand, {}), + 'toggletag': (command.ToggleThreadTagCommand, {'tag': 'inbox'}), # envelope - 'send': (commands.SendMailCommand, {}), - 'reedit': (commands.EnvelopeEditCommand, {}), - 'subject': (commands.EnvelopeSetCommand, {'key': 'Subject'}), - 'to': (commands.EnvelopeSetCommand, {'key': 'To'}), - - 'open_envelope': (commands.OpenEnvelopeCommand, {}), - 'retag': (commands.RetagCommand, {}), - 'retagprompt': (commands.RetagPromptCommand, {}), + 'send': (envelope.SendMailCommand, {}), + 'reedit': (envelope.EnvelopeEditCommand, {}), + 'subject': (envelope.EnvelopeSetCommand, {'key': 'Subject'}), + 'to': (envelope.EnvelopeSetCommand, {'key': 'To'}), + + 'open_envelope': (command.OpenEnvelopeCommand, {}), + 'retag': (command.RetagCommand, {}), + 'retagprompt': (command.RetagPromptCommand, {}), # thread - 'reply': (commands.ReplyCommand, {}), - 'bounce': (commands.BounceMailCommand, {}), + 'reply': (command.ReplyCommand, {}), + 'bounce': (command.BounceMailCommand, {}), } diff --git a/alot/message.py b/alot/message.py index 198980cf..e52cda3c 100644 --- a/alot/message.py +++ b/alot/message.py @@ -207,8 +207,9 @@ def decode_header(header): value = value + v.decode(enc) else: value = value + v + value = value.replace('\r','') + value = value.replace('\n',' ') return value - class Attachment: """represents a single mail attachment""" |