Ich bins nochmal! Habe mich nun doch daran gesetzt und mittels dem
OTRS Entwickler Handbuch und dem Beispiel mir ein eigenen Postmaster Filter geschrieben:
ABFilter.pm
Code: Select all
# --
# Kernel/System/PostMaster/Filter/ABFilter.pm - a postmaster filter
# Copyright (C) 2008 Fr4nk
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see http://www.gnu.org/licenses/gpl.txt.
# --
package Kernel::System::PostMaster::Filter::ABFilter;
use strict;
use vars qw($VERSION);
use DBI;
$VERSION = '$Revision: 1.21.2.1 $';
$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$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 opbjects
foreach (qw(ConfigObject LogObject DBObject)) {
$Self->{$_} = $Param{$_} || die "Got no $_!";
}
return $Self;
}
sub Run {
my $Self = shift;
my %Param = @_;
# get config options
my %Config = ();
my %Match = ();
my %Set = ();
if ($Param{JobConfig} && ref($Param{JobConfig}) eq 'HASH') {
%Config = %{$Param{JobConfig}};
if ($Config{Match}) {
%Match = %{$Config{Match}};
}
if ($Config{Set}) {
%Set = %{$Config{Set}};
}
}
# match 'Match => ???' stuff
my $Matched = '';
my $MatchedNot = 0;
my $Subject;
my $CustomerNo;
my $CustomerLogin;
my $CustomerEmail;
my $CustomerFirstName;
my $CustomerLastName;
my $DB = "DBI:mysql:otrs";
my $User = "root";
my $Pswd = '**PSWD**';
my $Anz = 0;
my $i = 0;
my @Datei;
my @Ergebnis;
my @Customer_logins;
my @Customer_emails;
my @Customer_firsts;
my @Customer_lasts;
foreach (sort keys %Match) {
if ($Param{GetParam}->{$_} && $Param{GetParam}->{$_} =~ /$Match{$_}/i) {
$Matched = $1 || '1';
$Subject = $&;
}
else {
$MatchedNot = 1;
}
}
# should I filter incoming mail?
if ($Matched && !$MatchedNot) {
# Nr aus Subject extrahieren
if($Subject =~ /[0-9]+/)
{
$CustomerNo = $&;
# DB Abfrage nach der CustomerNo
my $connect = DBI->connect("$DB", "$User", "$Pswd"); # or die "DB Connections failed! Error:\n$DBI::errstr";
my $sql = qq{SELECT login, email, first_name, last_name FROM customer_user WHERE customer_id LIKE '$CustomerNo'};
my $result = $connect->prepare( $sql );
$Anz = $result->execute();
# Überprüfen ob Anzahl der Datensätz 0 ist
if($Anz == 0)
{
$Self->{LogObject}->Log(
Priority => 'notice',
Message => "No Data for CustomerNo:$CustomerNo!",
);
}
else
{
# 1. Kunde wird genommen und gespeichert
$i = 0;
while(@Ergebnis=$result->fetchrow_array)
{
if($i == 0)
{
push(@Customer_logins, $Ergebnis[0]);
push(@Customer_emails, $Ergebnis[1]);
push(@Customer_firsts, $Ergebnis[2]);
push(@Customer_lasts, $Ergebnis[3]);
}
$i++;
}
$result->finish();
$connect->disconnect();
# 1. Wert speichern
$CustomerLogin = pop(@Customer_logins);
$CustomerEmail = pop(@Customer_emails);
$CustomerFirstName = pop(@Customer_firsts);
$CustomerLastName = pop(@Customer_lasts);
# Log Eintrag
$Self->{LogObject}->Log(
Priority => 'notice',
Message => "Database for Subject:$Subject and CustomerNo:$CustomerNo successful queried! ($CustomerLogin, $CustomerEmail, $CustomerFirstName, $CustomerLastName)",
);
}
}
else
{
$Self->{LogObject}->Log(
Priority => 'notice',
Message => "Database for Subject:$Subject and CustomerNo:$CustomerNo could not queried!",
);
}
foreach (keys %Set) {
if ($Set{$_} =~ /\[\*\*\*\]/i) {
$Set{$_} = $Matched;
}
#$Param{GetParam}->{$_} = $Set{$_};
# X-OTRS setzen
if($_ eq "X-OTRS-CustomerUser")
{
$Param{GetParam}->{$_} = $CustomerLogin;
$Self->{LogObject}->Log(
Priority => 'notice',
Message => "Set param $_ to $CustomerLogin",
);
}
#else
#{
# $Self->{LogObject}->Log(
# Priority => 'notice',
# Message => "X-OTRS Header: $Param{GetParam}->{$_} => $CustomerLogin NICHT gesetzt!",
# );
#}
if($_ eq "From")
{
$Param{GetParam}->{$_} = "\"$CustomerFirstName $CustomerLastName\" <$CustomerEmail>";
$Self->{LogObject}->Log(
Priority => 'notice',
Message => "Set param $_ to \"$CustomerFirstName $CustomerLastName\" <$CustomerEmail>",
);
}
#else
#{
# $Self->{LogObject}->Log(
# Priority => 'notice',
# Message => "$_ to \"$CustomerFirstName $CustomerLastName\" <$CustomerEmail> NICHT gesetzt!",
# );
#}
#$Self->{LogObject}->Log(
#Priority => 'notice',
#Message => "Set param '$_' to '$Set{$_}' (Message-ID: $Param{GetParam}->{'Message-ID'}) ",
#);
}
}
return 1;
}
1;
Config.pm
Code: Select all
# Anrufbeantworter Filter!
$Self->{'PostMaster::PreFilterModule'}->{'ABFilter'} = {
Module => 'Kernel::System::PostMaster::Filter::ABFilter',
Match => {
Subject => 'Sprachmitteilung von [0-9]+',
},
Set => {
'From' => '',
'X-OTRS-CustomerUser' => '',
},
};
Wobei die ABFilter.pm unter \Kernel\System\PostMaster\Filter liegt. Die Config.pm erübrigt sich.
Es ist zwar nicht alles OTRS konform, geschweige denn sauber programmiert (auch nicht optmial gelöst, mir fehlen Perl-Kenntnisse) aber es klappt wunderbar..

(Bin kein FIA sondern FISI!!

)
Vielleicht können manche damit was anfangen!
so far...