Hi,
I want to filter the email received to a specific queue if the email has a PDF or DOC attachment. On the Postmaster Filter there is no field "Attachment" to choose from.
Does it have another name? Does it exist?
Thanks in advance
Filter emails by attachment
Moderator: crythias
-
- Znuny expert
- Posts: 241
- Joined: 06 Feb 2009, 11:15
- Znuny Version: 3.0.x
- Company: Perl-Services.de
- Contact:
Re: Filter emails by attachment
You should write your own postmaster filter module:
Kernel/System/PostMaster/Filter/Attachments.pm
And add this to your Kernel/Config.pm:
Disclaimer: This code is untested and you have to replace 'Queuename' with the name of the queue you want to move the ticket to.
Edit: s/TicketMoveQueue/TicketQueueSet/
Kernel/System/PostMaster/Filter/Attachments.pm
Code: Select all
# --
# Kernel/System/PostMaster/Filter/Attachments.pm - the global PostMaster module for OTRS
# Copyright (C) 2011 perl-services.de, http://perl-services.de/
# --
# $Id: Invoices.pm,v 1.4 2011/05/31 07:56:35 rb Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --
package Kernel::System::PostMaster::Filter::Attachments;
use strict;
use Kernel::System::Ticket;
use vars qw($VERSION);
$VERSION = '$Revision: 1.4 $';
$VERSION =~ s/^.*:\s(\d+\.\d+)\s.*$/$1/;
sub new {
my $Type = shift;
my %Param = @_;
# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
$Self->{Debug} = $Param{Debug} || 0;
# get needed objects
for my $Object (
qw(ConfigObject LogObject DBObject TimeObject MainObject EncodeObject)
)
{
$Self->{$Object} = $Param{$Object} || die "Got no $Object!";
}
$Self->{TicketObject} = Kernel::System::Ticket->new( %{$Self} );
return $Self;
}
sub Run {
my ( $Self, %Param ) = @_;
for my $Needed (qw(JobConfig GetParam)) {
if ( !$Param{$Needed} ) {
$Self->{LogObject}->Log(
Priority => 'error',
Message => "Need $Needed!",
);
return;
}
}
$Self->{LogObject}->Log(
Priority => 'notice',
Message => 'TicketID: ' . $Param{TicketID},
);
for my $Attachment ( @{$Param{GetParam}->{Attachment}} ) {
if ( $Attachment->{Filename} =~ m{(?:\.pdf|\.doc)\z}i ) {
$Self->{TicketObject}->TicketQueueSet(
TicketID => $Param{TicketID},
Queue => 'Queuename',
UserID => 1,
);
}
}
return 1;
}
1;
Code: Select all
$Self->{'PostMaster::PostFilterModule'}->{'010-Attachments'} = {
'Module' => 'Kernel::System::PostMaster::Filter::Attachments'
};
Edit: s/TicketMoveQueue/TicketQueueSet/
Need a Perl/OTRS developer? You can contact me at info@perl-services.de
Re: Filter emails by attachment
Thanks a lot for the quick response and help.
I'm not a Perl developer so i went the "Ctrl-C Ctrl-V" way. I created Attachments.pm and pasted your code, and edited the Config.pm and pasted your code.
I ran: otrs.LoaderCache.pm , otrs.DeleteCache.pm and otrs.RebuildConfig.pm .
I then went to PostMaster Filters but i have no option there. Must i create one in Core::PostMaster? I created one named "Attachment".
I'm not sure what am i supposed to see here
Also,
I'm not a Perl developer so i went the "Ctrl-C Ctrl-V" way. I created Attachments.pm and pasted your code, and edited the Config.pm and pasted your code.
I ran: otrs.LoaderCache.pm , otrs.DeleteCache.pm and otrs.RebuildConfig.pm .
I then went to PostMaster Filters but i have no option there. Must i create one in Core::PostMaster? I created one named "Attachment".
I'm not sure what am i supposed to see here

Also,
Is this to instruct to change "TicketQueueSet" for "TicketMoveQueue" in the Attachment.pm?Edit: s/TicketMoveQueue/TicketQueueSet/
-
- Znuny expert
- Posts: 241
- Joined: 06 Feb 2009, 11:15
- Znuny Version: 3.0.x
- Company: Perl-Services.de
- Contact:
Re: Filter emails by attachment
No, you don't have to create anything in SysConfig. The Postmaster filter is active as soon as you saved the changes in Kernel/Config.pm...
The "Edit: ..." part was just a hint for everybody who saw the first version of my post and came back later as I had changed the code. The first version was wrong... So nothing to do for you.
To see if there is an error, please have a look at the log.
The "Edit: ..." part was just a hint for everybody who saw the first version of my post and came back later as I had changed the code. The first version was wrong... So nothing to do for you.
To see if there is an error, please have a look at the log.
Need a Perl/OTRS developer? You can contact me at info@perl-services.de
Re: Filter emails by attachment
I've tried your code and it doesn't work. At least, not in the way i would want it to work. I looked at the logs and:
[Mon Aug 8 14:07:35 2011][Notice][Kernel::System::MailAccount::POP3::Fetch] POP3: Fetched 1 email(s) from ***********@***********.pt/pop.***********.pt.
[Mon Aug 8 14:09:04 2011][Notice][Kernel::System::Ticket::TicketCreate] New Ticket [2011080810000271/olha] created (TicketID=37,Queue=Postmaster,Priority=3 normal,State=new)
[Mon Aug 8 14:09:04 2011][Notice][Kernel::System::MailAccount::POP3::Fetch] POP3: Fetched 1 email(s) from ***********@***********.pt/pop.***********.pt.
[Mon Aug 8 14:10:27 2011][Notice][Kernel::System::Ticket::TicketCreate] New Ticket [2011080810000281/FW: olha] created (TicketID=38,Queue=Postmaster,Priority=3 normal,State=new)
[Mon Aug 8 14:10:27 2011][Notice][Kernel::System::MailAccount::POP3::Fetch] POP3: Fetched 1 email(s) from ***********@***********.pt/pop.***********.pt
[Mon Aug 8 14:16:11 2011][Notice][Kernel::System::Ticket::TicketCreate] New Ticket [2011080810000299/FW: olha] created (TicketID=39,Queue=Postmaster,Priority=3 normal,State=new)
[Mon Aug 8 14:16:11 2011][Notice][Kernel::System::PostMaster::Filter::Attachments::Run] TicketID: 39
I did change the QueueName to the one i wanted but to no avail. I removed the if condition so that it could execute always, like so:
for my $Attachment ( @{$Param{GetParam}->{Attachment}} ) {
#if ( $Attachment->{Filename} =~ m{(?:\.pdf|\.doc)\z}i ) {
$Self->{TicketObject}->TicketQueueSet(
TicketID => $Param{TicketID},
Queue => 'Misc',
UserID => 1,
);
#}
And it does not redirect to the given queue.
[Mon Aug 8 14:07:35 2011][Notice][Kernel::System::MailAccount::POP3::Fetch] POP3: Fetched 1 email(s) from ***********@***********.pt/pop.***********.pt.
[Mon Aug 8 14:09:04 2011][Notice][Kernel::System::Ticket::TicketCreate] New Ticket [2011080810000271/olha] created (TicketID=37,Queue=Postmaster,Priority=3 normal,State=new)
[Mon Aug 8 14:09:04 2011][Notice][Kernel::System::MailAccount::POP3::Fetch] POP3: Fetched 1 email(s) from ***********@***********.pt/pop.***********.pt.
[Mon Aug 8 14:10:27 2011][Notice][Kernel::System::Ticket::TicketCreate] New Ticket [2011080810000281/FW: olha] created (TicketID=38,Queue=Postmaster,Priority=3 normal,State=new)
[Mon Aug 8 14:10:27 2011][Notice][Kernel::System::MailAccount::POP3::Fetch] POP3: Fetched 1 email(s) from ***********@***********.pt/pop.***********.pt
[Mon Aug 8 14:16:11 2011][Notice][Kernel::System::Ticket::TicketCreate] New Ticket [2011080810000299/FW: olha] created (TicketID=39,Queue=Postmaster,Priority=3 normal,State=new)
[Mon Aug 8 14:16:11 2011][Notice][Kernel::System::PostMaster::Filter::Attachments::Run] TicketID: 39
I did change the QueueName to the one i wanted but to no avail. I removed the if condition so that it could execute always, like so:
for my $Attachment ( @{$Param{GetParam}->{Attachment}} ) {
#if ( $Attachment->{Filename} =~ m{(?:\.pdf|\.doc)\z}i ) {
$Self->{TicketObject}->TicketQueueSet(
TicketID => $Param{TicketID},
Queue => 'Misc',
UserID => 1,
);
#}
And it does not redirect to the given queue.
-
- Znuny expert
- Posts: 241
- Joined: 06 Feb 2009, 11:15
- Znuny Version: 3.0.x
- Company: Perl-Services.de
- Contact:
Re: Filter emails by attachment
Those mails have attachments? You can see that the filter is called. And when it does not move the ticket, you should add debugging output.
Add before the for-loop...
Then you can see what kind of parameters are passed.
Add
Code: Select all
use Data::Dumper;
$Self->{LogObject}->Log(
Priority => 'error',
Message => Dumper $Param{GetParam},
);
Then you can see what kind of parameters are passed.
Need a Perl/OTRS developer? You can contact me at info@perl-services.de