# Path: pyas2/models.py
# DEFAULT_ENTRY = ('', "---------")
#     CONTENT_TYPE_CHOICES = (
#         ('application/EDI-X12', 'application/EDI-X12'),
#         ('application/EDIFACT', 'application/EDIFACT'),
#         ('application/edi-consent', 'application/edi-consent'),
#         ('application/XML', 'application/XML'),
#         ('text/CSV', 'text/CSV'),
#     )
#     ENCRYPT_ALG_CHOICES = (
#         ('des_ede3_cbc', '3DES'),
#         ('des_cbc', 'DES'),
#         ('aes_128_cbc', 'AES-128'),
#         ('aes_192_cbc', 'AES-192'),
#         ('aes_256_cbc', 'AES-256'),
#         ('rc2_40_cbc', 'RC2-40'),
#     )
#     SIGN_ALG_CHOICES = (
#         ('sha1', 'SHA-1'),
#     )
#     MDN_TYPE_CHOICES = (
#         ('SYNC', 'Synchronous'),
#         ('ASYNC', 'Asynchronous'),
#     )
#     DIRECTION_CHOICES = (
#         ('IN', _('Inbound')),
#         ('OUT', _('Outbound')),
#     )
#     STATUS_CHOICES = (
#         ('S', _('Success')),
#         ('E', _('Error')),
#         ('W', _('Warning')),
#         ('P', _('Pending')),
#         ('R', _('Retry')),
#         ('IP', _('In Process')),
#     )
#     MODE_CHOICES = (
#         ('SYNC', _('Synchronous')),
#         ('ASYNC', _('Asynchronous')),
#     )
#     STATUS_CHOICES = (
#         ('S', _('Success')),
#         ('E', _('Error')),
#         ('W', _('Warning')),
#     )
#     STATUS_CHOICES = (
#         ('S', _('Sent')),
#         ('R', _('Received')),
#         ('P', _('Pending')),
#     )
# def get_certificate_path(instance, filename):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
# def getorganizations():
# def getpartners():
# def check_odirs(sender, instance, created, **kwargs):
# def check_pdirs(sender, instance, created, **kwargs):
# def update_dirs():
# class PrivateCertificate(models.Model):
# class PublicCertificate(models.Model):
# class Organization(models.Model):
# class Partner(models.Model):
# class Message(models.Model):
# class Payload(models.Model):
# class Log(models.Model):
# class MDN(models.Model):
# 
# Path: pyas2/pyas2init.py
# def initialize():
# def initserverlogging(logname):


import requests
import email
import hashlib
import as2utils
import os
import base64
from django.utils.translation import ugettext as _
from email.mime.multipart import MIMEMultipart
from email.parser import HeaderParser
from pyas2 import models
from pyas2 import pyas2init
from string import Template
        signed_message.as_string()
        as2_content = as2utils.canonicalize(as2utils.extractpayload(signed_message))
        payload = signed_message
        pyas2init.logger.debug('Signed message %s payload as:\n%s' % (message.message_id, payload.as_string()))

    # Encrypt the message if requested in the profile
    if message.partner.encryption:
        models.Log.objects.create(message=message,
                                  status='S',
                                  text=_(u'Encrypting the message using partner key {0:s}'.format(
                                      message.partner.encryption_key)))
        message.encrypted = True
        payload = as2utils.encrypt_payload(as2utils.canonicalize(as2utils.mimetostring(payload, 0)),
                                           message.partner.encryption_key.certificate.path,
                                           message.partner.encryption)
        payload.set_type('application/pkcs7-mime')
        as2_content = payload.get_payload().decode('base64')
        del payload['Content-Transfer-Encoding']
        pyas2init.logger.debug('Encrypted message %s payload as:\n%s' % (message.message_id, payload.as_string()))

    # If MDN is to be requested from the partner, set the appropriate headers
    if message.partner.mdn:
        as2_header['disposition-notification-to'] = 'no-reply@pyas2.com'
        if message.partner.mdn_sign:
            as2_header['disposition-notification-options'] = u'signed-receipt-protocol=required, ' \
                                                             u'pkcs7-signature; ' \
                                                             u'signed-receipt-micalg=optional, ' \
                                                             u'%s' % message.partner.mdn_sign
        message.mdn_mode = 'SYNC'
        if message.partner.mdn_mode == 'ASYNC':

# Path: pyas2/models.py
# DEFAULT_ENTRY = ('', "---------")
#     CONTENT_TYPE_CHOICES = (
#         ('application/EDI-X12', 'application/EDI-X12'),
#         ('application/EDIFACT', 'application/EDIFACT'),
#         ('application/edi-consent', 'application/edi-consent'),
#         ('application/XML', 'application/XML'),
#         ('text/CSV', 'text/CSV'),
#     )
#     ENCRYPT_ALG_CHOICES = (
#         ('des_ede3_cbc', '3DES'),
#         ('des_cbc', 'DES'),
#         ('aes_128_cbc', 'AES-128'),
#         ('aes_192_cbc', 'AES-192'),
#         ('aes_256_cbc', 'AES-256'),
#         ('rc2_40_cbc', 'RC2-40'),
#     )
#     SIGN_ALG_CHOICES = (
#         ('sha1', 'SHA-1'),
#     )
#     MDN_TYPE_CHOICES = (
#         ('SYNC', 'Synchronous'),
#         ('ASYNC', 'Asynchronous'),
#     )
#     DIRECTION_CHOICES = (
#         ('IN', _('Inbound')),
#         ('OUT', _('Outbound')),
#     )
#     STATUS_CHOICES = (
#         ('S', _('Success')),
#         ('E', _('Error')),
#         ('W', _('Warning')),
#         ('P', _('Pending')),
#         ('R', _('Retry')),
#         ('IP', _('In Process')),
#     )
#     MODE_CHOICES = (
#         ('SYNC', _('Synchronous')),
#         ('ASYNC', _('Asynchronous')),
#     )
#     STATUS_CHOICES = (
#         ('S', _('Success')),
#         ('E', _('Error')),
#         ('W', _('Warning')),
#     )
#     STATUS_CHOICES = (
#         ('S', _('Sent')),
#         ('R', _('Received')),
#         ('P', _('Pending')),
#     )
# def get_certificate_path(instance, filename):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
# def getorganizations():
# def getpartners():
# def check_odirs(sender, instance, created, **kwargs):
# def check_pdirs(sender, instance, created, **kwargs):
# def update_dirs():
# class PrivateCertificate(models.Model):
# class PublicCertificate(models.Model):
# class Organization(models.Model):
# class Partner(models.Model):
# class Message(models.Model):
# class Payload(models.Model):
# class Log(models.Model):
# class MDN(models.Model):
# 
# Path: pyas2/pyas2init.py
# def initialize():
# def initserverlogging(logname):


# Path: pyas2/as2lib.py
import requests
import email
import hashlib
import as2utils
import os
import base64
from django.utils.translation import ugettext as _
from email.mime.multipart import MIMEMultipart
from email.parser import HeaderParser
from pyas2 import models
from pyas2 import pyas2init
from string import Template

        signed_message.as_string()
        as2_content = as2utils.canonicalize(as2utils.extractpayload(signed_message))
        payload = signed_message
        pyas2init.logger.debug('Signed message %s payload as:\n%s' % (message.message_id, payload.as_string()))

    # Encrypt the message if requested in the profile
    if message.partner.encryption:
        models.Log.objects.create(message=message,
                                  status='S',
                                  text=_(u'Encrypting the message using partner key {0:s}'.format(
                                      message.partner.encryption_key)))
        message.encrypted = True
        payload = as2utils.encrypt_payload(as2utils.canonicalize(as2utils.mimetostring(payload, 0)),
                                           message.partner.encryption_key.certificate.path,
                                           message.partner.encryption)
        payload.set_type('application/pkcs7-mime')
        as2_content = payload.get_payload().decode('base64')
        del payload['Content-Transfer-Encoding']
        pyas2init.logger.debug('Encrypted message %s payload as:\n%s' % (message.message_id, payload.as_string()))

    # If MDN is to be requested from the partner, set the appropriate headers
    if message.partner.mdn:
        as2_header['disposition-notification-to'] = 'no-reply@pyas2.com'
        if message.partner.mdn_sign:
            as2_header['disposition-notification-options'] = u'signed-receipt-protocol=required, ' \
                                                             u'pkcs7-signature; ' \
                                                             u'signed-receipt-micalg=optional, ' \
                                                             u'%s' % message.partner.mdn_sign
        message.mdn_mode = 'SYNC'
        if message.partner.mdn_mode == 'ASYNC':

            as2_header['receipt-delivery-option'] = pyas2init.gsettings['mdn_url']