#!/usr/bin/env python3
#
# process an .eml file through the whole markup process

import sys
import os
import inspect

currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
parentparentdir = os.path.dirname(parentdir)
sys.path.insert(0, parentparentdir)

import getopt
import django
from django.conf import settings

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'procat2.settings')
django.setup()

from markup.tasks import process_message


def main(argv):
    def usage():
        print('usage: %s file.eml' % argv[0])
        return 100
    try:
        (opts, args) = getopt.getopt(argv[1:], '')
    except getopt.GetoptError:
        return usage()
    if not args: return usage()

    process_message(args[0])


if __name__ == '__main__': sys.exit(main(sys.argv))
