diff --git a/alot/commands/thread.py b/alot/commands/thread.py index eadad4fcb..da4e6e7db 100644 --- a/alot/commands/thread.py +++ b/alot/commands/thread.py @@ -98,6 +98,25 @@ def determine_sender(mail, action='reply'): return from_value, account +def quote(ui, message=None): + if not message: + tree = ui.current_buffer.get_selected_messagetree() + else: + # I'm assuming the message is in the current buffer. + tree = next(tree for tree in ui.current_buffer.messagetrees() + if tree._message == message) + + quotehook = settings.get_hook('text_quote') + if quotehook: + return quotehook(tree.get_current_text()) + else: + quote_prefix = settings.get('quote_prefix') + mailcontent = "" + for line in tree.get_current_text().splitlines(): + mailcontent += quote_prefix + line + '\n' + return mailcontent + + @registerCommand(MODE, 'reply', arguments=[ (['--all'], {'action': 'store_true', 'help': 'reply to all'}), (['--list'], {'action': cargparse.BooleanAction, 'default': None, @@ -142,14 +161,7 @@ async def apply(self, ui): quotestring = qf(name, address, timestamp, ui=ui, dbm=ui.dbman) else: quotestring = 'Quoting %s (%s)\n' % (name or address, timestamp) - mailcontent = quotestring - quotehook = settings.get_hook('text_quote') - if quotehook: - mailcontent += quotehook(self.message.accumulate_body()) - else: - quote_prefix = settings.get('quote_prefix') - for line in self.message.accumulate_body().splitlines(): - mailcontent += quote_prefix + line + '\n' + mailcontent = quotestring + quote(ui, self.message) envelope = Envelope(bodytext=mailcontent, replied=self.message) @@ -346,18 +358,11 @@ async def apply(self, ui): timestamp = self.message.get_date() qf = settings.get_hook('forward_prefix') if qf: - quote = qf(name, address, timestamp, ui=ui, dbm=ui.dbman) + quotestring = qf(name, address, timestamp, ui=ui, dbm=ui.dbman) else: - quote = 'Forwarded message from %s (%s):\n' % ( + quotestring = 'Forwarded message from %s (%s):\n' % ( name or address, timestamp) - mailcontent = quote - quotehook = settings.get_hook('text_quote') - if quotehook: - mailcontent += quotehook(self.message.accumulate_body()) - else: - quote_prefix = settings.get('quote_prefix') - for line in self.message.accumulate_body().splitlines(): - mailcontent += quote_prefix + line + '\n' + mailcontent = quotestring + quote(ui, self.message) envelope.body = mailcontent diff --git a/alot/widgets/thread.py b/alot/widgets/thread.py index 737690950..e613e1057 100644 --- a/alot/widgets/thread.py +++ b/alot/widgets/thread.py @@ -264,16 +264,22 @@ def _other_part(self, offset): self._current_part += offset self._current_part %= len(mps) + def get_current_text(self): + self._get_current(1) + def _get_current_part(self): + self._get_current(2) + + def _get_current(self, index): mps = self._get_multiparts() if mps: - return mps[self._current_part][1] + return mps[self._current_part][index] def _get_multipart_selector(self): mps = self._get_multiparts() if mps: return MultipartWidget( - [ctype for ctype, _ in self._get_multiparts()], + [ctype for ctype, _, _ in self._get_multiparts()], self._current_part) def _get_multiparts(self): @@ -284,6 +290,7 @@ def _get_multiparts(self): self._multiparts = [ (ctype, + text, TextlinesList(text, att, att_focus)) for ctype, text in self._message.get_body_parts()]