Expand my Community achievements bar.

Announcing the launch of new sub-community for Campaign Web UI to cater specifically to the needs of Campaign Web UI users!

Constraint / dataPolicy on Email Address

Avatar

Level 5

Hi there,

I'm aware there is a constraint on the email address field on the Recipient table (aka a data policy) that only allows a "valid format" email address to be stored in this field.

Does anyone know where the "rules" of the constraint is documented?

I'd like to be able to replicate the logic when exporting data from a CRM system that exports data to Adobe Campaign, so these records can be filtered at source.

Thanks

David

12 Replies

Avatar

Community Advisor

Hi,

The dataPolicy rules are undocumented, but if you're implementing validation it should hew to rfc 5322 compliance anyway:

Thanks,

-Jon

Avatar

Community Advisor

Hi David,

You can find it under Administration>Configuration> Javascript codes

it's called dataPolicy.js

1745834_pastedImage_2.png

Thanks

David



David Kangni

Avatar

Community Advisor

That's a subset of the dataPolicy functionality (missing emailOrScript, hyphenIdentifier), looks like part of interaction module's js xtk implementation. I wonder if the c++ xtk matches, and why they didn't just copy the rfc regex..

Avatar

Level 7

Hi davidk23955130​ - I just tested that code you highlighted above with an invalid email address - "blah23/2456@gmail.com" - it passes those tests but you can't insert it into the recipient table. The email addresses passes all RFC5322 tests I have thrown at it.

Can anyone tell us the exact data policy that Adobe Campaign uses to validate an email? We need this.

Avatar

Community Advisor

1748141_pastedImage_11.png

email is defined as string using constraint on data policy.

If you need to use any of the special characters literally, you must escape it by putting a backslash in front of it e.g /a\*b/ to escape '*'. ACC's regex in the data policy doesn't have the escaping special characters capability as it's using an old javascript regex.

Thanks

David



David Kangni

Avatar

Level 7

Hi David - I tried what you said and escaped the special characters in the email, but the recipient write still fails. Here is my test code:

var email = "blah23\/2456@gmail.com";

var firstName = "Ford";

var lastName = "Prefect";

var mobile = "0000888999"

//RFC5322 email regex

var regexEmail = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

 

var pattEmail = new RegExp(regexEmail);

//this will pass

if(pattEmail.test(email)) {

var recipientId = xtk.session.GetNewIds(1);

//this will fail

xtk.session.Write(

      <recipient _operation="insert"

          xtkschema="nms:recipient"

          id={recipientId}

          email={email}

          firstName={firstName}

          lastName={lastName}

          mobilePhone={mobile} >

          <folder name="nmsRootRecipient"/>

      </recipient>

    );

} else {

  logWarning("Bad email: " + email);

}

2019-05-08 08_30_59-Journal.png

Avatar

Level 7

And again using Adobe dataPolicy.js email test instead of the RFC5322 regex:

var email = "blah23\/2456@gmail.com";

var firstName = "Ford";

var lastName = "Prefect";

var mobile = "0000888999"

var testResult = null;

//dataPolicy.js email test

var aPart = email.split("@");

if (aPart.length === 2 && aPart[0].match(/^[\S]+$/) &&

    aPart[1].match(/^([\w\-]+\.)+[\w\-]+$/)) {

  testResult = email.toLowerCase();

} else {

  // TODO shouldn't we return an empty string?

  testResult = null;

}

logInfo("Result of Adobe email test: " + testResult);

//this will pass

if(testResult) {

var recipientId = xtk.session.GetNewIds(1);

//this will fail

xtk.session.Write(

      <recipient _operation="insert"

          xtkschema="nms:recipient"

          id={recipientId}

          email={email}

          firstName={firstName}

          lastName={lastName}

          mobilePhone={mobile} >

          <folder name="nmsRootRecipient"/>

      </recipient>

    );

} else {

  logWarning("Bad email: " + email);

}

2019-05-08 09_01_26-Journal.png

Avatar

Community Advisor

it's normal because your attribute in your recipient schema is still using the default dataPolicy

Thanks

David



David Kangni

Avatar

Level 7

So what is the exact test for an invalid email where the recipient schema uses the default dataPolicy? I need to be able to capture these invalid emails before it gets to the write stage

Avatar

Level 7

So another piece to this puzzle (provided by Support) is the option value for the valid characters in an email address XtkEmail_Characters. I tested this value and this Option value is definitely being used by the mystery validation function to check for valid characters in the email before the write happens.

email_chars.png

What they couldn't confirm was how this was applied to the email address (local-part or domain or both). Nor could they confirm what other checks were being performed before the recipient Write was attempted.

Avatar

Level 7

OK - I finally have an answer on how ACC determines a valid email. It took way more effort than I expected but we got an answer:

So I am assuming that the first part of this response is the dataPolicy check and the second is a regex against the XtkEmail_Characters option. e.g. something like this

loadLibrary("xtk:shared/nl.js");

loadLibrary("xtk:shared/dataPolicy.js");

var email = "blah232456@gmail.com";

/**

*

* Function to determine if an email is valid for the Adobe Campaign

* database checks. This process checks using the default email dataPolicy

* and the option value XtkEmail_Characters.

*

* @param email {string} email address to test

* @return true(valid) | false(invalid)

*

**/ 

function isValidAdobeEmail( email ) { 

var patt = "[^@" + getOption('XtkEmail_Characters').replace(/[.*+?\-^${}()|[\]\\]/g, '\\\$&') + "]";

//logInfo("EmailFunctions.js::isValidAdobeEmail() - Escaped XtkEmail_Characters: " + patt);

var regex = new RegExp(patt, "g"); 

var testFlag = !regex.test(email); 

//logInfo("Result of XtkEmail_Characters test: " + ((testFlag)?"valid":"invalid"));

var dataPolicyResult = !NL.isEmpty(NL.DataPolicy.filter("email", email)); 

//logInfo("Result of dataPolicy email test: " + ((!NL.isEmpty(dataPolicyResult))?"valid":"invalid"));

return testFlag && dataPolicyResult; 

}

//Test the email

if( isValidAdobeEmail(email) ) {

  //email address is valid

} else {

  //email is invalid

}

Edit: minimised the code

Avatar

Community Advisor

Hi,

No there is no regex here. The code is matching characters after splitting the string into @ and .

Pseudocode in js would be:

str.split(/[@.]/).filter(function(_){

    return _.match(/^[XtkEmail_Characters as a character class]+$/);

}).length >= 3

Thanks,

-Jon