コード例 #1
0
ファイル: walk.py プロジェクト: nextleap-project/bitmask-dev
def get_raw_docs(msg):
    """
    We get also some of the headers to be able to
    index the content. Here we remove any mutable part, as the the filename
    in the content disposition.
    """
    return (
        {'type': 'cnt',
         'raw': part.get_payload(),
         'phash': get_hash(part.get_payload()),
         'content-type': part.get_content_type(),
         'charset': part.get_content_charset(),
         'content-disposition': first(part.get(
             'content-disposition', '').split(';')),
         'content-transfer-encoding': part.get(
             'content-transfer-encoding', '')
         } for part in msg.walk() if not isinstance(part.get_payload(), list))
コード例 #2
0
ファイル: soledad.py プロジェクト: rrosajp/bitmask-dev
def _build_headers_doc(msg, chash, body_phash, parts_map):
    """
    Assemble a headers document from the original parsed message, the
    content-hash, and the parts map.

    It takes into account possibly repeated headers.
    """
    headers = defaultdict(list)
    for k, v in msg.items():
        headers[k].append(v)
    # "fix" for repeated headers (as in "Received:"
    for k, v in headers.items():
        newline = "\n%s: " % (k.lower(), )
        headers[k] = newline.join(v)

    lower_headers = lowerdict(dict(headers))
    msgid = first(_MSGID_RE.findall(lower_headers.get('message-id', '')))

    _hdoc = HeaderDocWrapper(chash=chash,
                             headers=headers,
                             body=body_phash,
                             msgid=msgid)

    def copy_attr(headers, key, doc):
        if key in headers:
            setattr(doc, key, headers[key])

    copy_attr(lower_headers, "subject", _hdoc)
    copy_attr(lower_headers, "date", _hdoc)

    hdoc = _hdoc.serialize()
    # add some of the attr from the parts map to header doc
    for key in parts_map:
        if key in ('body', 'multi', 'part_map'):
            hdoc[key] = parts_map[key]
    return stringify_parts_map(hdoc)
コード例 #3
0
    def do_msg_status(self, userid, mbox, msgid):
        account = self._get_account(userid)
        msg = yield account.get_message_by_msgid(mbox, msgid)
        if msg is None:
            raise Exception("Not found message id: " + msgid)

        headers = msg.get_headers()
        encryption = headers.get(IncomingMail.LEAP_ENCRYPTION_HEADER, '')
        signature = headers.get(IncomingMail.LEAP_SIGNATURE_HEADER, '')

        status = {}
        pubkey_re = re.compile(' pubkey="([0-9A-F]*)"')
        fingerprint = first(pubkey_re.findall(signature))
        status['signature'] = signature.split(';')[0]
        status['sign_fp'] = fingerprint
        status['encryption'] = encryption

        if ((IncomingMail.LEAP_ENCRYPTION_DECRYPTED == encryption) and
                (IncomingMail.LEAP_SIGNATURE_VALID == status['signature'])):
            status['secured'] = True
        else:
            status['secured'] = False

        defer.returnValue(status)