Thread Mailheader mit Datum nach RFC 2822 erstellen: Mailheader Bearbeitung Time::localtime (15 answers)
Opened by biede at 2007-05-22 01:59

biede
 2007-05-22 01:59
#76828 #76828
User since
2007-05-17
5 Artikel
BenutzerIn
[default_avatar]
Hallo Leser dieses Beitrags!

Ich hatte letzte Woche schonmal geschireben, als ich ein Problem hatte ein "Datefield" in einen E-Mailheader einzufuegen.
Das Problem besteht leider immernoch. Ich habe jetzt schon alle Vorschläge durchprobiert und bin leider nicht zum Erfolg gekommen.

Deshalb hab ich mich entschlossen mal das gesamte Script (Auszug aus dem OTRS Ticket System der Datei Email.pm) zu posten und hoffe, das jemand meinen Fehler findet, da ich mir nach langen probieren einfach nicht sicher bin woran es liegt, dass es nicht funktioniert. Ich tippe aber in erster Linie mal, dass es an mir liegt, da ich noch keine großen Erfahrungen mit Perl gemacht hab und zugegebenermaßen auch nicht zu 100 Prozent verstehe was genau in diesem Script passiert. Meinen Eintrag habe ich mit "#####Datum" beginnend markiert, er fängt ca. bei Zeile 180 an.

Wie gesagt, es soll einfach nur ein Datumsstempel in den Mailheader eingefügt werden, da es der Entwickler dieses Scripts anscheinend vergessen hat.

Schonmal schönen dankt für die aufgebrachte Mühe mir bei meinem Problem zu helfen.

Gruß Stefan

Code: (dl )
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# --
# Kernel/System/Email.pm - the global email send module
# Copyright (C) 2001-2004 Martin Edenhofer <martin+code@otrs.org>
# --
# $Id: Email.pm,v 1.6.2.1 2004/10/07 14:11:08 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::Email;

use strict;
use MIME::Words qw(:all);
use MIME::Entity;
use Mail::Address;
use Time::localtime; #Veraenderung zum Original

use vars qw($VERSION);
$VERSION = '$Revision: 1.6.2.1 $';
$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/;

=head1 NAME

Kernel::System::Email - to send email

=head1 SYNOPSIS

Global module to send email via sendmail or SMTP.

=head1 PUBLIC INTERFACE

=over 4

=cut

=item new()

create a object

use Kernel::Config;
use Kernel::System::Log;
use Kernel::System::DB;
use Kernel::System::Email;

my $ConfigObject = Kernel::Config->new();
my $LogObject = Kernel::System::Log->new(
ConfigObject => $ConfigObject,
);
my $DBObject = Kernel::System::DB->new(
ConfigObject => $ConfigObject,
LogObject => $LogObject,
);
my $SendObject = Kernel::System::Email->new(
ConfigObject => $ConfigObject,
LogObject => $LogObject,
DBObject => $DBObject,
);

=cut

sub new {
my $Type = shift;
my %Param = @_;
# allocate new hash for object
my $Self = {};
bless ($Self, $Type);
# get common opjects
foreach (keys %Param) {
$Self->{$_} = $Param{$_};
}
# debug level
$Self->{Debug} = $Param{Debug} || 0;
# check all needed objects
foreach (qw(ConfigObject LogObject DBObject)) {
die "Got no $_" if (!$Self->{$_});
}
# load generator backend module
my $GenericModule = $Self->{ConfigObject}->Get('SendmailModule')
|| 'Kernel::System::Email::Sendmail';
if (!eval "require $GenericModule") {
die "Can't load sendmail backend module $GenericModule! $@";
}
# create backend object
$Self->{Backend} = $GenericModule->new(%Param);

$Self->{FQDN} = $Self->{ConfigObject}->Get('FQDN');
$Self->{Organization} = $Self->{ConfigObject}->Get('Organization');
$Self->{SendmailBcc} = $Self->{ConfigObject}->Get('SendmailBcc');

return $Self;
}

=item Send()

To send an email without already created header:

if ($SendObject->Send(
From => 'me@example.com',
To => 'friend@example.com',
Subject => 'Some words!',
Type => 'text/plain',
Charset => 'iso-8859-15',
Body => 'Some nice text',)) {
print "Email sent!\n";
}
else {
print "Email not sent!\n";
}

To send an email with already created header:

if ($SendObject->Send(
From => 'me@example.com',
To => 'friend@example.com',
Header => $Header,
Body => $Body,)) {
print "Email sent!\n";
}
else {
print "Email not sent!\n";
}

=cut

sub Send {
my $Self = shift;
my %Param = @_;

# check needed stuff
foreach (qw(Body)) {
if (!$Param{$_}) {
$Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
return;
}
}
if (!$Param{To} && !$Param{Cc} && !$Param{Bcc}) {
$Self->{LogObject}->Log(Priority => 'error', Message => "Need To, Cc or Bcc!");
return;
}
# check from
if (!$Param{From}) {
$Param{From} = $Self->{ConfigObject}->Get('AdminEmail') || 'otrs@localhost';
}

if (!$Param{Header}) {
my %Header = ();
foreach (qw(From To Cc Bcc Subject Organization Charset)) {
if ($Param{$_}) {
$Header{$_} = $Param{$_};
}
}
# do some encode
foreach (qw(From To Cc Bcc Subject)) {
if ($Header{$_} && $Param{Charset}) {
$Header{$_} = encode_mimewords($Header{$_}, Charset => $Param{Charset}) || '';
}
}
$Header{'X-Mailer'} = "OTRS Mail Service ($VERSION)";
$Header{'X-Powered-By'} = 'OTRS - Open Ticket Request System (http://otrs.org/)';
$Header{'Type'} = $Param{Type} || 'text/plain';
if ($Param{Charset} && $Param{Charset} =~ /utf(8|-8)/i) {
$Header{'Encoding'} = '8bit';
# $Header{'Encoding'} = 'base64';
}
else {
# $Header{'Encoding'} = '7bit';
$Header{'Encoding'} = 'quoted-printable';
}
# Veraenderung zum Original Datum in den Mailheader eingefuegt
###### Datum
my @dateArray = split(/\s+/, scalar localtime);
my $time = $dateArray[3];
my $dateYear = $dateArray[4];
my $dateMonth = $dateArray[1];
my $dateDay = $dateArray[2];
my $dateWeekday = $dateArray[0];

$Header{'Date'} = "Date: ".$dateWeekday.", ".$dateDay." ".$dateMonth." ".$dateYear." ".$time." +0200";
###### Datum Ende

$Header{'Message-ID'} = "Message-ID: <".time().".".rand(999999)."\@$Self->{FQDN}>";
my $Entity = MIME::Entity->build(%Header, Data => $Param{Body});
# get header
my $head = $Entity->head;
$Param{Header} = $head->as_string();

$Param{Body} = $Entity->body_as_string();
}
# get recipients
my $To = '';
my @ToArray = ();
foreach (qw(To Cc Bcc)) {
if ($Param{$_}) {
foreach my $Email (Mail::Address->parse($Param{$_})) {
push (@ToArray, $Email->address());
if ($To) {
$To .= ', ';
}
$To .= $Email->address();
}
}
}
if ($Self->{SendmailBcc}) {
push (@ToArray, $Self->{SendmailBcc});
$To .= ", $Self->{SendmailBcc}";
}

# get sender
my @Sender = Mail::Address->parse($Param{From});
my $RealFrom = $Sender[0]->address();

# debug
if ($Self->{Debug} > 1) {
$Self->{LogObject}->Log(
Priority => 'notice',
Message => "Sent email to '$To' from '$RealFrom'. ".
"Subject => $Param{Subject};",
);
}

return $Self->{Backend}->Send(
From => $RealFrom,
To => $To,
ToArray => \@ToArray,
Header => \$Param{Header},
Body => \$Param{Body},
);
}

1;

=head1 TERMS AND CONDITIONS

This software is part of the OTRS project (http://otrs.org/).

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.

=cut

=head1 VERSION

$Revision: 1.6.2.1 $ $Date: 2004/10/07 14:11:08 $

=cut

View full thread Mailheader mit Datum nach RFC 2822 erstellen: Mailheader Bearbeitung Time::localtime