Skip to content

Commit

Permalink
Merge pull request #52 from abhishek-ram/fixes-0320
Browse files Browse the repository at this point in the history
Fixes 0320
  • Loading branch information
abhishek-ram committed Mar 20, 2019
2 parents cb267c8 + 7890644 commit 5217ec1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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
~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion pyas2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__title__ = 'pyAS2'
__version__ = '0.4.4'
__version__ = '0.4.5'
1 change: 1 addition & 0 deletions pyas2/as2lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
15 changes: 10 additions & 5 deletions pyas2/management/commands/sendas2message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
19 changes: 11 additions & 8 deletions pyas2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import tempfile
import traceback
import email
import uuid


def server_error(request, template_name='500.html'):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5217ec1

Please sign in to comment.