Ejemplo n.º 1
0
        if motd:
            self.event.data['motd'] = motd

            lang = config.prefs.language or 'en'
            motd['_motd'] = motd.get(lang, motd.get('en'))

            latest = motd.get('latest_version')
            if not latest:
                motd['_version_info'] = _('Mailpile update info unavailable')
            elif latest == APPVER:
                motd['_version_info'] = _('Your Mailpile is up to date')
            else:
                motd['_version_info'] = _('An upgrade for Mailpile is '
                                          'available, version %s'
                                          ) % latest

            if '--silent' in self.args:
                motd = {}
            elif '--ifnew' in self.args and not motd.get('_is_new'):
                motd = {}

            return self._success(message, result=motd)
        else:
            message = '%s: %s' % (_('Message Of The Day'), _('Unknown'))
            return self._error(message, result={})


_plugins.register_commands(MessageOfTheDay)
_plugins.register_slow_periodic_job('motd', 3600, MessageOfTheDay.update)
Ejemplo n.º 2
0
        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):
    """Add auto-tag rule for current search or terms"""
    SYNOPSIS = (None, 'filter', 'filter', '[new|read] [notag|maketag] [=<mid>] '
                                          '[<terms>] [+<tag>] [-<tag>] '
                                          '[<comment>]')
    ORDER = ('Tagging', 1)
Ejemplo n.º 3
0
    def command(self):
        cfg, idx = self.session.config, self.session.config.index
        if not idx:
            return self._error(_('The index is not ready yet'))

        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, UnAttach,   # Manipulate
                           UnThread,                          # ...
                           Sendit, UpdateAndSendit,           # Send
                           EmptyOutbox)                       # ...
Ejemplo n.º 4
0
        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:
            kws = self._get_keywords(e)
            result = results[e.msg_mid()] = {}
            for at_config in config.prefs.autotag:
                if not at_config.match_tag:
Ejemplo n.º 5
0
                    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, 90]
})
_plugins.register_slow_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)  # ...
Ejemplo n.º 6
0
            {'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):
    """Add auto-tag rule for current search or terms"""
    SYNOPSIS = (None, 'filter', 'filter',
                '[new|read] [notag|maketag] [=<mid>] '
                '[<terms>] [+<tag>] [-<tag>] '
                '[<comment>]')
Ejemplo n.º 7
0
            motd = old_motd

        if motd:
            self.event.data['motd'] = motd

            lang = config.prefs.language or 'en'
            motd['_motd'] = motd.get(lang, motd.get('en'))

            latest = motd.get('latest_version')
            if not latest:
                motd['_version_info'] = _('Mailpile update info unavailable')
            elif latest == APPVER:
                motd['_version_info'] = _('Your Mailpile is up to date')
            else:
                motd['_version_info'] = _('An upgrade for Mailpile is '
                                          'available, version %s') % latest

            if '--silent' in self.args:
                motd = {}
            elif '--ifnew' in self.args and not motd.get('_is_new'):
                motd = {}

            return self._success(message, result=motd)
        else:
            message = '%s: %s' % (_('Message Of The Day'), _('Unknown'))
            return self._error(message, result={})


_plugins.register_commands(MessageOfTheDay)
_plugins.register_slow_periodic_job('motd', 3600, MessageOfTheDay.update)
Ejemplo n.º 8
0
        """
        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:
            kws = self._get_keywords(e)
            result = results[e.msg_mid()] = {}
            for at_config in autotag_configs(config):