summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2012-02-19 20:32:27 +0000
committerPatrick Totzke <patricktotzke@gmail.com>2012-02-19 20:32:27 +0000
commit790ebe9d71f87b9295a99de28ae892d22caabe42 (patch)
tree318d534f4c42b66235d474ac043237678fc41646 /alot
parent20cfb8218cd3753598c2ab5fba248df3819f97da (diff)
move get_mime_handler to SettingsManager
Diffstat (limited to 'alot')
-rw-r--r--alot/message.py5
-rw-r--r--alot/settings.py59
2 files changed, 30 insertions, 34 deletions
diff --git a/alot/message.py b/alot/message.py
index 75f204c2..f2d995ca 100644
--- a/alot/message.py
+++ b/alot/message.py
@@ -15,7 +15,6 @@ from notmuch.globals import NullPointerError
from alot import __version__
import logging
import helper
-from settings import get_mime_handler
from settings import settings
from helper import string_sanitize
from helper import string_decode
@@ -313,8 +312,8 @@ def extract_body(mail, types=None):
body_parts.append(string_sanitize(raw_payload))
else:
#get mime handler
- handler = get_mime_handler(ctype, key='view',
- interactive=False)
+ handler = settings.get_mime_handler(ctype, key='view',
+ interactive=False)
if handler:
#open tempfile. Not all handlers accept stuff from stdin
tmpfile = tempfile.NamedTemporaryFile(delete=False,
diff --git a/alot/settings.py b/alot/settings.py
index 96baf62b..d0c41b9e 100644
--- a/alot/settings.py
+++ b/alot/settings.py
@@ -130,6 +130,7 @@ class SettingsManager(object):
:type theme: str
"""
self.hooks = None
+ self._mailcaps = mailcap.getcaps()
theme_path = theme or os.path.join(DEFAULTSPATH, 'default.theme')
self._theme = Theme(theme_path)
@@ -347,36 +348,32 @@ class SettingsManager(object):
abooks.append(a.abook)
return abooks
-
-settings = SettingsManager()
-mailcaps = mailcap.getcaps()
+ def get_mime_handler(self, mime_type, key='view', interactive=True):
+ """
+ get shellcomand defined in the users `mailcap` as handler for files of
+ given `mime_type`.
+
+ :param mime_type: file type
+ :type mime_type: str
+ :param key: identifies one of possibly many commands for this type by
+ naming the intended usage, e.g. 'edit' or 'view'. Defaults
+ to 'view'.
+ :type key: str
+ :param interactive: choose the "interactive session" handler rather
+ than the "print to stdout and immediately return"
+ handler
+ :type interactive: bool
+ """
+ if interactive:
+ mc_tuple = mailcap.findmatch(self._mailcaps, mime_type, key=key)
+ else:
+ mc_tuple = mailcap.findmatch(self._mailcaps, mime_type,
+ key='copiousoutput')
+ if mc_tuple:
+ if mc_tuple[1]:
+ return mc_tuple[1][key]
+ else:
+ return None
-def get_mime_handler(mime_type, key='view', interactive=True):
- """
- get shellcomand defined in the users `mailcap` as handler for files of
- given `mime_type`.
-
- :param mime_type: file type
- :type mime_type: str
- :param key: identifies one of possibly many commands for this type by
- naming the intended usage, e.g. 'edit' or 'view'. Defaults
- to 'view'.
- :type key: str
- :param interactive: choose the "interactive session" handler rather than
- the "print to stdout and immediately return" handler
- :type interactive: bool
- """
- if interactive:
- mc_tuple = mailcap.findmatch(mailcaps,
- mime_type,
- key=key)
- else:
- mc_tuple = mailcap.findmatch(mailcaps,
- mime_type,
- key='copiousoutput')
- if mc_tuple:
- if mc_tuple[1]:
- return mc_tuple[1][key]
- else:
- return None
+settings = SettingsManager()