Skip to content

Commit 57b6966

Browse files
author
Felix Van der Jeugt
committed
quote selected part on reply/forward
1 parent f6f99b0 commit 57b6966

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

alot/commands/thread.py

Lines changed: 23 additions & 18 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,
@@ -142,14 +161,7 @@ async def apply(self, ui):
142161
quotestring = qf(name, address, timestamp, ui=ui, dbm=ui.dbman)
143162
else:
144163
quotestring = 'Quoting %s (%s)\n' % (name or address, timestamp)
145-
mailcontent = quotestring
146-
quotehook = settings.get_hook('text_quote')
147-
if quotehook:
148-
mailcontent += quotehook(self.message.accumulate_body())
149-
else:
150-
quote_prefix = settings.get('quote_prefix')
151-
for line in self.message.accumulate_body().splitlines():
152-
mailcontent += quote_prefix + line + '\n'
164+
mailcontent = quotestring + quote(ui, self.message)
153165

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

@@ -346,18 +358,11 @@ async def apply(self, ui):
346358
timestamp = self.message.get_date()
347359
qf = settings.get_hook('forward_prefix')
348360
if qf:
349-
quote = qf(name, address, timestamp, ui=ui, dbm=ui.dbman)
361+
quotestring = qf(name, address, timestamp, ui=ui, dbm=ui.dbman)
350362
else:
351-
quote = 'Forwarded message from %s (%s):\n' % (
363+
quotestring = 'Forwarded message from %s (%s):\n' % (
352364
name or address, timestamp)
353-
mailcontent = quote
354-
quotehook = settings.get_hook('text_quote')
355-
if quotehook:
356-
mailcontent += quotehook(self.message.accumulate_body())
357-
else:
358-
quote_prefix = settings.get('quote_prefix')
359-
for line in self.message.accumulate_body().splitlines():
360-
mailcontent += quote_prefix + line + '\n'
365+
mailcontent = quotestring + quote(ui, self.message)
361366

362367
envelope.body = mailcontent
363368

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+
self._get_current(1)
269+
267270
def _get_current_part(self):
271+
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)