Remove image/png from inbound emails

Leonard Brown
Tera Contributor

Hi Everyone,

I'm currently tasked with setting up a inbound action to map a excel sheet imported to transform maps created in the system. This is working fine but then if someone has a image in their email like in their signature for example the image is getting attached to the email record too. I know there are some properties we can update to help mitigate this but I have been tasked with handling this without changing them. I would like to somehow either create a transform script or business rule to remove any attachment that comes in as image/png in that email before the maps even run but not having any luck accomplishing this. I appreciate any feedback provided thank you in advance. 

3 REPLIES 3

Nayan Mahato
Tera Guru
Hi Leonard Brown,
 
The easiest way to handle it is by using the below two system properties. Thanks.
 
glide.email.inbound.image_sys_attachment.filter.action-
 
The action to take on filtered inbound email image attachments.you can use to filter images and either attach to the record, attach to the email or not attach at all
 
glide.email.inbound.image_sys_attachment.filter.minimum_bytes-
 
Inbound email image attachment byte size below which the image attachment is filtered (0 is no filtering)
 
Regards,
Nayan
 
 

 

Hi Nayan,

 

Thank you for the feedback but I have been tasked with completing this change without modifying those properties. I would like to know alternatives that have been successful for completing this before the properties became an option in previous version upgrade. 

You can write the below BR in the sys_emal table. Thanks.

 

Table: sys_emal

 When: After

 Condition: current.body.indexOf('<img') > 0

 Script:

 (function executeRule(current, previous /*null when async*/) { 

 var attachsToDelete = current.body.match(/<img.*alt=".*target_sn".*>/g);

var numToDelete = attachsToDelete.length;

 if (numToDelete > 0) {

 for (var x = 0; x < numToDelete; x++) {

 var sysIdStart = attachsToDelete[x].search(/src="cid:/) + 'src="cid:'.length;

 var fileName = attachsToDelete[x].substring(sysIdStart, attachsToDelete[x].search(/@/));

  var grSysAttach = new GlideRecord('sys_attachment');

 grSysAttach.addQuery('file_name','STARTSWITH', fileName);

 grSysAttach.addQuery('table_name', 'sys_email');

 grSysAttach.addQuery('table_sys_id', current.sys_id);

 grSysAttach.query();

  if (grSysAttach.next() && grSysAttach.getRowCount() < 2) {

  grSysAttach.deleteRecord();

  }

  }

}

 })(current, previous);

 

OR Got to the below link-

*************

https://community.servicenow.com/community?id=community_article&sys_id=3208b6c4db114090190dfb243996196c

 

Regards,

Nayan