|
14 | 14 | from .globals import AttachmentWidget |
15 | 15 | from ..settings.const import settings |
16 | 16 | from ..db.utils import decode_header, X_SIGNATURE_MESSAGE_HEADER |
17 | | -from ..db.utils import extract_body |
| 17 | +from ..db.utils import extract_body_parts |
18 | 18 |
|
19 | 19 |
|
20 | 20 | class MessageSummaryWidget(urwid.WidgetWrap): |
@@ -73,6 +73,18 @@ def keypress(self, size, key): |
73 | 73 | return key |
74 | 74 |
|
75 | 75 |
|
| 76 | +class ContenttypeWidget(urwid.WidgetWrap): |
| 77 | + def __init__(self, types, current): |
| 78 | + value_att = settings.get_theming_attribute('thread', 'header_value') |
| 79 | + |
| 80 | + cols = [] |
| 81 | + cols.append(urwid.Text("content-type: ")) |
| 82 | + for i, ctype in enumerate(types): |
| 83 | + cols.append(urwid.Text((value_att if i == current else None, ctype))) |
| 84 | + cols = [('fixed', len(c.text), c) for c in cols] |
| 85 | + urwid.WidgetWrap.__init__(self, urwid.Columns(cols, dividechars=1)) |
| 86 | + |
| 87 | + |
76 | 88 | class FocusableText(urwid.WidgetWrap): |
77 | 89 | """Selectable Text used for nodes in our example""" |
78 | 90 | def __init__(self, txt, att, att_focus): |
@@ -172,6 +184,8 @@ def __init__(self, message, odd=True): |
172 | 184 | self._default_headers_tree = None |
173 | 185 | self.display_attachments = True |
174 | 186 | self._attachments = None |
| 187 | + self._current_contenttype = 0 |
| 188 | + self._content_parts = None |
175 | 189 | self._maintree = SimpleTree(self._assemble_structure()) |
176 | 190 | CollapsibleTree.__init__(self, self._maintree) |
177 | 191 |
|
@@ -205,6 +219,10 @@ def _assemble_structure(self): |
205 | 219 | if attachmenttree is not None: |
206 | 220 | mainstruct.append((attachmenttree, None)) |
207 | 221 |
|
| 222 | + contenttype = self._get_contenttype() |
| 223 | + if contenttype is not None: |
| 224 | + mainstruct.append((contenttype, None)) |
| 225 | + |
208 | 226 | bodytree = self._get_body() |
209 | 227 | if bodytree is not None: |
210 | 228 | mainstruct.append((bodytree, None)) |
@@ -236,15 +254,29 @@ def _get_source(self): |
236 | 254 | self._sourcetree = TextlinesList(sourcetxt, att, att_focus) |
237 | 255 | return self._sourcetree |
238 | 256 |
|
| 257 | + def _get_content_parts(self): |
| 258 | + if self._content_parts is None: |
| 259 | + att = settings.get_theming_attribute('thread', 'body') |
| 260 | + att_focus = settings.get_theming_attribute( |
| 261 | + 'thread', 'body_focus') |
| 262 | + |
| 263 | + self._content_parts = [ |
| 264 | + (ctype, |
| 265 | + TextlinesList(text, att, att_focus)) |
| 266 | + for ctype, text |
| 267 | + in extract_body_parts(self._message.get_email())] |
| 268 | + |
| 269 | + return self._content_parts |
| 270 | + |
239 | 271 | def _get_body(self): |
240 | | - if self._bodytree is None: |
241 | | - bodytxt = extract_body(self._message.get_email()) |
242 | | - if bodytxt: |
243 | | - att = settings.get_theming_attribute('thread', 'body') |
244 | | - att_focus = settings.get_theming_attribute( |
245 | | - 'thread', 'body_focus') |
246 | | - self._bodytree = TextlinesList(bodytxt, att, att_focus) |
247 | | - return self._bodytree |
| 272 | + return self._get_content_parts()[self._current_contenttype][1] |
| 273 | + |
| 274 | + def _get_contenttype(self): |
| 275 | + return ContenttypeWidget([ctype for ctype, _ in self._get_content_parts()], self._current_contenttype) |
| 276 | + |
| 277 | + def next_contenttype(self): |
| 278 | + self._current_contenttype += 1 |
| 279 | + self._current_contenttype %= len(self._get_content_parts()) |
248 | 280 |
|
249 | 281 | def _get_headers(self): |
250 | 282 | if self.display_all_headers is True: |
|
0 commit comments