File: CMD.pm

package info (click to toggle)
otrs2 2.0.4p01-18
  • links: PTS
  • area: main
  • in suites: etch
  • size: 7,900 kB
  • ctags: 4,437
  • sloc: perl: 81,607; xml: 8,135; sql: 8,013; sh: 1,113; makefile: 22; php: 16
file content (82 lines) | stat: -rw-r--r-- 2,185 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# --
# Kernel/System/PostMaster/Filter/CMD.pm - sub part of PostMaster.pm
# Copyright (C) 2001-2003 Martin Edenhofer <martin+code@otrs.org>
# --
# $Id: CMD.pm,v 1.1 2003/11/01 19:50:11 martin Exp $
# --
# 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::CMD;

use strict;

use vars qw($VERSION);
$VERSION = '$Revision: 1.1 $';
$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 opbjects
    foreach (qw(ConfigObject LogObject DBObject ParseObject)) {
        $Self->{$_} = $Param{$_} || die "Got no $_!";
    }

    return $Self;
}
# --
sub Run {
    my $Self = shift;
    my %Param = @_;
    # get config options
    my %Config = ();
    my %Set = ();
    if ($Param{JobConfig} && ref($Param{JobConfig}) eq 'HASH') {
        %Config = %{$Param{JobConfig}}; 
        if ($Config{Set}) {
            %Set = %{$Config{Set}};
        }
    }
    # check CMD config param
    if (!$Config{CMD}) {
        $Self->{LogObject}->Log(
            Priority => 'error',
            Message => "Need CMD config option in PostMaster::PreFilterModule job!",
        );
        return;
    }
    # execute prog
    my $TmpFile = $Self->{ConfigObject}->Get('TempDir')."/PostMaster.Filter.CMD.$$";
    if (open(PROG, "|$Config{CMD} > $TmpFile")) {
        print PROG $Self->{ParseObject}->GetPlainEmail();
        close (PROG);
    }
    if (-s $TmpFile) {
        open(IN, "< $TmpFile");
        my $Ret = <IN>;
        close (IN);
        # set new params
        foreach (keys %Set) {
           $Param{GetParam}->{$_} = $Set{$_};
           $Self->{LogObject}->Log(
               Priority => 'notice',
               Message => "Set param '$_' to '$Set{$_}' because of '$Ret' (Message-ID: $Param{GetParam}->{'Message-ID'}) ",
           );
        }
    }
    unlink $TmpFile;
    return 1; 
}
# --
1;