regular expressions for postmaster filter

Moderator: crythias

Post Reply
thoqui
Znuny newbie
Posts: 30
Joined: 10 Jun 2015, 14:43
Znuny Version: 3.3.8

regular expressions for postmaster filter

Post by thoqui »

Hello,

I didn't find a regular expression to get first three letters of first name and first two letters of name from an email address in the header "Body".

For example : 'FirstName.Name@domain.com...' ==> 'FirNa'

Thanks
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 expressions for postmaster filter

Post by reneeb »

Doesn't work with stock postmaster filters. You need either http://opar.perl-services.de/dist/Enhan ... lter-4.0.1 or write your own postmaster filter module.
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
thoqui
Znuny newbie
Posts: 30
Joined: 10 Jun 2015, 14:43
Znuny Version: 3.3.8

Re: regular expressions for postmaster filter

Post by thoqui »

Thanks you !

But how to convert a case text to uppercase text in postmaster filters ?
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 expressions for postmaster filter

Post by reneeb »

If you want to do more than just match, you definitely need your own postmaster filter module... As a base, you could use https://gist.github.com/reneeb/7308b1cb390a26c1bfe5
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
thoqui
Znuny newbie
Posts: 30
Joined: 10 Jun 2015, 14:43
Znuny Version: 3.3.8

Re: regular expressions for postmaster filter

Post by thoqui »

What do the file SetQueue.pm do ?
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 expressions for postmaster filter

Post by reneeb »

It checks whether a ticket is not in Queue1 and not closed and sets the new queue and a new state for the ticket.

In your case, you have to replace the lines 46 to 56 with something like

Code: Select all

my ($First, $Last) = $Param{GetParam}->{From} =~ m{
    (\w{3})   # first three letter of firstname
    \w+        # rest of firstname
    \.            # separator
    (\w{2})   # first two letters of lastname
   \w+        # rest of lastname
   \@         # literal @
}xms;

# make the first character uppercase and the rest lowercase
$First = ucfirst lc $First;
$Last = ucfirst lc $Last;

# do what ever you want with the info
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
thoqui
Znuny newbie
Posts: 30
Joined: 10 Jun 2015, 14:43
Znuny Version: 3.3.8

Re: regular expressions for postmaster filter

Post by thoqui »

I tried to test your file but it doesn't work.

I added the file in C:\otrs\OTRS\Kernel\System\PostMaster\Filter, is it all ?
Then, is there an other configuration to do ?
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 expressions for postmaster filter

Post by reneeb »

The sample config is also in the gist.
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
thoqui
Znuny newbie
Posts: 30
Joined: 10 Jun 2015, 14:43
Znuny Version: 3.3.8

Re: regular expressions for postmaster filter

Post by thoqui »

I am sorry but I don't know the gist.
How to do it ?
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 expressions for postmaster filter

Post by reneeb »

reneeb wrote:[...] As a base, you could use https://gist.github.com/reneeb/7308b1cb390a26c1bfe5
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
thoqui
Znuny newbie
Posts: 30
Joined: 10 Jun 2015, 14:43
Znuny Version: 3.3.8

Re: regular expressions for postmaster filter

Post by thoqui »

Yes, I saw it before but where should I put this gist ?
In C:\otrs\OTRS\Custom\Kernel\Config.pm ?
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 expressions for postmaster filter

Post by reneeb »

Yes in Kernel/Config.pm
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
thoqui
Znuny newbie
Posts: 30
Joined: 10 Jun 2015, 14:43
Znuny Version: 3.3.8

Re: regular expressions for postmaster filter

Post by thoqui »

Actually, it works very well with EnhancedPostmasterFilter because I had to reboot IIS to convert lowercase to uppercase !

Thanks you for all.

Thomas
Post Reply