OTRS 4 ignore duplicated mails

Moderator: crythias

Locked
ovron
Znuny newbie
Posts: 19
Joined: 23 Apr 2015, 15:29
Znuny Version: 4.0.7

OTRS 4 ignore duplicated mails

Post by ovron »

Hello

We successfully upgraded otrs from 3.3 to 4.0.7.
On the version 3.3 we had a PostMaster Filter called RejectDoubledConent.pm which ignores mails if a ticket already exists with the same subject and body. But now this filter don't work on the version 4.0.7.

Filter on version 3.3:

Code: Select all

# --
# Kernel/System/PostMaster/Filter/RejectDoubledContent.pm - sub part of PostMaster.pm
# Copyright (C) 2012 Perl-Services.de
# --
# $Id: NewTicketReject.pm,v 1.20 2012/11/20 15:52:12 mh 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::RejectDoubledContent;

use strict;
use warnings;

use Kernel::System::Ticket;
use Kernel::System::Email;

use vars qw($VERSION);
$VERSION = qw($Revision: 1.20 $) [1];

sub new {
    my ( $Type, %Param ) = @_;

    # allocate new hash for object
    my $Self = {};
    bless( $Self, $Type );

    $Self->{Debug} = $Param{Debug} || 0;

    # get needed objects
    for (qw(ConfigObject LogObject DBObject MainObject)) {
        $Self->{$_} = $Param{$_} || die "Got no $_!";
    }

    $Self->{TicketObject} = Kernel::System::Ticket->new(%Param);
    $Self->{EmailObject}  = Kernel::System::Email->new(%Param);

    return $Self;
}

sub Run {
    my ( $Self, %Param ) = @_;

    # check needed stuff
    for (qw(JobConfig GetParam)) {
        if ( !$Param{$_} ) {
            $Self->{LogObject}->Log( Priority => 'error', Message => "Need $_!" );
            return;
        }
    }

    # Search for tickets with the same subject, sender, state
    my %MailParams = %{ $Param{GetParam} || {} };
    my @TicketIDs = $Self->{TicketObject}->TicketSearch(
        From => $MailParams{From},
        Subject => $MailParams{Subject},
	StateType => ['open', 'new']
	UserID	=> 1,
    );

    # ignore mail if tickets with the same params are found
    if ( @TicketIDs ) {
        $Param{GetParam}->{'X-OTRS-Ignore'} = 'yes';
    }

    return 1;
}

1;
And also in the config.pm:

Code: Select all

$Self->{'PostMaster::PreFilterModule'}->{'0001-DoubledContent'} = {
        Module => 'Kernel::System::PostMaster::Filter::RejectDoubledContent',
};
Do you have any idea how i've to change the file that it works on version 4.0.7?

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: OTRS 4 ignore duplicated mails

Post by reneeb »

untested

Code: Select all

# --
# Kernel/System/PostMaster/Filter/RejectDoubledContent.pm - sub part of PostMaster.pm
# Copyright (C) 2012 Perl-Services.de
# --
# $Id: NewTicketReject.pm,v 1.20 2012/11/20 15:52:12 mh 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::RejectDoubledContent;

use strict;
use warnings;

our @ObjectDependencies = qw(
    Kernel::System::Ticket
    Kernel::System::Log
);

sub new {
    my ( $Type, %Param ) = @_;

    # allocate new hash for object
    my $Self = {};
    bless( $Self, $Type );

    $Self->{Debug} = $Param{Debug} || 0;

    return $Self;
}

sub Run {
    my ( $Self, %Param ) = @_;

    my $LogObject = $Kernel::OM->Get('Kernel::System::Log');
    my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');

    # check needed stuff
    for (qw(JobConfig GetParam)) {
        if ( !$Param{$_} ) {
            $LogObject->Log( Priority => 'error', Message => "Need $_!" );
            return;
        }
    }

    # Search for tickets with the same subject, sender, state
    my %MailParams = %{ $Param{GetParam} || {} };
    my @TicketIDs = $TicketObject->TicketSearch(
        From => $MailParams{From},
        Subject => $MailParams{Subject},
   StateType => ['open', 'new']
   UserID   => 1,
    );

    # ignore mail if tickets with the same params are found
    if ( @TicketIDs ) {
        $Param{GetParam}->{'X-OTRS-Ignore'} = 'yes';
    }

    return 1;
}

1;
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
ovron
Znuny newbie
Posts: 19
Joined: 23 Apr 2015, 15:29
Znuny Version: 4.0.7

Re: OTRS 4 ignore duplicated mails

Post by ovron »

Thank you but it don't work..

in the sys log from otrs it stays:

- Can't process mail, see log sub system! at /opt/otrs/bin/otrs.PostMaster.pl line 100.
- syntax error at /opt/otrs/Kernel/System/PostMaster/Filter/RejectDoubledContent.pm line 54, near "UserID"


- POP3S: Can't process mail, mail saved (/opt/otrs/var/spool/problem-email-71732db1e057a1693cf14b1e226f7408, report it on http://bugs.otrs.org/)!
- syntax error at /opt/otrs/bin/cgi-bin/../../Kernel/System/PostMaster/Filter/RejectDoubledContent.pm line 54, near "UserID"
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: OTRS 4 ignore duplicated mails

Post by reneeb »

There's a comma missing after

Code: Select all

   StateType => ['open', 'new']
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
ovron
Znuny newbie
Posts: 19
Joined: 23 Apr 2015, 15:29
Znuny Version: 4.0.7

Re: OTRS 4 ignore duplicated mails

Post by ovron »

Now it works!!

Thanks a lot!
Locked