summaryrefslogtreecommitdiff
path: root/alot/db/utils.py
diff options
context:
space:
mode:
authorJustus Winter <4winter@informatik.uni-hamburg.de>2013-05-27 13:42:29 +0200
committerPatrick Totzke <patricktotzke@gmail.com>2013-06-16 21:18:06 +0100
commit08cf72562b6ac73a2ad834dabc985c89a7daa4fe (patch)
tree43e06bd4d65215d537c203815dd3c29d9ea7e7ad /alot/db/utils.py
parentfd76cd46e63f5d75b028d738d522a56b69cba601 (diff)
Move the parameter extraction to its own function
Move the parameter extraction to its own function and generalize it so it can be reused. Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
Diffstat (limited to 'alot/db/utils.py')
-rw-r--r--alot/db/utils.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/alot/db/utils.py b/alot/db/utils.py
index 6861b39e..e42deed7 100644
--- a/alot/db/utils.py
+++ b/alot/db/utils.py
@@ -57,6 +57,21 @@ def add_signature_headers(mail, sigs, error_msg):
)
+def get_params(mail, failobj=None, header='content-type', unquote=True):
+ '''Get Content-Type parameters as dict.
+
+ RFC 2045 specifies that parameter names are case-insensitive, so
+ we normalize them here.
+
+ :param mail: :class:`email.message.Message`
+ :param failobj: object to return if no such header is found
+ :param header: the header to search for parameters, default
+ :param unquote: unquote the values
+ :returns: a `dict` containing the parameters
+ '''
+ return {k.lower():v for k, v in mail.get_params(failobj, header, unquote)}
+
+
def message_from_file(handle):
'''Reads a mail from the given file-like object and returns an email
object, very much like email.message_from_file. In addition to
@@ -91,10 +106,7 @@ def message_from_file(handle):
malformed = 'expected Content-Type: {0}, got: {1}'.format(
want, ct)
- # Get Content-Type parameters as dict. RFC 2045 specifies that
- # parameter names are case-insensitive, so we normalize them
- # here.
- p = {k.lower():v for k, v in m.get_params()}
+ p = get_params(m)
if p.get('protocol', 'nothing') != want:
malformed = 'expected protocol={0}, got: {1}'.format(