# Path: snoop/emails.py
# def decode_header(header):
# def people(headers, header_names):
# def extract_email_data(tree):
#     def __init__(self, file):
#     def parts(self, message, number_bits=[]):
#     def _get_part_content(self, part, number):
#     def open_part(self, number):
#     def parts_tree(self, message):
#         def _header(key, header):
#     def get_tree(self):
#     def get_part_text(self, part):
#         def get_payload(encrypted=False):
#     def get_attachments(self):
#     def _message(self):
#     def get_text(self):
#     def __init__(self, file, path):
#     def _get_part_content(self, part, number):
#     def _message(self):
# def msgcache(func):
#     def wrapper(doc):
# def open_msg(doc):
# def is_email(doc):
# def open_email(doc):
# def get_email_part(doc, part):
# def raw_parse_email(doc):
# def parse_email(doc):
# class CorruptedFile(exceptions.BrokenDocument):
# class PayloadError(exceptions.BrokenDocument):
# class EmailParser(object):
# class MissingEmlxPart(exceptions.BrokenDocument):
# class EmlxParser(EmailParser):
# 
# Path: snoop/models.py
# def cache(model, keyfunc):
#     def decorator(func):
#         def wrapper(*args, **kwargs):
#     def __str__(self):
#     def __str__(self):
#     def absolute_path(self):
#     def _open_file(self):
#     def open(self, filesystem=False):
#     def absolute_path(self):
# class EmailCache(models.Model):
# class Collection(models.Model):
# class Document(models.Model):
#     class Meta:
# class Ocr(models.Model):
#     class Meta:
# class Digest(models.Model):
# class Job(models.Model):
#     class Meta:
# class TikaCache(models.Model):
# class TikaLangCache(models.Model):
# class HtmlTextCache(models.Model):
#                     MB = 1024*1024
# 
# Path: snoop/pgp.py
# GPG = None
#             GPG = gnupg.GPG(gnupghome=settings.SNOOP_GPG_HOME,
#                             gpgbinary=settings.SNOOP_GPG_BINARY)
# def is_enabled():
# def _get_gpg():
# def extract_pgp_block(content):
# def contains_pgp_block(content):
# def decrypt_pgp_block(content, passphrase=None):
# class DecryptionError(exceptions.BrokenDocument):


import tempfile
import gnupg
import pytest
from django.conf import settings
from snoop import emails, models, pgp
    reason="SNOOP_GPG_BINARY not set")

PATH_HUSH_MAIL = 'eml-9-pgp/encrypted-hushmail-knockoff.eml'
HEIN_PRIVATE_KEY = 'eml-9-pgp/keys/hein-priv.gpg'
HEIN_PUBLIC_KEY = 'eml-9-pgp/keys/hein-pub.gpg'

@pytest.yield_fixture(autouse=True)
def patch_gpg_to_temp_dir(monkeypatch):
    with tempfile.TemporaryDirectory() as tmp:
        gpg = gnupg.GPG(gnupghome=tmp, gpgbinary='gpg')
        for path in [HEIN_PRIVATE_KEY, HEIN_PUBLIC_KEY]:
            with open(settings.SNOOP_ROOT + "/" + path, 'rb') as f:
                gpg.import_keys(f.read())
        monkeypatch.setattr(pgp, 'GPG', gpg)
        monkeypatch.setattr(settings, 'SNOOP_GPG_HOME', '/tmp')
        yield

def create_email_doc(path, collection):
    doc = models.Document(
        path=path,
        content_type='message/rfc822',
        collection=collection,
    )
    doc.save = lambda *a, **k: None
    return doc

def parse_email(path, document_collection):
    return emails.parse_email(create_email_doc(path, document_collection))

def open_email(path, document_collection):

# Path: snoop/emails.py
# def decode_header(header):
# def people(headers, header_names):
# def extract_email_data(tree):
#     def __init__(self, file):
#     def parts(self, message, number_bits=[]):
#     def _get_part_content(self, part, number):
#     def open_part(self, number):
#     def parts_tree(self, message):
#         def _header(key, header):
#     def get_tree(self):
#     def get_part_text(self, part):
#         def get_payload(encrypted=False):
#     def get_attachments(self):
#     def _message(self):
#     def get_text(self):
#     def __init__(self, file, path):
#     def _get_part_content(self, part, number):
#     def _message(self):
# def msgcache(func):
#     def wrapper(doc):
# def open_msg(doc):
# def is_email(doc):
# def open_email(doc):
# def get_email_part(doc, part):
# def raw_parse_email(doc):
# def parse_email(doc):
# class CorruptedFile(exceptions.BrokenDocument):
# class PayloadError(exceptions.BrokenDocument):
# class EmailParser(object):
# class MissingEmlxPart(exceptions.BrokenDocument):
# class EmlxParser(EmailParser):
# 
# Path: snoop/models.py
# def cache(model, keyfunc):
#     def decorator(func):
#         def wrapper(*args, **kwargs):
#     def __str__(self):
#     def __str__(self):
#     def absolute_path(self):
#     def _open_file(self):
#     def open(self, filesystem=False):
#     def absolute_path(self):
# class EmailCache(models.Model):
# class Collection(models.Model):
# class Document(models.Model):
#     class Meta:
# class Ocr(models.Model):
#     class Meta:
# class Digest(models.Model):
# class Job(models.Model):
#     class Meta:
# class TikaCache(models.Model):
# class TikaLangCache(models.Model):
# class HtmlTextCache(models.Model):
#                     MB = 1024*1024
# 
# Path: snoop/pgp.py
# GPG = None
#             GPG = gnupg.GPG(gnupghome=settings.SNOOP_GPG_HOME,
#                             gpgbinary=settings.SNOOP_GPG_BINARY)
# def is_enabled():
# def _get_gpg():
# def extract_pgp_block(content):
# def contains_pgp_block(content):
# def decrypt_pgp_block(content, passphrase=None):
# class DecryptionError(exceptions.BrokenDocument):


# Path: testsuite/test_pgp_hushmail.py
import tempfile
import gnupg
import pytest
from django.conf import settings
from snoop import emails, models, pgp

    reason="SNOOP_GPG_BINARY not set")

PATH_HUSH_MAIL = 'eml-9-pgp/encrypted-hushmail-knockoff.eml'
HEIN_PRIVATE_KEY = 'eml-9-pgp/keys/hein-priv.gpg'
HEIN_PUBLIC_KEY = 'eml-9-pgp/keys/hein-pub.gpg'

@pytest.yield_fixture(autouse=True)
def patch_gpg_to_temp_dir(monkeypatch):
    with tempfile.TemporaryDirectory() as tmp:
        gpg = gnupg.GPG(gnupghome=tmp, gpgbinary='gpg')
        for path in [HEIN_PRIVATE_KEY, HEIN_PUBLIC_KEY]:
            with open(settings.SNOOP_ROOT + "/" + path, 'rb') as f:
                gpg.import_keys(f.read())
        monkeypatch.setattr(pgp, 'GPG', gpg)
        monkeypatch.setattr(settings, 'SNOOP_GPG_HOME', '/tmp')
        yield

def create_email_doc(path, collection):
    doc = models.Document(
        path=path,
        content_type='message/rfc822',
        collection=collection,
    )
    doc.save = lambda *a, **k: None
    return doc

def parse_email(path, document_collection):
    return emails.parse_email(create_email_doc(path, document_collection))

def open_email(path, document_collection):

    return emails.open_email(create_email_doc(path, document_collection))