summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2011-10-22 12:02:30 +0100
committerPatrick Totzke <patricktotzke@gmail.com>2011-10-22 12:02:30 +0100
commit4e6a8e97c94042fb2f74803351d32e2922f75643 (patch)
tree32c3897b295710d91bdc0fec25e1db7adfc781b5
parentf6b020cc441591739b157776e15a64827b91e300 (diff)
move urwid_sanitize to helper.string_sanitize
-rw-r--r--alot/helper.py11
-rw-r--r--alot/message.py18
2 files changed, 16 insertions, 13 deletions
diff --git a/alot/helper.py b/alot/helper.py
index 2706ca63..06952102 100644
--- a/alot/helper.py
+++ b/alot/helper.py
@@ -31,6 +31,17 @@ from email.mime.image import MIMEImage
from email.mime.text import MIMEText
import urwid
+from settings import config
+
+
+def string_sanitize(string):
+ """strips, and replaces non-printable characters"""
+ tab_width = config.getint('general', 'tabwidth')
+ string = string.strip()
+ string = string.replace('\t', ' ' * tab_width)
+ string = string.replace('\r', '')
+ return string
+
def shorten(string, maxlen):
if maxlen > 1 and len(string) > maxlen:
diff --git a/alot/message.py b/alot/message.py
index d83c92dc..f6d290e5 100644
--- a/alot/message.py
+++ b/alot/message.py
@@ -28,6 +28,7 @@ from email.iterators import typed_subpart_iterator
import helper
from settings import get_mime_handler
from settings import config
+from helper import string_sanitize
class Message(object):
@@ -196,14 +197,6 @@ def extract_headers(mail, headers=None):
return headertext
-def urwid_sanitize(string):
- tab_width = config.getint('general', 'tabwidth')
- string = string.strip()
- string = string.replace('\t', ' ' * tab_width)
- string = string.replace('\r', '')
- return string
-
-
def extract_body(mail):
html = list(typed_subpart_iterator(mail, 'text', 'html'))
@@ -219,7 +212,7 @@ def extract_body(mail):
if part.get_content_maintype() == 'text':
raw_payload = unicode(raw_payload, enc, errors='replace')
if ctype == 'text/plain' and not drop_plaintext:
- body_parts.append(urwid_sanitize(raw_payload))
+ body_parts.append(string_sanitize(raw_payload))
else:
#get mime handler
handler = get_mime_handler(ctype, key='view',
@@ -240,9 +233,9 @@ def extract_body(mail):
#remove tempfile
os.unlink(tmpfile.name)
if rendered_payload: # handler had output
- body_parts.append(urwid_sanitize(rendered_payload))
+ body_parts.append(string_sanitize(rendered_payload))
elif part.get_content_maintype() == 'text':
- body_parts.append(urwid_sanitize(raw_payload))
+ body_parts.append(string_sanitize(raw_payload))
# else drop
return '\n\n'.join(body_parts)
@@ -271,11 +264,10 @@ def decode_header(header):
valuelist = email.header.decode_header(header)
decoded_list = []
- tab_width = config.getint('general', 'tabwidth')
for v, enc in valuelist:
if enc:
v = v.decode(enc, errors='replace')
- decoded_list.append(urwid_sanitize(v))
+ decoded_list.append(string_sanitize(v))
return u' '.join(decoded_list)