Regular Expression to filter emails - Postmaster filter

Moderator: crythias

Post Reply
kannansoundararajan
Znuny newbie
Posts: 11
Joined: 28 Sep 2012, 07:12
Znuny Version: 3.0.11
Real Name: Kannan S
Company: Zyme Solutions

Regular Expression to filter emails - Postmaster filter

Post by kannansoundararajan »

We have a requirement where if the email originated from our domain ( ex : domain1.com) and if recepients are all our employees (whose email ids have domain1.com), we want this article to be routed as email-internal so that these interactions are not visible to customers. This is required since all are not part of OTRS and our management teams can be copied on tickets and they may want to follow up internally on the status within the company.

To accomodate this, i have set the following Postmaster filter:

Name : 1_Assign_Email_Internal (This is the first filter that gets executed)
Stop After Match = No
Filter Conditions :

Cc = ((.*)@domain1.com|())
To = ((.*)@domain1.com|())
From = ((.*)@domain1.com|())

Set Email Headers:

X-OTRS-Followup-ArticleType = email-internal

This is primarily to check if From (also has only domain1.com or empty) and (To also has only domain1.com or empty) and CC (also has only domain1.com or empty)

The above filter works only if To and CC or populated. If To or CC is not populated, the filter does not work.

I suspect my condition of empty with a | () does not seem to work. Can you kindly help with how to capture the empty condition?

Thanks,
Kannan
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Regular Expression to filter emails - Postmaster filter

Post by reneeb »

Untested:

The regex should be
\@domain1.com|(^$)

Please note that this regex matches when any recipient is in domain1.com. Even when there are recipients outside domain1.com.
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
crythias
Moderator
Posts: 10169
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Regular Expression to filter emails - Postmaster filter

Post by crythias »

Match is match all (AND). To have an OR requires separate filter.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
kannansoundararajan
Znuny newbie
Posts: 11
Joined: 28 Sep 2012, 07:12
Znuny Version: 3.0.11
Real Name: Kannan S
Company: Zyme Solutions

Re: Regular Expression to filter emails - Postmaster filter

Post by kannansoundararajan »

Thankyou both for the responses.

crythias, From your earlier posts i understand that all the filter conditions are AND which i understand completely.

But within a regular expression i want to use a OR condition. Is that not possible? Please let me know.

reneeb, let me test your recommendation and get back. Thanks.

Thanks,
Kannan
alfista16
Znuny newbie
Posts: 2
Joined: 22 Mar 2013, 15:16
Znuny Version: 3.2.0

Re: Regular Expression to filter emails - Postmaster filter

Post by alfista16 »

For the web OTRS interface, the "OR" condition can be used with the symbol " | ". As the example in the e-mail filters suggests, when you want to create a filter for me@example.com OR test@example.com, you have to write: (me|test)@example.com.

I have a question though.

Where can we find regexpressions for AND and NOT? For example, i want to create a filter for e-mails sent, whose subject contains the strings "This" AND "is" but NOT "Sparta". Any suggestions please? I was wondering if this could be implemented throught he web interface. If not, i could also edit the OTRS files.

Thank you in advance.
alfista16
Znuny newbie
Posts: 2
Joined: 22 Mar 2013, 15:16
Znuny Version: 3.2.0

Re: Regular Expression to filter emails - Postmaster filter

Post by alfista16 »

Anyone? I am still trying to find a solution to this.
crythias
Moderator
Posts: 10169
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Regular Expression to filter emails - Postmaster filter

Post by crythias »

You can't really implement a "not", but you can use the "stop processing more rules" to some effect.

Since the rules process in alphabetical order, you could search for "This.*is.*.Sparta" and essentially do nothing with it, but stop processing more rules.
The next rule alphabetically can handle "This.*is.*" normally.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
logicalispain
Znuny newbie
Posts: 4
Joined: 02 Mar 2016, 11:12
Znuny Version: 3.1.9

Re: Regular Expression to filter emails - Postmaster filter

Post by logicalispain »

Good afternoon,

We're following your guidelines, but we did not get the dynamic filters to save the value of what was previously captured by regexp in OTRS version 5.0.14:

Please, can you help us?

Best regards,
You do not have the required permissions to view the files attached to this post.
jojo
Znuny guru
Posts: 15019
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: Regular Expression to filter emails - Postmaster filter

Post by jojo »

only one capture is allowed in OTRS5 per Postmaster Filter, OTRS6 will have named captures(thanks to RenéeB)
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
logicalispain
Znuny newbie
Posts: 4
Joined: 02 Mar 2016, 11:12
Znuny Version: 3.1.9

Re: Regular Expression to filter emails - Postmaster filter

Post by logicalispain »

jojo wrote:only one capture is allowed in OTRS5 per Postmaster Filter, OTRS6 will have named captures(thanks to RenéeB)
Thanks for your answer.
You mean that, we only can capture one field?
root
Administrator
Posts: 3934
Joined: 18 Dec 2007, 12:23
Znuny Version: Znuny and Znuny LTS
Real Name: Roy Kaldung
Company: Znuny
Contact:

Re: Regular Expression to filter emails - Postmaster filter

Post by root »

Hi,

With a default OTRS 5 you can only capture one value. Maybe you can use https://opar.perl-services.de/dist/Enha ... lter-5.0.2 until OTRS 6 is released and stable. It's the from developer mentioned above (RenéeB)

- Roy
Znuny and Znuny LTS running on CentOS / RHEL / Debian / SLES / MySQL / PostgreSQL / Oracle / OpenLDAP / Active Directory / SSO

Use a test system - always.

Do you need professional services? Check out https://www.znuny.com/

Do you want to contribute or want to know where it goes ?
logicalispain
Znuny newbie
Posts: 4
Joined: 02 Mar 2016, 11:12
Znuny Version: 3.1.9

Re: Regular Expression to filter emails - Postmaster filter

Post by logicalispain »

root wrote:Hi,

With a default OTRS 5 you can only capture one value. Maybe you can use https://opar.perl-services.de/dist/Enha ... lter-5.0.2 until OTRS 6 is released and stable. It's the from developer mentioned above (RenéeB)

- Roy
Thank you very much!!!
Post Reply