diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8065548..00f1258 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,12 @@ Release History =============== +0.4.5 - 2019-03-20 +~~~~~~~~~~~~~~~ + +* Use uuid for filenames and not message id +* More verbose logging of exceptions + 0.4.4 - 2019-03-15 ~~~~~~~~~~~~~~~ diff --git a/pyas2/__init__.py b/pyas2/__init__.py index b602259..1658496 100644 --- a/pyas2/__init__.py +++ b/pyas2/__init__.py @@ -1,2 +1,2 @@ __title__ = 'pyAS2' -__version__ = '0.4.4' +__version__ = '0.4.5' diff --git a/pyas2/as2lib.py b/pyas2/as2lib.py index dab219e..8893f71 100644 --- a/pyas2/as2lib.py +++ b/pyas2/as2lib.py @@ -184,6 +184,7 @@ def build_mdn(message, status, **kwargs): u'The disposition-notification report has additional details.') models.Log.objects.create(message=message, status='E', text=kwargs['status_message']) message.status = 'E' + message.adv_status = kwargs['status_message'] else: message.status = 'S' diff --git a/pyas2/management/commands/sendas2message.py b/pyas2/management/commands/sendas2message.py index ea69c9e..861bec3 100644 --- a/pyas2/management/commands/sendas2message.py +++ b/pyas2/management/commands/sendas2message.py @@ -4,7 +4,7 @@ from pyas2 import as2lib from pyas2 import as2utils from pyas2 import pyas2init -from optparse import make_option +import traceback import email.utils import shutil import time @@ -71,14 +71,19 @@ def handle(self, *args, **options): try: payload = as2lib.build_message(message) as2lib.send_message(message, payload) - except Exception, e: - pyas2init.logger.error(_(u'Failed to send message, error:\n%(txt)s') % {'txt': as2utils.txtexc()}) + except Exception: message.status = 'E' - models.Log.objects.create(message=message, status='E', text=_(u'Failed to send message, error is %s' % e)) + txt = traceback.format_exc(None).decode('utf-8', 'ignore') + message.adv_status = \ + _(u'Failed to send message, error:\n%(txt)s') % {'txt': txt} + pyas2init.logger.error(message.adv_status) + + models.Log.objects.create( + message=message, status='E', text=message.adv_status) message.save() # Send mail here - as2utils.senderrorreport(message, _(u'Failed to send message, error is %s' % e)) + as2utils.senderrorreport(message, message.adv_status) sys.exit(2) sys.exit(0) diff --git a/pyas2/views.py b/pyas2/views.py index 6da56dd..7233589 100644 --- a/pyas2/views.py +++ b/pyas2/views.py @@ -19,6 +19,7 @@ import tempfile import traceback import email +import uuid def server_error(request, template_name='500.html'): @@ -436,12 +437,13 @@ def as2receive(request, *args, **kwargs): except Exception, e: message.status = 'E' - models.Log.objects.create(message=message, - status='E', - text=_(u'Failed to send message, error is %s' % e)) + message.adv_status = _(u'Failed to send message, error is:\n %s' % + traceback.format_exc(None).decode('utf-8', 'ignore')) + models.Log.objects.create( + message=message, status='E', text=message.adv_status) # Send mail here - as2utils.senderrorreport(message, _(u'Failed to send message, error is %s' % e)) + as2utils.senderrorreport(message, message.adv_status) finally: # Save message and send response to HTTP request @@ -489,9 +491,9 @@ def as2receive(request, *args, **kwargs): # Get the filename from the header and if not there set to message id if message.partner.keep_filename and payload.get_filename(): - filename = payload.get_filename() + filename = payload.get_filename()[:100] else: - filename = '%s.msg' % message.message_id + filename = '%s.msg' % uuid.uuid4() # Save the message content to the store and inbox content = payload.get_payload(decode=True) @@ -544,13 +546,14 @@ def as2receive(request, *args, **kwargs): adv_status = 'integrity-check-failed' status_message = _(u'An error occurred during the AS2 message processing: %s' % e) - except Exception, e: + except Exception: txt = traceback.format_exc(None).decode('utf-8', 'ignore') pyas2init.logger.error(_(u'Unexpected error while processing message %(msg)s, ' u'error:\n%(txt)s'), {'txt': txt, 'msg': message.message_id}) status = 'error' adv_status = 'unexpected-processing-error' - status_message = _(u'An error occurred during the AS2 message processing: %s' % e) + status_message = _(u'An error occurred during the AS2' + u' message processing: \n %s' % txt) finally: # Build the mdn for the message based on processing status mdn_body, mdn_message = as2lib.build_mdn(message,