MOTD_URL_DEFAULT = 'https://www.mailpile.is' + MOTD_MARS MOTD_URL_TOR_ONLY = 'http://clgs64523yi2bkhz.onion' + MOTD_MARS MOTD_URL_NO_MARS = 'https://www.mailpile.is' + MOTD_NO_MARS MOTD_URL_TOR_ONLY_NO_MARS = 'http://clgs64523yi2bkhz.onion' + MOTD_NO_MARS MOTD_URLS = { "default": MOTD_URL_DEFAULT, "tor-only": MOTD_URL_TOR_ONLY, "generic": MOTD_URL_NO_MARS, "tor-generic": MOTD_URL_TOR_ONLY_NO_MARS, "unknown": "", "none": "" } _plugins.register_config_variables('prefs', { 'motd_url': p(_('URL to the Message Of The Day'), 'str', 'unknown') }) class MessageOfTheDay(Command): """Download and/or display the Message Of The Day""" SYNOPSIS = (None, 'motd', 'motd', '[--silent|--ifnew] [--[no]update|--check]') ORDER = ('Internals', 6) CONFIG_REQUIRED = False IS_USER_ACTIVITY = False @classmethod def _disable_updates(cls, session): # Don't auto-update the MOTD if the user hasn't configured any # accounts yet - no point bothering the user or the MOTD server. #
messages = [] for tag in cfg.get_tags(type='outbox'): search = ['in:%s' % tag._key] for msg_idx_pos in idx.search(self.session, search, order='flat-index').as_set(): messages.append('=%s' % b36(msg_idx_pos)) if messages: self.args = tuple(messages) return Sendit.command(self) else: return self._success(_('The outbox is empty')) _plugins.register_config_variables('prefs', { 'empty_outbox_interval': [_('Delay between attempts to send mail'), int, 90] }) _plugins.register_slow_periodic_job('sendmail', 'prefs.empty_outbox_interval', EmptyOutbox.sendmail) _plugins.register_commands( Compose, Reply, Forward, # Create Draft, Update, Attach, # Manipulate UnThread, # ... Sendit, UpdateAndSendit, # Send EmptyOutbox) # ...
# Messages no longer in the outbox get their events canceled... if cfg.event_log: events = cfg.event_log.incomplete(source='.plugins.compose.Sendit') for ev in events: if ('mid' in ev.data and ('=%s' % ev.data['mid']) not in messages): ev.flags = ev.COMPLETE ev.message = _('Sending cancelled.') cfg.event_log.log_event(ev) # Send all the mail! if messages: self.args = tuple(set(messages)) return Sendit.command(self) else: return self._success(_('The outbox is empty')) _plugins.register_config_variables('prefs', { 'empty_outbox_interval': [_('Delay between attempts to send mail'), int, 10] }) _plugins.register_fast_periodic_job('sendmail', 'prefs.empty_outbox_interval', EmptyOutbox.sendmail) _plugins.register_commands(Compose, Reply, Forward, # Create Draft, Update, Attach, UnAttach, # Manipulate UnThread, # ... Sendit, UpdateAndSendit, # Send EmptyOutbox) # ...
'parent': ['ID of parent tag, if any', 'str', ''], # Outdated crap 'hides_flag': ['DEPRECATED', 'ignore', None], 'write_flag': ['DEPRECATED', 'ignore', None], }, {}]) _plugins.register_config_section('filters', ["Filters", { 'tags': ['Tag/untag actions', 'str', ''], 'terms': ['Search terms', 'str', ''], 'comment': ['Human readable description', 'str', ''], 'type': ['Filter type', FILTER_TYPES, FILTER_TYPES[0]], }, {}]) _plugins.register_config_variables('sys', { 'writable_tags': ['DEPRECATED', 'str', []], 'invisible_tags': ['DEPRECATED', 'str', []], }) #INFO_HIDES_TAG_METADATA = ('flag_editable', 'flag_hides') def GetFilters(cfg, filter_on=None, types=FILTER_TYPES[:1]): filters = cfg.filters.keys() filters.sort(key=lambda k: int(k, 36)) flist = [] tset = set(types) for fid in filters: terms = cfg.filters[fid].get('terms', '') ftype = cfg.filters[fid]['type'] if not (set([ftype, 'any', 'all', None]) & tset): continue
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=True) ##[ 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 export_path(self, mbox_type): if mbox_type == 'mbox': return 'mailpile-%d.mbx' % time.time() else: return 'mailpile-%d'
tag, dry_run=dry_run)) return self._success( _('Performed automation for %d tags') % len(results), {'results': results}) @classmethod def run_in_background(cls, session): result = cls(session, arg=['-all']).run() return True _plugins.register_config_variables( 'prefs', { 'tag_automation_interval': [_('Periodically perform tag automation (seconds)'), int, 8 * 60 * 60] }) _plugins.register_slow_periodic_job('tag_automation', 'prefs.tag_automation_interval', TagAutomation.run_in_background) class FilterCommand(Command): def finish(self, save=True): self._background_save(config=True, index=True) return True class Filter(FilterCommand):
'parent': ['ID of parent tag, if any', 'str', ''], # Outdated crap 'hides_flag': ['DEPRECATED', 'ignore', None], 'write_flag': ['DEPRECATED', 'ignore', None], }, {}]) _plugins.register_config_section('filters', ["Filters", { 'tags': ['Tag/untag actions', 'str', ''], 'terms': ['Search terms', 'str', ''], 'comment': ['Human readable description', 'str', ''], 'type': ['Filter type', FILTER_TYPES, FILTER_TYPES[0]], }, {}]) _plugins.register_config_variables('sys', { 'writable_tags': ['DEPRECATED', 'str', []], 'invisible_tags': ['DEPRECATED', 'str', []], }) #INFO_HIDES_TAG_METADATA = ('flag_editable', 'flag_hides') def GetFilters(cfg, filter_on=None, types=FILTER_TYPES[:1]): filters = cfg.filters.keys() filters.sort(key=lambda k: int(k, 36)) flist = [] tset = set(types) for fid in filters: terms = cfg.filters[fid].get('terms', '') ftype = cfg.filters[fid]['type'] if not (set([ftype, 'any', 'all', None]) & tset): continue
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 export_path(self, mbox_type): if mbox_type == 'mbox': return 'mailpile-%d.mbx' % time.time() else:
def interval_retrain(cls, session): """ Retrains autotaggers Classmethod used for periodic automatic retraining """ result = cls(session)._retrain() if result: return True else: return False _plugins.register_config_variables( 'prefs', { 'autotag_retrain_interval': [_('Periodically retrain autotagger (seconds)'), int, 24 * 60 * 60] }) _plugins.register_slow_periodic_job('retrain_autotag', 'prefs.autotag_retrain_interval', Retrain.interval_retrain) class Classify(AutoTagCommand): SYNOPSIS = (None, 'autotag/classify', None, '<msgs>') ORDER = ('Tagging', 9) def _classify(self, emails): session, config, idx = self.session, self.session.config, self._idx() results = {}
if clean_session.results or dry_run: results.append(self._perform_auto_action(clean_session, tag, dry_run=dry_run)) return self._success( _('Performed automation for %d tags') % len(results), {'results': results}) @classmethod def run_in_background(cls, session): result = cls(session, arg=['-all']).run() return True _plugins.register_config_variables('prefs', { 'tag_automation_interval': [ _('Periodically perform tag automation (seconds)'), int, 8*60*60]}) _plugins.register_slow_periodic_job( 'tag_automation', 'prefs.tag_automation_interval', TagAutomation.run_in_background) class FilterCommand(Command): def finish(self, save=True): self._background_save(config=True, index=True) return True class Filter(FilterCommand):
# MOTD_URL_DEFAULT = 'https://www.mailpile.is' + MOTD_MARS MOTD_URL_TOR_ONLY = 'http://clgs64523yi2bkhz.onion' + MOTD_MARS MOTD_URL_NO_MARS = 'https://www.mailpile.is' + MOTD_NO_MARS MOTD_URL_TOR_ONLY_NO_MARS = 'http://clgs64523yi2bkhz.onion' + MOTD_NO_MARS MOTD_URLS = { "default": MOTD_URL_DEFAULT, "tor-only": MOTD_URL_TOR_ONLY, "generic": MOTD_URL_NO_MARS, "tor-generic": MOTD_URL_TOR_ONLY_NO_MARS, "unknown": "", "none": "" } _plugins.register_config_variables( 'prefs', {'motd_url': p(_('URL to the Message Of The Day'), 'str', 'unknown')}) class MessageOfTheDay(Command): """Download and/or display the Message Of The Day""" SYNOPSIS = (None, 'motd', 'motd', '[--silent|--ifnew] [--[no]update|--check]') ORDER = ('Internals', 6) CONFIG_REQUIRED = False IS_USER_ACTIVITY = False @classmethod def _disable_updates(cls, session): # Don't auto-update the MOTD if the user hasn't configured any # accounts yet - no point bothering the user or the MOTD server.
@classmethod def interval_retrain(cls, session): """ Retrains autotaggers Classmethod used for periodic automatic retraining """ result = cls(session)._retrain() if result: return True else: return False _plugins.register_config_variables('prefs', { 'autotag_retrain_interval': [_('Periodically retrain autotagger (seconds)'), int, 24*60*60], }) _plugins.register_slow_periodic_job('retrain_autotag', 'prefs.autotag_retrain_interval', Retrain.interval_retrain) class Classify(AutoTagCommand): SYNOPSIS = (None, 'autotag/classify', None, '<msgs>') ORDER = ('Tagging', 9) def _classify(self, emails): session, config, idx = self.session, self.session.config, self._idx() results = {} unknown = [] for e in emails:
# Details: # https://github.com/mailpile/Mailpile/wiki/Mailpile-Analytics-Reporting-System # MOTD_MARS = '/motd/%(ver)s-%(os)s/motd.json?lang=%(lang)s&py=%(py)s' MOTD_NO_MARS = '/motd/latest/motd.json' # MOTD_URL_DEFAULT = 'https://www.mailpile.is' + MOTD_MARS MOTD_URL_TOR_ONLY = 'http://clgs64523yi2bkhz.onion' + MOTD_MARS MOTD_URL_NO_MARS = 'https://www.mailpile.is' + MOTD_NO_MARS MOTD_URL_TOR_ONLY_NO_MARS = 'http://clgs64523yi2bkhz.onion' + MOTD_NO_MARS _plugins.register_config_variables('prefs', { 'motd_url': p( _('URL to the Message Of The Day'), 'url', MOTD_URL_DEFAULT ) }) class MessageOfTheDay(Command): """Download and/or display the Message Of The Day""" SYNOPSIS = (None, 'motd', 'motd', '[--silent|--ifnew] [--[no]update|--check]') ORDER = ('Internals', 6) CONFIG_REQUIRED = False IS_USER_ACTIVITY = False @classmethod def _disable_updates(cls, session): # Don't auto-update the MOTD if the user hasn't configured any
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 export_path(self, mbox_type): if mbox_type == "mbox": return "mailpile-%d.mbx" % time.time()