Exemple #1
0

_plugins = PluginManager(builtin=__file__)


##[ Keywords ]################################################################


def meta_kw_extractor(index, msg_mid, msg, msg_size, msg_ts, **kwargs):
    """Create a search term with the floored log2 size of the message."""
    if msg_size <= 0:
        return []
    return ["%s:ln2sz" % int(math.log(msg_size, 2))]


_plugins.register_meta_kw_extractor("sizes", meta_kw_extractor)


##[ Search terms ]############################################################


_size_units = {"t": 40, "g": 30, "m": 20, "k": 10, "b": 0}
_range_keywords = ["..", "-"]


def _mk_logsize(size, default_unit=0):
    if not size:
        return 0
    unit = 0
    size = size.lower()
    if size[-1].isdigit():  # ends with a number
Exemple #2
0
        sig.add('mp_sig-none')
    elif len(sig) > 1:
        sig = choose_one('mp_sig-%s', sig, SignatureInfo.STATUSES)

    # Emit tags for our states
    for tname in (enc | sig):
        tag = index.config.get_tags(slug=tname)
        if tag:
            kw.add('%s:in' % tag[0]._key)

    if 'cryptostate' in index.config.sys.debug:
        print 'part crypto state(=%s): %s' % (msg_mid, ','.join(list(kw)))

    return list(kw)

_plugins.register_text_kw_extractor('crypto_tkwe', text_kw_extractor)
_plugins.register_meta_kw_extractor('crypto_mkwe', meta_kw_extractor)


##[ Search helpers ]##########################################################

def search(config, idx, term, hits):
    #
    # FIXME: Translate things like pgp:signed into a search for all the
    #        tags that have signatures (good or bad).
    #
    return []

_plugins.register_search_term('crypto', search)
_plugins.register_search_term('pgp', search)
Exemple #3
0
                            if (rcpt != sender) and rcpt_keyid:
                                kb = gnupg.get_minimal_key(key_id=rcpt_keyid,
                                                           user_id=rcpt)
                                if kb:
                                    gossip_list.append(
                                        make_autocrypt_header(
                                            rcpt,
                                            kb,
                                            prefix='Autocrypt-Gossip'))
                        except (ValueError, IndexError):
                            pass
                    if len(gossip_list) > 1:
                        # No point gossiping peoples keys back to them alone.
                        for hdr in gossip_list:
                            msg.add_header('Autocrypt-Gossip', hdr)

                matched = True

        return sender, rcpts, msg, matched, True


_plugins.register_meta_kw_extractor('autocrypt', autocrypt_meta_kwe)
_plugins.register_commands(AutoCryptSearch, AutoCryptForget, AutoCryptParse,
                           AutoCryptPeers)

# Note: we perform our transformations BEFORE the GnuPG transformations
# (prio 500), so the memory hole transformation can take care of hiding
# the Autocrypt-Gossip headers.
_plugins.register_outgoing_email_content_transform('400_autocrypt',
                                                   AutoCryptTxf)
Exemple #4
0
from mailpile.i18n import ngettext as _n
from mailpile.plugins import PluginManager

_plugins = PluginManager(builtin=__file__)

##[ Keywords ]################################################################


def meta_kw_extractor(index, msg_mid, msg, msg_size, msg_ts, **kwargs):
    """Create a search term with the floored log2 size of the message."""
    if msg_size <= 0:
        return []
    return ['%s:ln2sz' % int(math.log(msg_size, 2))]


_plugins.register_meta_kw_extractor('sizes', meta_kw_extractor)

##[ Search terms ]############################################################

_size_units = {'t': 40, 'g': 30, 'm': 20, 'k': 10, 'b': 0}
_range_keywords = ['..', '-']


def _mk_logsize(size, default_unit=0):
    if not size:
        return 0
    unit = 0
    size = size.lower()
    if size[-1].isdigit():  # ends with a number
        unit = default_unit
    elif len(size) >= 2 and size[-2] in _size_units and size[-1] == 'b':
Exemple #5
0

##[ Keywords ]################################################################

def meta_kw_extractor(index, msg_mid, msg, msg_size, msg_ts, **kwargs):
    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
        d[2] -= 31
    if d[1] > 12:
        d[0] += 1
        d[1] -= 12


def _mk_date(ts):
    mdate = datetime.date.fromtimestamp(ts)
Exemple #6
0
        sig = choose_one('mp_sig-%s', sig, SignatureInfo.STATUSES)

    # Emit tags for our states
    for tname in (enc | sig):
        tag = index.config.get_tags(slug=tname)
        if tag:
            kw.add('%s:in' % tag[0]._key)

    if 'cryptostate' in index.config.sys.debug:
        print 'part crypto state(=%s): %s' % (msg_mid, ','.join(list(kw)))

    return list(kw)


_plugins.register_text_kw_extractor('crypto_tkwe', text_kw_extractor)
_plugins.register_meta_kw_extractor('crypto_mkwe', meta_kw_extractor)

##[ Search helpers ]##########################################################


def search(config, idx, term, hits):
    #
    # FIXME: Translate things like pgp:signed into a search for all the
    #        tags that have signatures (good or bad).
    #
    return []


_plugins.register_search_term('crypto', search)
_plugins.register_search_term('pgp', search)
                            if (rcpt != sender) and rcpt_keyid:
                                kb = gnupg.get_minimal_key(key_id=rcpt_keyid,
                                                           user_id=rcpt)
                                if kb:
                                    gossip_list.append(make_autocrypt_header(
                                        rcpt, kb, prefix='Autocrypt-Gossip'))
                        except (ValueError, IndexError):
                            pass
                    if len(gossip_list) > 1:
                        # No point gossiping peoples keys back to them alone.
                        for hdr in gossip_list:
                            msg.add_header('Autocrypt-Gossip', hdr)

                matched = True

        return sender, rcpts, msg, matched, True


_plugins.register_meta_kw_extractor('autocrypt', autocrypt_meta_kwe)
_plugins.register_commands(
    AutoCryptSearch,
    AutoCryptForget,
    AutoCryptParse,
    AutoCryptPeers)

# Note: we perform our transformations BEFORE the GnuPG transformations
# (prio 500), so the memory hole transformation can take care of hiding
# the Autocrypt-Gossip headers.
_plugins.register_outgoing_email_content_transform(
    '400_autocrypt', AutoCryptTxf)