summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2012-11-07 09:14:27 +0000
committerPatrick Totzke <patricktotzke@gmail.com>2012-11-07 09:14:27 +0000
commitb978cd01a5c839eda0af703789e1260b0cbb870c (patch)
tree0fab41c649f811ad22f83d1dc3c2273331d478bc /alot
parent11ee1111618ff8ead9c2f4f35506c095ccf96bbb (diff)
parentb91039115eadcc911184dfc102496444fe73db1f (diff)
Merge branch '0.3.3-feature-plaintext'
Diffstat (limited to 'alot')
-rw-r--r--alot/db/message.py4
-rw-r--r--alot/db/utils.py21
-rw-r--r--alot/defaults/alot.rc.spec4
3 files changed, 18 insertions, 11 deletions
diff --git a/alot/db/message.py b/alot/db/message.py
index 35a36aa1..65ef2dc8 100644
--- a/alot/db/message.py
+++ b/alot/db/message.py
@@ -243,9 +243,7 @@ class Message(object):
"""
returns bodystring extracted from this mail
"""
- #TODO: don't hardcode which part is considered body but allow toggle
- # commands and a config default setting
-
+ #TODO: allow toggle commands to decide which part is considered body
return extract_body(self.get_email())
def get_text_content(self):
diff --git a/alot/db/utils.py b/alot/db/utils.py
index 8f9de4c9..2ee9e03e 100644
--- a/alot/db/utils.py
+++ b/alot/db/utils.py
@@ -46,20 +46,21 @@ def extract_body(mail, types=None):
"""
returns a body text string for given mail.
If types is `None`, `text/*` is used:
- In case mail has a `text/html` part, it is prefered over
- `text/plain` parts.
+ The exact preferred type is specified by the prefer_plaintext config option
+ which defaults to text/html.
:param mail: the mail to use
:type mail: :class:`email.Message`
:param types: mime content types to use for body string
:type types: list of str
"""
- html = list(typed_subpart_iterator(mail, 'text', 'html'))
- # if no specific types are given, we favor text/html over text/plain
- drop_plaintext = False
- if html and not types:
- drop_plaintext = True
+ preferred = 'text/plain' if settings.get('prefer_plaintext') else 'text/html'
+ has_preferred = False
+
+ # see if the mail has our preferred type
+ if types == None:
+ has_preferred = list(typed_subpart_iterator(mail, *preferred.split('/')))
body_parts = []
for part in mail.walk():
@@ -71,10 +72,14 @@ def extract_body(mail, types=None):
cd = part.get('Content-Disposition', '')
if cd.startswith('attachment'):
continue
+ # if the mail has our preferred type, we only keep this type
+ # note that if types != None, has_preferred always stays False
+ if has_preferred and ctype != preferred:
+ continue
enc = part.get_content_charset() or 'ascii'
raw_payload = part.get_payload(decode=True)
- if ctype == 'text/plain' and not drop_plaintext:
+ if ctype == 'text/plain':
raw_payload = string_decode(raw_payload, enc)
body_parts.append(string_sanitize(raw_payload))
else:
diff --git a/alot/defaults/alot.rc.spec b/alot/defaults/alot.rc.spec
index 3725d8c1..0550109a 100644
--- a/alot/defaults/alot.rc.spec
+++ b/alot/defaults/alot.rc.spec
@@ -183,6 +183,10 @@ reply_force_address = boolean(default=False)
# only if original subject doesn't start with 'Fwd:' or this prefix
forward_subject_prefix = string(default='Fwd: ')
+
+# prefer plaintext alternatives over html content in multipart/alternative
+prefer_plaintext = boolean(default=False)
+
# Key bindings
[bindings]
__many__ = string(default=None)