When processing an inbound email with Generic Email Parsing Script (
https://exchange.xforce.ibmcloud.com/hub/extension/4ba70106b6f2dfa77cb1e3c921db7ff5), if the email doesn´t have a From name besides the sender email the script crashes with the error:
11:09:56.956 [Camel (camel-1) thread #525 - JmsConsumer[email-service.save-email-data]] ERROR [] c.c.e.EmailMessageIngesterImpl - Rule 'Inbound email processing' is unable to update the Email Message 'emailmessage-1163' because: AttributeError: Invalid field name: name line 499, in addBasicInfoToIncident
com.co3.domain.exceptions.Co3IllegalStateException: Rule 'Inbound email processing' is unable to update the Email Message 'emailmessage-1163' because: AttributeError: Invalid field name: name
com.ibm.resilient.common.domain.exceptions.Co3IllegalArgumentException: Script execution failed with message 'AttributeError: Invalid field name: name
Important: I got this behavior when running the script on Python3 only.
For instance:
- If sender has a name, there is no problem:
...
From: John Doe <
johndoe@company.com>
To: IBM Resilient <
resilient@company.com>
Subject: A subject
...
- If sender has no name, it crashes in the function "addBasicInfoToIncident":
...
From: <
x1234@company.com>
Subject: A subject
To: <
resilient@company.com>
...
Apparently, under Python3 it is not enough checking if attribute emailmessage.from.name is not None, in the "addBasicInfoToIncident" function from the email parsing script:
def addBasicInfoToIncident(self):
"""A method to perform basic information extraction from the email message.
The email message sender address, including personal name if present, is set as the reporter field
in the incident. An artifact is created from the email message subject with the type "Email Subject".
No return value.
"""
newReporterInfo = emailmessage.from.address
if emailmessage.from.name is not None:
newReporterInfo = u"{0} <{1}>".format(emailmessage.from.name, emailmessage.from.address)
log.info(u"Adding reporter field \"{0}\"".format(newReporterInfo))
incident.reporter = newReporterInfo
if emailmessage.subject is not None:
self.addUniqueArtifact(u"{0}".format(emailmessage.subject), "Email Subject", "")
As a workaround, I added a try/except block:
def addBasicInfoToIncident(self):
newReporterInfo = emailmessage.from.address
try:
if emailmessage.from.name is not None:
newReporterInfo = u"{0} <{1}>".format(emailmessage.from.name, emailmessage.from.address)
log.info(u"Adding reporter field \"{0}\"".format(newReporterInfo))
incident.reporter = newReporterInfo
if emailmessage.subject is not None:
self.addUniqueArtifact(u"{0}".format(emailmessage.subject), "Email Subject", "Suspicious email subject")
except:
log.error(u"Error getting emailmessage.from.name")
pass
Regards,
Guido.
------------------------------
Guido Bernat
------------------------------