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 Dec 16, 2018
1 parent 5c42efe commit 44468a7
Show file tree
Hide file tree
Showing 2 changed files with 32 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 @@ -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,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down
11 changes: 9 additions & 2 deletions alot/widgets/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()]
Expand Down

0 comments on commit 44468a7

Please sign in to comment.