# Path: snoop/digest.py
# def digest(doc):
#     if not doc.sha1:
#         with doc.open() as f:
#             md5, sha1, fsize = _calculate_hashes(f)
#             if not doc.content_type:
#                 f.seek(0)
#                 doc.content_type = libmagic_guess_content_type(f, fsize)
#         if not doc.disk_size:
#             doc.disk_size = fsize
#         doc.sha1 = sha1
#         doc.md5 = md5
#         doc.save()
# 
#     data = {
#         'path': '//'.join(_path_bits(doc)),
#         'lang': None,
#         'sha1': doc.sha1,
#         'md5': doc.md5,
#         'filename': doc.filename,
#         'rev': doc.rev,
#     }
# 
#     if emails.is_email(doc):
#         data.update(emails.parse_email(doc))
# 
#     if 'pgp' in doc.flags:
#         data['pgp'] = doc.flags['pgp']
# 
#     if doc.container_id:
#         data['message'] = doc.container_id
# 
#     filetype = guess_filetype(doc)
#     data['type'] = filetype
# 
#     if filetype in ['text', 'html']:
#         data['text'] = text.get_text(doc)
# 
#     if filetype == 'html':
#         data['safe_html'] = html.get_safe_html(doc)
# 
#     if filetype == 'image':
#         data.update(extract_exif(doc))
# 
#     if settings.SNOOP_TIKA_SERVER_ENDPOINT and \
#             filetype in settings.SNOOP_TIKA_FILE_TYPES and \
#             doc.disk_size <= settings.SNOOP_TIKA_MAX_FILE_SIZE:
#         parsed = tika_parse(doc.sha1, doc.open)
#         data['text'] = (parsed.get('content') or '').strip()
#         data.update(extract_meta(parsed.get('metadata', {})))
# 
#     if settings.SNOOP_ANALYZE_LANG:
#         if 'text' in data and len(data['text']) > 100:
#             data['lang'] = tika_lang(data['text'])[:2]
# 
#     if 'text' in data:
#         data['word-count'] = word_count(data['text'])
# 
#     ocr_items = list(models.Ocr.objects.filter(
#         collection_id=doc.collection.id,
#         md5=doc.md5
#     ))
#     if ocr_items:
#         data['ocr'] = {ocr.tag: ocr.text for ocr in ocr_items}
# 
#     if archives.is_archive(doc):
#         archives.extract_to_base(doc)
#     if pst.is_pst_file(doc):
#         pst.extract_to_base(doc)
# 
#     return data
# 
# 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/pst.py
# KNOWN_TYPES = {
#     'application/x-hoover-pst',
# }
#     CACHE_ROOT = Path(settings.SNOOP_PST_CACHE_ROOT)
#     CACHE_ROOT = None
# class PSTExtractionFailed(exceptions.BrokenDocument):
# class MissingPSTFile(exceptions.BrokenDocument):
# def _other_temps(sha1, current):
# def call_readpst(pst_path, output_dir):
# def extract_to_base(doc):
# def list_children(doc):
# def open_file(doc, name):
# def is_pst_file(doc):
# 
# Path: snoop/content_types.py
# def guess_content_type(filename):
#     return mimetypes.guess_type(filename, strict=False)[0] or ''


import pytest
import tempfile
from pathlib import Path
from django.conf import settings
from snoop import digest, models, pst
from snoop.content_types import guess_content_type

pytestmark = pytest.mark.skipif(not settings.SNOOP_READPST_BINARY,
    reason="SNOOP_READPST_BINARY not set")

PST_JANE_AND_DOE = {
    'parent': None,
    'path': "pst/flags_jane_doe.pst",
    'files': [
        "pst-test-2@aranetic.com/5.eml",
        "pst-test-2@aranetic.com/Inbox/1.eml",
        "pst-test-2@aranetic.com/Inbox/2.eml",
        "pst-test-2@aranetic.com/Inbox/3.eml",
        "pst-test-2@aranetic.com/Inbox/4.eml",
        "pst-test-2@aranetic.com/Inbox/5.eml",
        "pst-test-2@aranetic.com/Inbox/6.eml",
        "pst-test-2@aranetic.com/Sent Items/1.eml",
        "pst-test-2@aranetic.com/Sent Items/2.eml",
    ],
    'md5': '699502e6b8c005e0f2b3d523cf9479cc',
    'sha1': '7638280179f243ad10fcb4cd651bbfb5d979f5ab',
    'filename': 'flags_jane_doe.pst',
    'type': 'email-archive',
}


# Path: snoop/digest.py
# def digest(doc):
#     if not doc.sha1:
#         with doc.open() as f:
#             md5, sha1, fsize = _calculate_hashes(f)
#             if not doc.content_type:
#                 f.seek(0)
#                 doc.content_type = libmagic_guess_content_type(f, fsize)
#         if not doc.disk_size:
#             doc.disk_size = fsize
#         doc.sha1 = sha1
#         doc.md5 = md5
#         doc.save()
# 
#     data = {
#         'path': '//'.join(_path_bits(doc)),
#         'lang': None,
#         'sha1': doc.sha1,
#         'md5': doc.md5,
#         'filename': doc.filename,
#         'rev': doc.rev,
#     }
# 
#     if emails.is_email(doc):
#         data.update(emails.parse_email(doc))
# 
#     if 'pgp' in doc.flags:
#         data['pgp'] = doc.flags['pgp']
# 
#     if doc.container_id:
#         data['message'] = doc.container_id
# 
#     filetype = guess_filetype(doc)
#     data['type'] = filetype
# 
#     if filetype in ['text', 'html']:
#         data['text'] = text.get_text(doc)
# 
#     if filetype == 'html':
#         data['safe_html'] = html.get_safe_html(doc)
# 
#     if filetype == 'image':
#         data.update(extract_exif(doc))
# 
#     if settings.SNOOP_TIKA_SERVER_ENDPOINT and \
#             filetype in settings.SNOOP_TIKA_FILE_TYPES and \
#             doc.disk_size <= settings.SNOOP_TIKA_MAX_FILE_SIZE:
#         parsed = tika_parse(doc.sha1, doc.open)
#         data['text'] = (parsed.get('content') or '').strip()
#         data.update(extract_meta(parsed.get('metadata', {})))
# 
#     if settings.SNOOP_ANALYZE_LANG:
#         if 'text' in data and len(data['text']) > 100:
#             data['lang'] = tika_lang(data['text'])[:2]
# 
#     if 'text' in data:
#         data['word-count'] = word_count(data['text'])
# 
#     ocr_items = list(models.Ocr.objects.filter(
#         collection_id=doc.collection.id,
#         md5=doc.md5
#     ))
#     if ocr_items:
#         data['ocr'] = {ocr.tag: ocr.text for ocr in ocr_items}
# 
#     if archives.is_archive(doc):
#         archives.extract_to_base(doc)
#     if pst.is_pst_file(doc):
#         pst.extract_to_base(doc)
# 
#     return data
# 
# 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/pst.py
# KNOWN_TYPES = {
#     'application/x-hoover-pst',
# }
#     CACHE_ROOT = Path(settings.SNOOP_PST_CACHE_ROOT)
#     CACHE_ROOT = None
# class PSTExtractionFailed(exceptions.BrokenDocument):
# class MissingPSTFile(exceptions.BrokenDocument):
# def _other_temps(sha1, current):
# def call_readpst(pst_path, output_dir):
# def extract_to_base(doc):
# def list_children(doc):
# def open_file(doc, name):
# def is_pst_file(doc):
# 
# Path: snoop/content_types.py
# def guess_content_type(filename):
#     return mimetypes.guess_type(filename, strict=False)[0] or ''


# Path: testsuite/test_pst.py
import pytest
import tempfile
from pathlib import Path
from django.conf import settings
from snoop import digest, models, pst
from snoop.content_types import guess_content_type


pytestmark = pytest.mark.skipif(not settings.SNOOP_READPST_BINARY,
    reason="SNOOP_READPST_BINARY not set")

PST_JANE_AND_DOE = {
    'parent': None,
    'path': "pst/flags_jane_doe.pst",
    'files': [
        "pst-test-2@aranetic.com/5.eml",
        "pst-test-2@aranetic.com/Inbox/1.eml",
        "pst-test-2@aranetic.com/Inbox/2.eml",
        "pst-test-2@aranetic.com/Inbox/3.eml",
        "pst-test-2@aranetic.com/Inbox/4.eml",
        "pst-test-2@aranetic.com/Inbox/5.eml",
        "pst-test-2@aranetic.com/Inbox/6.eml",
        "pst-test-2@aranetic.com/Sent Items/1.eml",
        "pst-test-2@aranetic.com/Sent Items/2.eml",
    ],
    'md5': '699502e6b8c005e0f2b3d523cf9479cc',
    'sha1': '7638280179f243ad10fcb4cd651bbfb5d979f5ab',
    'filename': 'flags_jane_doe.pst',
    'type': 'email-archive',
}


EMAIL_TWO = {