summaryrefslogtreecommitdiff
path: root/alot/buffers/envelope.py
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2018-06-19 10:40:07 +0100
committerPatrick Totzke <patricktotzke@gmail.com>2018-06-19 22:08:36 +0100
commitf0105c37556116c07f9f30c1fe960ea9e67e7229 (patch)
tree8642317be8306ea7c18ad62ef9146f507df95f9f /alot/buffers/envelope.py
parentd19615d2ac5bb23aca9068ca8c7644f466ce0b48 (diff)
refactor buffers
This splits buffers.py, which contained all buffer classes, into several smaller files. issue #1226
Diffstat (limited to 'alot/buffers/envelope.py')
-rw-r--r--alot/buffers/envelope.py98
1 files changed, 98 insertions, 0 deletions
diff --git a/alot/buffers/envelope.py b/alot/buffers/envelope.py
new file mode 100644
index 00000000..ef88bed3
--- /dev/null
+++ b/alot/buffers/envelope.py
@@ -0,0 +1,98 @@
+# Copyright (C) 2011-2018 Patrick Totzke <patricktotzke@gmail.com>
+# This file is released under the GNU GPL, version 3 or a later revision.
+# For further details see the COPYING file
+from __future__ import absolute_import
+import urwid
+import os
+
+from .buffer import Buffer
+from ..settings.const import settings
+from ..widgets.globals import HeadersList
+from ..widgets.globals import AttachmentWidget
+
+
+class EnvelopeBuffer(Buffer):
+ """message composition mode"""
+
+ modename = 'envelope'
+
+ def __init__(self, ui, envelope):
+ self.ui = ui
+ self.envelope = envelope
+ self.all_headers = False
+ self.rebuild()
+ Buffer.__init__(self, ui, self.body)
+
+ def __str__(self):
+ to = self.envelope.get('To', fallback='unset')
+ return '[envelope] to: %s' % (shorten_author_string(to, 400))
+
+ def get_info(self):
+ info = {}
+ info['to'] = self.envelope.get('To', fallback='unset')
+ return info
+
+ def cleanup(self):
+ if self.envelope.tmpfile:
+ os.unlink(self.envelope.tmpfile.name)
+
+ def rebuild(self):
+ displayed_widgets = []
+ hidden = settings.get('envelope_headers_blacklist')
+ # build lines
+ lines = []
+ for (k, vlist) in self.envelope.headers.items():
+ if (k not in hidden) or self.all_headers:
+ for value in vlist:
+ lines.append((k, value))
+
+ # sign/encrypt lines
+ if self.envelope.sign:
+ description = 'Yes'
+ sign_key = self.envelope.sign_key
+ if sign_key is not None and len(sign_key.subkeys) > 0:
+ description += ', with key ' + sign_key.uids[0].uid
+ lines.append(('GPG sign', description))
+
+ if self.envelope.encrypt:
+ description = 'Yes'
+ encrypt_keys = self.envelope.encrypt_keys.values()
+ if len(encrypt_keys) == 1:
+ description += ', with key '
+ elif len(encrypt_keys) > 1:
+ description += ', with keys '
+ key_ids = []
+ for key in encrypt_keys:
+ if key is not None and key.subkeys:
+ key_ids.append(key.uids[0].uid)
+ description += ', '.join(key_ids)
+ lines.append(('GPG encrypt', description))
+
+ if self.envelope.tags:
+ lines.append(('Tags', ','.join(self.envelope.tags)))
+
+ # add header list widget iff header values exists
+ if lines:
+ key_att = settings.get_theming_attribute('envelope', 'header_key')
+ value_att = settings.get_theming_attribute('envelope',
+ 'header_value')
+ gaps_att = settings.get_theming_attribute('envelope', 'header')
+ self.header_wgt = HeadersList(lines, key_att, value_att, gaps_att)
+ displayed_widgets.append(self.header_wgt)
+
+ # display attachments
+ lines = []
+ for a in self.envelope.attachments:
+ lines.append(AttachmentWidget(a, selectable=False))
+ if lines:
+ self.attachment_wgt = urwid.Pile(lines)
+ displayed_widgets.append(self.attachment_wgt)
+
+ self.body_wgt = urwid.Text(self.envelope.body)
+ displayed_widgets.append(self.body_wgt)
+ self.body = urwid.ListBox(displayed_widgets)
+
+ def toggle_all_headers(self):
+ """toggles visibility of all envelope headers"""
+ self.all_headers = not self.all_headers
+ self.rebuild()