def load(self, session, filename=None): self._mkworkdir(session) self.index = None self.reset(rules=False, data=True) filename = filename or self.conffile lines = [] try: fd = open(filename, 'rb') try: decrypt_and_parse_lines(fd, lambda l: lines.append(l), None) except ValueError: pass fd.close() except IOError: pass # Discover plugins and update the config rule to match from mailpile.plugins import PluginManager self.plugins = PluginManager(config=self, builtin=True).discover([ os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'plugins'), os.path.join(self.workdir, 'plugins') ]) self.sys.plugins.rules['_any'][1] = self.plugins.available() # Parse once (silently), to figure out which plugins to load... self.parse_config(None, '\n'.join(lines), source=filename) if len(self.sys.plugins) == 0: self.sys.plugins.extend(self.plugins.DEFAULT) self.load_plugins(session) # Now all the plugins are loaded, reset and parse again! self.reset_rules_from_source() self.parse_config(session, '\n'.join(lines), source=filename) # Open event log self.event_log = EventLog( self.data_directory('event_log', mode='rw', mkdir=True), # FIXME: Disbled encryption for now lambda: False and self.prefs.obfuscate_index).load() # Enable translations translation = self.get_i18n_translation(session) # Configure jinja2 self.jinja_env = Environment( loader=MailpileJinjaLoader(self), autoescape=True, trim_blocks=True, extensions=[ 'jinja2.ext.i18n', 'jinja2.ext.with_', 'jinja2.ext.do', 'mailpile.jinjaextensions.MailpileCommand' ]) self.jinja_env.install_gettext_translations(translation, newstyle=True) # Load VCards self.vcards = VCardStore( self, self.data_directory('vcards', mode='rw', mkdir=True))
def data_file_and_mimetype(self, ftype, fpath, *args, **kwargs): # The theme gets precedence core_path = self.data_directory(ftype, *args, **kwargs) path, mimetype = os.path.join(core_path, fpath), None # If there's nothing there, check our plugins if not os.path.exists(path): from mailpile.plugins import PluginManager path, mimetype = PluginManager().get_web_asset(fpath, path) if os.path.exists(path): return path, mimetype else: return None, None
#coding:utf-8 import os import mailpile.security as security from mailpile.commands import Command from mailpile.i18n import gettext as _ from mailpile.i18n import ngettext as _n from mailpile.plugins import PluginManager from mailpile.crypto.gpgi import GnuPG from mailpile.vcard import * _plugins = PluginManager(builtin=__file__) # User default GnuPG key file DEF_GNUPG_HOME = os.path.expanduser('~/.gnupg') class GnuPGImporter(VCardImporter): FORMAT_NAME = 'GnuPG' FORMAT_DESCRIPTION = _('Import contacts from GnuPG keyring') SHORT_NAME = 'gpg' CONFIG_RULES = { 'active': [_('Enable this importer'), bool, True], 'gpg_home': [_('Location of keyring'), 'path', DEF_GNUPG_HOME], } VCL_KEY_FMT = 'data:application/x-pgp-fingerprint,%s' # Merge by own identifier, email or key (in that order) MERGE_BY = ['x-gpg-mrgid', 'email']
if self.data.get('_method', None) == 'POST': password = self.data.get('password', [None])[0] else: password = self.session.ui.get_password( _('Enter your password:'******' ') if policy == 'store': if fingerprint in config.passphrases: del config.passphrases[fingerprint] config.secrets[fingerprint] = { 'password': password, 'policy': policy } return happy(_('Password stored permanently')) elif policy == 'cache-only' and password: sps = SecurePassphraseStorage(password) if ttl > 0: sps.expiration = time.time() + ttl config.passphrases[fingerprint] = sps if fingerprint.lower() in config.secrets: del config.secrets[fingerprint.lower()] return happy(_('Password stored temporarily')) else: return self._error(_('Invalid password policy!'), result) plugin_manager = PluginManager(builtin=True) plugin_manager.register_commands(Authenticate, DeAuthenticate, SetPassphrase)
PGPKeysImportAsVCards(self.session, arg=fingerprints).run() # Previous crypto evaluations may now be out of date, so we # clear the cache so users can see results right away. ClearParseCache(pgpmime=True) # i18n note: Not translating things here, since messages are not # generally use-facing and we want to reduce load on our # translators. return self._success('Evaluated key TOFU', result={ 'missing_keys': missing, 'imported_keys': imported, 'status': status, 'on_keychain': old}) PluginManager(builtin=__file__).register_commands( KeyLookup, KeyImport, KeyTofu) ##[ Basic lookup handlers ]################################################### class LookupHandler: NAME = "NONE" TIMEOUT = 2 PRIORITY = 10000 LOCAL = False def __init__(self, session, known_keys_list): self.session = session self.known_keys = known_keys_list def _gnupg(self):
def _get_ui_elements(self, ui_type, state, context=None): self._debug('get_ui_element(%s, %s, ...)' % (ui_type, state)) ctx = context or state.get('context_url', '') return copy.deepcopy(PluginManager().get_ui_elements(ui_type, ctx))
import mailbox import os import time from gettext import gettext as _ import mailpile.config from mailpile.plugins import PluginManager from mailpile.util import * from mailpile.commands import Command from mailpile.mailutils import Email _plugins = PluginManager(builtin=os.path.basename(__file__)[:-3]) ##[ Configuration ]########################################################### MAILBOX_FORMATS = ('mbox', 'maildir') _plugins.register_config_variables( 'prefs', { 'export_format': ['Default format for exporting mail', MAILBOX_FORMATS, 'mbox'], }) ##[ Commands ]################################################################ class ExportMail(Command): """Export messages to an external mailbox""" SYNOPSIS = (None, 'export', None, '<msgs> [flat] [<fmt>:<path>]') ORDER = ('Searching', 99)
def _get_ui_elements(self, ui_type, state, context=None): ctx = context or state.get('context_url', '') return copy.deepcopy(PluginManager().get_ui_elements(ui_type, ctx))
import time import datetime from gettext import gettext as _ from mailpile.plugins import PluginManager _plugins = PluginManager(builtin=__name__) ##[ Keywords ]################################################################ def meta_kw_extractor(index, msg_mid, msg, msg_size, msg_ts): mdate = datetime.date.fromtimestamp(msg_ts) keywords = [ '%s:year' % mdate.year, '%s:month' % mdate.month, '%s:day' % mdate.day, '%s-%s:yearmonth' % (mdate.year, mdate.month), '%s-%s-%s:date' % (mdate.year, mdate.month, mdate.day) ] return keywords _plugins.register_meta_kw_extractor('dates', meta_kw_extractor) ##[ Search terms ]############################################################ def _adjust(d): if d[2] > 31: d[1] += 1
from mailpile.plugins import PluginManager from mailpile.commands import Command from mailpile.crypto.state import * from mailpile.eventlog import Event from mailpile.plugins.tags import Tag from mailpile.mailutils import ExtractEmails, ExtractEmailAndName, Email from mailpile.mailutils import NotEditableError from mailpile.mailutils import NoFromAddressError, PrepareMessage from mailpile.smtp_client import SendMail from mailpile.search import MailIndex from mailpile.urlmap import UrlMap from mailpile.util import * from mailpile.plugins.search import Search, SearchResults, View _plugins = PluginManager(builtin=True) class EditableSearchResults(SearchResults): def __init__(self, session, idx, new, sent, **kwargs): SearchResults.__init__(self, session, idx, **kwargs) self.new_messages = new self.sent_messages = sent if new: self['created'] = [m.msg_mid() for m in new] if sent: self['sent'] = [m.msg_mid() for m in new] self['summary'] = _('Sent: %s') % self['summary'] def AddComposeMethods(cls):