Skip to content

Commit

Permalink
quote selected part on reply/forward
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Van der Jeugt committed Jan 12, 2018
1 parent a81c407 commit 219ca8c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
41 changes: 23 additions & 18 deletions alot/commands/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,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_visible_part())
else:
quote_prefix = settings.get('quote_prefix')
mailcontent = ""
for line in tree.get_visible_part().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,
Expand Down Expand Up @@ -151,14 +170,7 @@ 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)

Expand Down Expand Up @@ -354,18 +366,11 @@ 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

Expand Down
8 changes: 6 additions & 2 deletions alot/widgets/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,24 +263,28 @@ def _get_content_parts(self):

self._content_parts = [
(ctype,
text,
TextlinesList(text, att, att_focus))
for ctype, text
in extract_body_parts(self._message.get_email())]

preferred = 'text/plain' if settings.get(
'prefer_plaintext') else 'text/html'
prefs = [i for i, e in enumerate(self._content_parts)
if e[0] == preferred]
if e[0] == preferred]
self._current_contenttype = prefs[0] if prefs else 0

return self._content_parts

def _get_body(self):
return self._get_content_parts()[self._current_contenttype][2]

def get_visible_part(self):
return self._get_content_parts()[self._current_contenttype][1]

def _get_contenttype(self):
return ContenttypeWidget(
[ctype for ctype, _ in self._get_content_parts()],
[ctype for ctype, _, _ in self._get_content_parts()],
self._current_contenttype)

def next_contenttype(self):
Expand Down

0 comments on commit 219ca8c

Please sign in to comment.