summaryrefslogtreecommitdiff
path: root/service/pixelated/extensions/incoming_decrypt_header.py
blob: 2db5dd1d48d72e827cd0066baee896ad2512acfd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import leap.mail.imap.fetch as fetch


def mark_as_encrypted_inline(f):

    def w(*args, **kwargs):
        msg, valid_sign = f(*args)
        is_encrypted = fetch.PGP_BEGIN in args[1].as_string() and fetch.PGP_END in args[1].as_string()
        decrypted_successfully = fetch.PGP_BEGIN not in msg.as_string() and fetch.PGP_END not in msg.as_string()

        if not is_encrypted:
            encrypted = 'false'
        else:
            if decrypted_successfully:
                encrypted = 'true'
            else:
                encrypted = 'fail'

        msg.add_header('X-Pixelated-encryption-status', encrypted)
        return msg, valid_sign

    return w


def mark_as_encrypted_multipart(f):

    def w(*args, **kwargs):
        msg, valid_sign = f(*args)
        msg.add_header('X-Pixelated-encryption-status', 'true')
        return msg, valid_sign
    return w


fetch.LeapIncomingMail._maybe_decrypt_inline_encrypted_msg = mark_as_encrypted_inline(fetch.LeapIncomingMail._maybe_decrypt_inline_encrypted_msg)
fetch.LeapIncomingMail._decrypt_multipart_encrypted_msg = mark_as_encrypted_multipart(fetch.LeapIncomingMail._decrypt_multipart_encrypted_msg)