Prevent duplicate image attachments from email replies

Marcel H_
Tera Guru

I'm trying to solve an issue with inbound email replies and the images that are attached to the target record each time.

Currently I have inbound actions that are properly creating or updating a record when someone replies to an email thread, and email properties set so that each reply email is stripping off the previous entries in the thread and updating Additional Comments with only the latest reply. The problem that I'm having is that even though the previous replies in the email thread are stripped out effectively, any inline pictures (signature logos, pictures pasted into the email body, etc.) get duplicated as attachments each time there is a reply.

As an example, in the pictures below, there was one record where a few people replied to an email thread that originally had 4 photos and 1 signature logo. There are now 52 attachment on the record, which are all duplicates of the pics and the logo:

find_real_file.png

find_real_file.png

I had previously come across a Business Rule script that was meant to prevent exact duplicate attachments to a record, but it doesn't seem to work the way that I expected. This is a late running (order 1,000) on before BR on the sys_attachment table:

function onBefore(current, previous) {

     var attach = new GlideRecord('sys_attachment');

		attach.addQuery('table_sys_id', current.table_sys_id);
		attach.addQuery('table_name', current.table_name);
		attach.addQuery('file_name', current.file_name);
		attach.addQuery('content_type', current.content_type);
		attach.addQuery('size_bytes', current.size_bytes);
		attach.query();

	if(attach.next()){
	current.setAbortAction(true);
	}

}

 

Has anyone else come across this issue and found a way to prevent duplicate attachments?