Email filter scripts for the customer portal#

Allegra can create items and comments on items from emails. The system itself does its best to prevent email loops. Beyond that, you can scan emails for specific content and suppress the creation of unwanted items. You can also strip out recurring text and attachments — such as the signatures and disclaimers some organizations attach — before items or comments are created.

Managing email filter scripts#

To manage email filter scripts, go to the “Administration” perspective > Customize > Scripts. There you will find at least three scripts:

  • A parameter record EmailSubjectRejectRegexps

  • A parameter record EmailBodyCutRegexps

  • A parameter record EmailAttachmentRemoveRegexps

  • A parameter record EmailSenderAddressRejectRegexps

  • A parameter record EmailSenderNameRejectRegexps

  • A parameter record EmailBodyRejectRegexps

These records are not scripts in the strict sense; instead, they serve as parameters for filtering built into the system. They are explained below. The records cannot be renamed. They use so-called “regular expressions”. You can find more information about regular expressions, for example, at https://wiki.selfhtml.org/wiki/Regulärer_Ausdruck.

Checking the email subject#

With this record, named EmailSubjectRejectRegexps, you can, for example, suppress the creation of items triggered by out-of-office messages and prevent mail loops. To do so, you define regular expressions that are applied to the “subject” of incoming emails. If a regular expression matches, the email is discarded.

The expressions are case-insensitive. Comment lines start with a hash mark “#”. Only one regular expression may be given per line.

Example:

# comment
automatic answer
out of.*?office
out of.*?house
Automatische Antwort
ausser Haus

If you rename the record, it becomes inactive. This can lead to unwanted email loops. This record tries to prevent items from being created on the basis of out-of-office messages.

Removing email text#

This record, named EmailBodyCutRegexps, contains a series of lines with regular expressions. If one of the expressions matches part of the email’s main text (the body), that part is removed.

The expressions ignore case as well as line breaks. Comment lines start with a hash mark “#”. One regular expression may be given per line.

In the following example, the disclaimer text at the end of an email is removed if it begins with the text “This e-mail may contain confidential” and ends with the text “We thank you for your cooperation.”

# comment
This\s*e-mail\s*may\s*contain\s*confidential.*?We\s*thank\s*you\s*for\s*your\s*cooperation\.

If you rename the record, it becomes inactive.

Removing attachments from emails#

This record, named EmailAttachmentRemoveRegexps, lets you remove attachments — such as company logos in signatures — before the email is created as an item or saved as a comment.

Allegra offers three ways to filter attachments or references to them:

  • by file name

  • references to attachments

  • hash code of an attachment

You define the patterns following the lines that contain the markers “#fileNames:”, “#referencePatterns:” or “#fileHashes:”. If the system finds an attachment whose file name matches a regular expression, that attachment is not saved. File name patterns are case-sensitive.

To also delete the references to image attachments that are to be removed within the email’s main body, specify reference patterns after the marker “#referencePatterns:”. The $cid part is removed dynamically with the current cid value. Each line below it should contain one regular expression up to the next marker.

It can happen that an email client changes the name of an embedded file to a generic name. In that case you cannot identify the file by its name.

Here the “#fileHashes:” function helps you. After the marker “#fileHashes:” you create a list with one hash code per line for each file that should not be added as an attachment.

Note

You can retrieve a hash for a file while editing an item that has this attachment: right-click the item’s attachment and select “File hash code”.

# comment
#fileNamePatterns:
track.*\.png
#referencePatterns:
<a href=\"#\".*?><img.*?src=\"cid:$cid\".*?><\/a>
#fileHashes:
#mailLogo
327623B4C0F43950325B56353D431EBB
#tracklogo
B01CAF8D877E5551AA694897A4C29C36
#reportLogo
5053A46D4188920C77578FE8B75D

Checking the sender address#

With this record, named EmailSenderAddressRejectRegexps, you can suppress the creation of items from emails sent by specific sender addresses. To do so, you define regular expressions that are applied to the sender address of incoming emails. If a regular expression matches, the email is discarded.

The expressions are case-insensitive. Comment lines start with a hash mark “#”. Only one regular expression may be given per line.

Checking the sender name#

With this record, named EmailSenderNameRejectRegexps, you can suppress the creation of items from emails sent by specific sender names. To do so, you define regular expressions that are applied to the sender names of incoming emails. If a regular expression matches, the email is discarded.

The expressions are case-insensitive. Comment lines start with a hash mark “#”. Only one regular expression may be given per line.

Checking the email text#

With this record, named EmailBodyRejectRegexps, you can suppress the creation of items from emails with specific content. To do so, you define regular expressions that are applied to the email text of incoming emails. If a regular expression matches, the email is discarded.

The expressions are case-insensitive. Comment lines start with a hash mark “#”. Only one regular expression may be given per line.