Inbound Action Script - Recipients array returns null on double quote email address

georgechen
Kilo Guru

Hi folks,

Just wondering if anyone has advice on inbound email recipients with surrounding quote marks,

I have experienced the received emails log showing recipient field as blank and verified the source emails with the senders,   they have confirmed the To address is correct, the recipient address can been seen in the received email header too.

From:George Chen <George.Chen@xxx.yy.zz>

To:"'abcqaz1234@service-now.com'" <'abcqaz1234@service-now.com'>

Subject:Test 3

however it is surrounded by ' marks e.g 'george.chen@test.com'     In the processing Inbound Mail Script the email.recipients_array returns null (

I have raised with SNOW HI and been advised to refer to Message (Java EE 6 ) , so I tried to fetch the recipient by the email.to array but unfortunately it also returns null.

I was wondering if there was a way to extract the To field in the header so that under the conditions email.recipients_array returns nothing the recipients address still could be parsed and processed to update and create records.

Thanks in advance.

George

3 REPLIES 3

staceyrocheleau
Kilo Guru

Could you use that to parse the header (getHeader("To", null))   http://docs.oracle.com/javaee/6/api/javax/mail/Part.html#getHeader(java.lang.String)

And then do some parsing?


If you do an inbound email action, can you get the header using email.headers? What does that return? You could then parse it to get the "to" perhaps and simply pattern match to grab the email.





Thanks Stacey,   I am trying the output email.getHeader("to",null) and it returns undefined



if (email.to.length==0 && email.recipients_array.length==0) {
//get email.headers in stead
logger.logInfo('getTofromHeader ()');
//getTofromHeader();
// parsing getHeader('to')
logger.logInfo('email.getHeader("To",null) = ' + email.getHeader('To',null));
logger.logInfo('email.getHeader("To") = ' + email.getHeader('To'));

}



email.getHeader("To",null) = undefined



Is the getHeader a function under email api?   If it can return the value of the To in the header, the parsing will be straightforward.



Regards,
George


I'm not sure how to use that. It was a quick guess based on the links/wiki.



If it's a matter of populating the "to" field in the email log you could add a business rule on insert. Before the insert, set a condition if the "to" is blank, try to grab it from the header. The script could parse the header something like this (tweak as necessary--this doesn't take out the <> around email etc.) This is very basic but it worked for me when I received an email with quotes like yours. It searches the header field for the line To: and then removes the "to:"   You may need to make it smarter and have the pattern look for a line starting with To:



Business Rule:


Table: Email (sys_email)


Filter: To is empty


Insert: true


When: before




(function executeRule(current, previous /*null when async*/) {
var header = current.headers.toString();

var t = /To\:[^\n]+/m.exec(header).toString();

t = t.replace(/To\:/,"");



current.direct = t;

})(current, previous);