Skip to content

Commit 31f7ab9

Browse files
author
Felix Van der Jeugt
committed
quote selected part on reply/forward
1 parent aa33a18 commit 31f7ab9

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

alot/commands/thread.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,25 @@ def determine_sender(mail, action='reply'):
9898
return from_value, account
9999

100100

101+
def quote(ui, message=None):
102+
if not message:
103+
tree = ui.current_buffer.get_selected_messagetree()
104+
else:
105+
# I'm assuming the message is in the current buffer.
106+
tree = next(tree for tree in ui.current_buffer.messagetrees()
107+
if tree._message == message)
108+
109+
quotehook = settings.get_hook('text_quote')
110+
if quotehook:
111+
return quotehook(tree.get_current_text())
112+
else:
113+
quote_prefix = settings.get('quote_prefix')
114+
mailcontent = ""
115+
for line in tree.get_current_text().splitlines():
116+
mailcontent += quote_prefix + line + '\n'
117+
return mailcontent
118+
119+
101120
@registerCommand(MODE, 'reply', arguments=[
102121
(['--all'], {'action': 'store_true', 'help': 'reply to all'}),
103122
(['--list'], {'action': cargparse.BooleanAction, 'default': None,
@@ -143,14 +162,7 @@ async def apply(self, ui):
143162
message=mail, ui=ui, dbm=ui.dbman)
144163
else:
145164
quotestring = 'Quoting %s (%s)\n' % (name or address, timestamp)
146-
mailcontent = quotestring
147-
quotehook = settings.get_hook('text_quote')
148-
if quotehook:
149-
mailcontent += quotehook(self.message.accumulate_body())
150-
else:
151-
quote_prefix = settings.get('quote_prefix')
152-
for line in self.message.accumulate_body().splitlines():
153-
mailcontent += quote_prefix + line + '\n'
165+
mailcontent = quotestring + quote(ui, self.message)
154166

155167
envelope = Envelope(bodytext=mailcontent, replied=self.message)
156168

@@ -347,19 +359,12 @@ async def apply(self, ui):
347359
timestamp = self.message.get_date()
348360
qf = settings.get_hook('forward_prefix')
349361
if qf:
350-
quote = qf(name, address, timestamp,
351-
message=mail, ui=ui, dbm=ui.dbman)
362+
quotestring = qf(name, address, timestamp,
363+
message=mail, ui=ui, dbm=ui.dbman)
352364
else:
353-
quote = 'Forwarded message from %s (%s):\n' % (
365+
quotestring = 'Forwarded message from %s (%s):\n' % (
354366
name or address, timestamp)
355-
mailcontent = quote
356-
quotehook = settings.get_hook('text_quote')
357-
if quotehook:
358-
mailcontent += quotehook(self.message.accumulate_body())
359-
else:
360-
quote_prefix = settings.get('quote_prefix')
361-
for line in self.message.accumulate_body().splitlines():
362-
mailcontent += quote_prefix + line + '\n'
367+
mailcontent = quotestring + quote(ui, self.message)
363368

364369
envelope.body = mailcontent
365370

alot/widgets/thread.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,16 +264,22 @@ def _other_part(self, offset):
264264
self._current_part += offset
265265
self._current_part %= len(mps)
266266

267+
def get_current_text(self):
268+
return self._get_current(1)
269+
267270
def _get_current_part(self):
271+
return self._get_current(2)
272+
273+
def _get_current(self, index):
268274
mps = self._get_multiparts()
269275
if mps:
270-
return mps[self._current_part][1]
276+
return mps[self._current_part][index]
271277

272278
def _get_multipart_selector(self):
273279
mps = self._get_multiparts()
274280
if mps:
275281
return MultipartWidget(
276-
[ctype for ctype, _ in self._get_multiparts()],
282+
[ctype for ctype, _, _ in self._get_multiparts()],
277283
self._current_part)
278284

279285
def _get_multiparts(self):
@@ -284,6 +290,7 @@ def _get_multiparts(self):
284290

285291
self._multiparts = [
286292
(ctype,
293+
text,
287294
TextlinesList(text, att, att_focus))
288295
for ctype, text
289296
in self._message.get_body_parts()]

0 commit comments

Comments
 (0)