Email Filter Scripts for Customer Portal#

Allegra can create items and comments on items from emails. The system itself tries to largely prevent email loops. In addition, it is possible to examine emails for specific content and suppress the creation of unwanted items. You can also remove recurring texts and attachments, such as some organizations use in their signatures and disclaimers, before creating items or comments.

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

These records are not scripts in the true sense, but are used as parameters of a filtering built into the system. They will be explained below. The records cannot be renamed. They use so-called “regular expressions”. More information on regular expressions can be found, for example, at https://wiki.selfhtml.org/wiki/Regulärer_Ausdruck.

Checking Email Subject#

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

The expressions ignore case. Comment lines start with a double hash “#”. Only one regular expression may be specified per line.

Example:

# Comment
automatic answer
out of.*?office
out of.*?house
Automatic response
out of the house

If you rename the record, it becomes inactive. This can lead to unwanted email loops. This record tries to prevent items from being created due to absence notes.

Removing Email Text#

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

The expressions ignore case and line breaks. Comment lines start with a double hash “#”. Only one regular expression may be specified per line.

In the following example, the disclaimer text at the end of an email is removed if it starts 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.

Remove Attachments from Email#

This record named EmailAttachmentRemoveRegexps allows you to remove attachments such as company logos in the signature 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 respectively after the lines with the markers “#fileNames:”, “#referencePatterns:” or “#fileHashes:”. If the system finds an attachment whose file name matches a regular expression, this attachment is not saved. The file name patterns are case sensitive.

In order to also delete the references to image attachments to be removed within the main email text, you specify reference patterns after the marker “#referencePatterns:”. The $cid part is dynamically removed with the current cid value. Each line below should contain a regular expression until the next marker.

It may happen that an email client changes the name of an embedded file to a generic name. In this 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 when editing an item with this attachment by right-clicking on the item’s attachment and selecting “File Hash Code”.

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