Dropping a email using Pre-Proc Script
- 1 Summary
- 1.1 Example Script - Drop Based on Cc Address excluding To Address (After version 4.1.4)
- 1.2 Example Script - Drop Based on Cc Address excluding To Address (Before version 4.1.4)
- 1.3 Example Script - Drop Based on Sender (After version 4.1.4)
- 1.4 Example Script - Drop Based on Sender (Before version 4.1.4)
- 1.5 Example Script - Drop based on Sender and Recipient address being found (After version 4.1.4)
Summary
Any Headers you wish to alter must be in the Matching Headers csv, or they will not be processed!
You may have a email sender that you do not want to create any new issues or comments. The solutions below will check specific conditions (e.g. Sender matches specific address) and if the conditions match then the email will be dropped. The solutions before version 4.1.4 do not use jemhUtils.dropMessage as this could not be used with the Pre-Proc tasks at the time, instead they will alter the subject to a value that matches the global blacklist. This value will first have to be added to the global blacklist.
Example Email
MIME-Version: 1.0
Received: by 10.223.112.12 with HTTP; Sat, 18 Jun 2011 22:42:26 -0700 (PDT)
Date: Sun, 19 Jun 2011 17:42:26 +1200
Message-ID: <BANLkTinB1mfSh+GwOXGNWoL4SyDvOpdBoQ@mail.gmail.com>
Subject: this message should be dropped when it is processed
From: system@x.com
To: mailbox@localhost
Cc: test@test.com
Content-Type: text/plain; charset=UTF-8
will the comment be rejected since the field processor has been changed testbodyExample Script - Drop Based on Cc Address excluding To Address (After version 4.1.4)
Matching Headers:
To,CcHeader Script:
for (i = 0; i < toAddresses.length; i++) {
if (toAddresses[i] !== "test@test.com") {
for (j = 0; j < ccAddresses.length; j++) {
if (ccAddresses[j] == "test@test.com") {
jemhUtils.dropMessage("Dropped due to a match of email test@test.com in the Cc Header");
}
}
}
}Matching Headers:
To,Cc,SubjectExample Script - Drop Based on Cc Address excluding To Address (Before version 4.1.4)
for (i = 0; i < toAddresses.length; i++) {
if (toAddresses[i] !== "test@test.com") {
for (j = 0; j < ccAddresses.length; j++) {
if (ccAddresses[j] == "test@test.com") {
headerBeans.get('subject').setUpdatedVal("Drop Me");
}
}
}
}Matching Headers:
To,Cc,SubjectExample Script - Drop Based on Sender (After version 4.1.4)
/* Enter custom Script here (example below) -- USE LOWER CASE HEADER NAMES */
var sender = null;
/*Retrieves the sender of the email*/
var fromHeader = headerBeans.get('from').getOriginalVal();
if (fromHeader !== null){
sender = fromHeader;
} else {
var replyToHeader = headerBeans.get('reply-to').getOriginalVal();
if (replyToHeader !== null) {
sender = replyToHeader;
}
}
/*checks if sender is system@x.com*/
if(sender !== null && sender.contains("system@x.com")){
/* Drops the email*/
jemhUtils.dropMessage("Dropped due to a match of sender email system@x.com");
} Matching Headers:
From,Reply-ToExample Script - Drop Based on Sender (Before version 4.1.4)
/* Enter custom Script here (example below) -- USE LOWER CASE HEADER NAMES */
/*Retrieves the sender of the email*/
var sender = headerBeans.get('from').getOriginalVal();
print('sender: '+ sender);
/*Retrieves the subject from email*/
var subjectVal = headerBeans.get('subject').getOriginalVal();
print('subject: '+ subjectVal);
/*checks if sender is system@x.com*/
if(sender == "system@x.com"){
/*Alters the subject to Drop Me*/
headerBeans.get('subject').setUpdatedVal("Drop Me");
print('New subject: ' + headerBeans.get('subject').getUpdatedVal() );
} Matching Headers:
From,SubjectExample Script - Drop based on Sender and Recipient address being found (After version 4.1.4)
Lines 10 - 18 must follow the same ordering as "Reply-To: then From: From Address Parse Order" within Email > Pre-Processing to ensure the correct processing occurs. For example if this is set to “Reply-To then From” then the Reply-To header must be checked before the From header.
var senderMatched = false;
var recipientMatched = false;
/* Sender and Recipient to be matched*/
var senderToMatch = "sender@test.com";
var recipientToMatch = "recipient@test.com";
/* Evaluating From Header and Then ReplyTo header for sender, the ordering of this needs to match */
/* "Reply-To: then From: From Address Parse Order" within Email > Pre-Processing to ensure the correct sender processing order. */
var fromHeader = headerBeans.get('from').getOriginalVal();
if (fromHeader !== null){
senderMatched = fromHeader.contains(senderToMatch);
} else {
var replyToHeader = headerBeans.get('reply-to').getOriginalVal();
if (replyToHeader !== null) {
senderMatched = replyToHeader.contains(senderToMatch);
}
}
/* Evaluating To header for the recipient address */
var toHeader = headerBeans.get('to').getOriginalVal();
if (toHeader !== null){
print(toHeader);
recipientMatched = toHeader.contains(recipientToMatch);
}
/* If match is not found then evaluate Cc header for the recipient address */
if (!recipientMatched){
var ccHeader = headerBeans.get('cc').getOriginalVal();
if (ccHeader !== null){
recipientMatched = ccHeader.contains(recipientToMatch);
}
}
/* If matches are found then drop the message */
if(senderMatched && recipientMatched){
jemhUtils.dropMessage("Dropped due to a match of sender email admin@admin.com and recipient match of mailbox@localhost");
} Matching Headers
From,Reply-To,To,Cc