/usr/share/otrs/Kernel/System/Email.pm is in otrs2 3.3.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 | # --
# Kernel/System/Email.pm - the global email send module
# Copyright (C) 2001-2014 OTRS AG, http://otrs.com/
# --
# 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::Email;
## nofilter(TidyAll::Plugin::OTRS::Perl::Require)
use strict;
use warnings;
use MIME::Entity;
use Mail::Address;
use Kernel::System::Crypt;
use Kernel::System::HTMLUtils;
=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 an object
use Kernel::Config;
use Kernel::System::Encode;
use Kernel::System::Log;
use Kernel::System::Main;
use Kernel::System::Time;
use Kernel::System::DB;
use Kernel::System::Email;
my $ConfigObject = Kernel::Config->new();
my $EncodeObject = Kernel::System::Encode->new(
ConfigObject => $ConfigObject,
);
my $LogObject = Kernel::System::Log->new(
ConfigObject => $ConfigObject,
EncodeObject => $EncodeObject,
);
my $MainObject = Kernel::System::Main->new(
ConfigObject => $ConfigObject,
EncodeObject => $EncodeObject,
LogObject => $LogObject,
);
my $TimeObject = Kernel::System::Time->new(
ConfigObject => $ConfigObject,
LogObject => $LogObject,
);
my $DBObject = Kernel::System::DB->new(
ConfigObject => $ConfigObject,
EncodeObject => $EncodeObject,
LogObject => $LogObject,
MainObject => $MainObject,
);
my $SendObject = Kernel::System::Email->new(
ConfigObject => $ConfigObject,
LogObject => $LogObject,
DBObject => $DBObject,
MainObject => $MainObject,
TimeObject => $TimeObject,
EncodeObject => $EncodeObject,
);
=cut
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {%Param};
bless( $Self, $Type );
# debug level
$Self->{Debug} = $Param{Debug} || 0;
# check all needed objects
for (qw(ConfigObject LogObject DBObject TimeObject MainObject EncodeObject)) {
die "Got no $_" if !$Self->{$_};
}
# load generator backend module
my $GenericModule = $Self->{ConfigObject}->Get('SendmailModule')
|| 'Kernel::System::Email::Sendmail';
return if !$Self->{MainObject}->Require($GenericModule);
# create backend object
$Self->{Backend} = $GenericModule->new( %{$Self} );
$Self->{HTMLUtilsObject} = Kernel::System::HTMLUtils->new( %{$Self} );
return $Self;
}
=item Send()
To send an email without already created header:
my $Sent = $SendObject->Send(
From => 'me@example.com',
To => 'friend@example.com',
Cc => 'Some Customer B <customer-b@example.com>', # not required
ReplyTo => 'Some Customer B <customer-b@example.com>', # not required, is possible to use 'Reply-To' instead
Subject => 'Some words!',
Charset => 'iso-8859-15',
MimeType => 'text/plain', # "text/plain" or "text/html"
Body => 'Some nice text',
InReplyTo => '<somemessageid-2@example.com>',
References => '<somemessageid-1@example.com> <somemessageid-2@example.com>',
Loop => 1, # not required, removes smtp from
Attachment => [
{
Filename => "somefile.csv",
Content => $ContentCSV,
ContentType => "text/csv",
},
{
Filename => "somefile.png",
Content => $ContentPNG,
ContentType => "image/png",
}
],
Sign => {
Type => 'PGP',
SubType => 'Inline|Detached',
Key => '81877F5E',
Type => 'SMIME',
Key => '3b630c80',
},
Crypt => {
Type => 'PGP',
SubType => 'Inline|Detached',
Key => '81877F5E',
Type => 'SMIME',
Key => '3b630c80',
},
);
if ($Sent) {
print "Email sent!\n";
}
else {
print "Email not sent!\n";
}
=cut
sub Send {
my ( $Self, %Param ) = @_;
# check needed stuff
for (qw(Body Charset)) {
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';
}
# replace all br tags with br tags with a space to show newlines in Lotus Notes
if ( $Param{MimeType} && lc $Param{MimeType} eq 'text/html' ) {
$Param{Body} =~ s{\Q<br/>\E}{<br />}xmsgi;
}
# map ReplyTo into Reply-To if present
if ( $Param{ReplyTo} ) {
$Param{'Reply-To'} = $Param{ReplyTo};
}
# get sign options for inline
if ( $Param{Sign} && $Param{Sign}->{SubType} && $Param{Sign}->{SubType} eq 'Inline' ) {
my $CryptObject = Kernel::System::Crypt->new(
LogObject => $Self->{LogObject},
DBObject => $Self->{DBObject},
ConfigObject => $Self->{ConfigObject},
EncodeObject => $Self->{EncodeObject},
CryptType => $Param{Sign}->{Type},
MainObject => $Self->{MainObject},
);
if ( !$CryptObject ) {
return;
}
my $Body = $CryptObject->Sign(
Message => $Param{Body},
Key => $Param{Sign}->{Key},
Type => 'Clearsign',
Charset => $Param{Charset},
);
if ($Body) {
$Param{Body} = $Body;
}
}
# crypt inline
if ( $Param{Crypt} && $Param{Crypt}->{Type} eq 'PGP' && $Param{Crypt}->{SubType} eq 'Inline' ) {
my $CryptObject = Kernel::System::Crypt->new(
LogObject => $Self->{LogObject},
DBObject => $Self->{DBObject},
ConfigObject => $Self->{ConfigObject},
EncodeObject => $Self->{EncodeObject},
CryptType => $Param{Crypt}->{Type},
MainObject => $Self->{MainObject},
);
if ( !$CryptObject ) {
$Self->{LogObject}->Log(
Message => 'Not possible to create crypt object',
Priority => 'error',
);
return;
}
my $Body = $CryptObject->Crypt(
Message => $Param{Body},
Key => $Param{Crypt}->{Key},
Type => $Param{Crypt}->{SubType},
);
if ($Body) {
$Param{Body} = $Body;
}
}
# build header
my %Header;
for (qw(From To Cc Subject Charset Reply-To)) {
next if !$Param{$_};
$Header{$_} = $Param{$_};
}
# loop
if ( $Param{Loop} ) {
$Header{'X-Loop'} = 'yes';
$Header{'Precedence:'} = 'bulk';
$Header{'Auto-Submitted:'} = "auto-generated";
}
# do some encode
for (qw(From To Cc Subject)) {
next if !$Header{$_};
$Header{$_} = $Self->_EncodeMIMEWords(
Field => $_,
Line => $Header{$_},
Charset => $Param{Charset},
);
}
# check if it's html, add text attachment
my $HTMLEmail = 0;
if ( $Param{MimeType} && $Param{MimeType} =~ /html/i ) {
$HTMLEmail = 1;
# add html as first attachment
my $Attach = {
Content => $Param{Body},
ContentType => "text/html; charset=\"$Param{Charset}\"",
Filename => '',
};
if ( !$Param{Attachment} ) {
@{ $Param{Attachment} } = ($Attach);
}
else {
@{ $Param{Attachment} } = ( $Attach, @{ $Param{Attachment} } );
}
# remember html body for later comparison
$Param{HTMLBody} = $Param{Body};
# add ascii body
$Param{MimeType} = 'text/plain';
$Param{Body} = $Self->{HTMLUtilsObject}->ToAscii(
String => $Param{Body},
);
}
my $Product = $Self->{ConfigObject}->Get('Product');
my $Version = $Self->{ConfigObject}->Get('Version');
if ( !$Self->{ConfigObject}->Get('Secure::DisableBanner') ) {
$Header{'X-Mailer'} = "$Product Mail Service ($Version)";
$Header{'X-Powered-By'} = 'OTRS - Open Ticket Request System (http://otrs.org/)';
}
$Header{Type} = $Param{MimeType} || 'text/plain';
# define email encoding
if ( $Param{Charset} && $Param{Charset} =~ /^iso/i ) {
$Header{Encoding} = '8bit';
}
else {
$Header{Encoding} = 'quoted-printable';
}
# check if we need to force the encoding
if ( $Self->{ConfigObject}->Get('SendmailEncodingForce') ) {
$Header{Encoding} = $Self->{ConfigObject}->Get('SendmailEncodingForce');
}
# check and create message id
if ( $Param{'Message-ID'} ) {
$Header{'Message-ID'} = $Param{'Message-ID'};
}
else {
$Header{'Message-ID'} = $Self->_MessageIDCreate();
}
# add date header
$Header{Date} = 'Date: ' . $Self->{TimeObject}->MailTimeStamp();
# add organisation header
my $Organization = $Self->{ConfigObject}->Get('Organization');
if ($Organization) {
$Header{Organization} = $Self->_EncodeMIMEWords(
Field => 'Organization',
Line => $Organization,
Charset => $Param{Charset},
);
}
# build MIME::Entity, Data should be bytes, not utf-8
# see http://bugs.otrs.org/show_bug.cgi?id=9832
$Self->{EncodeObject}->EncodeOutput( \$Param{Body} );
my $Entity = MIME::Entity->build( %Header, Data => $Param{Body} );
# set In-Reply-To and References header
my $Header = $Entity->head();
if ( $Param{InReplyTo} ) {
$Param{'In-Reply-To'} = $Param{InReplyTo};
}
for my $Key ( 'In-Reply-To', 'References' ) {
next if !$Param{$Key};
my $Value = $Param{$Key};
# Split up '<msgid><msgid>' to allow line folding (see bug#9345).
$Value =~ s{><}{> <}xmsg;
$Header->replace( $Key, $Value );
}
# add attachments to email
if ( $Param{Attachment} ) {
my $Count = 0;
my $PartType = '';
my @NewAttachments;
ATTACHMENT:
for my $Upload ( @{ $Param{Attachment} } ) {
# ignore attachment if no content is given
next ATTACHMENT if !defined $Upload->{Content};
# ignore attachment if no filename is given
next ATTACHMENT if !defined $Upload->{Filename};
# prepare ContentType for Entity Type. $Upload->{ContentType} has
# useless `name` parameter, we don't need to send it to the `attach`
# constructor. For more details see Bug #7879 and MIME::Entity.
# Note: we should remove `name` attribute only.
my @ContentTypeTmp = grep { !/\s*name=/ } ( split /;/, $Upload->{ContentType} );
$Upload->{ContentType} = join ';', @ContentTypeTmp;
# if it's a html email, add the first attachment as alternative (to show it
# as alternative content)
if ($HTMLEmail) {
$Count++;
if ( $Count == 1 ) {
$Entity->make_multipart('alternative;');
$PartType = 'alternative';
}
else {
# don't attach duplicate html attachment (aka file-2)
next ATTACHMENT if
$Upload->{Filename} eq 'file-2'
&& $Upload->{ContentType} =~ /html/i
&& $Upload->{Content} eq $Param{HTMLBody};
# skip, but remember all attachments except inline images
if ( !defined $Upload->{ContentID} ) {
push @NewAttachments, \%{$Upload};
next ATTACHMENT;
}
# add inline images as related
if ( $PartType ne 'related' ) {
$Entity->make_multipart( 'related;', Force => 1, );
$PartType = 'related';
}
}
}
# content encode
$Self->{EncodeObject}->EncodeOutput( \$Upload->{Content} );
# filename encode
my $Filename = $Self->_EncodeMIMEWords(
Field => 'filename',
Line => $Upload->{Filename},
Charset => $Param{Charset},
);
# format content id, leave undefined if no value
my $ContentID = $Upload->{ContentID};
if ( $ContentID && $ContentID !~ /^</ ) {
$ContentID = '<' . $ContentID . '>';
}
# attach file to email
$Entity->attach(
Filename => $Filename,
Data => $Upload->{Content},
Type => $Upload->{ContentType},
Id => $ContentID,
Disposition => $Upload->{Disposition} || 'inline',
Encoding => $Upload->{Encoding} || '-SUGGEST',
);
}
# add all other attachments as multipart mixed (if we had html body)
for my $Upload (@NewAttachments) {
# make multipart mixed
if ( $PartType ne 'mixed' ) {
$Entity->make_multipart( 'mixed;', Force => 1, );
$PartType = 'mixed';
}
# content encode
$Self->{EncodeObject}->EncodeOutput( \$Upload->{Content} );
# filename encode
my $Filename = $Self->_EncodeMIMEWords(
Field => 'filename',
Line => $Upload->{Filename},
Charset => $Param{Charset},
);
# attach file to email (no content id needed)
$Entity->attach(
Filename => $Filename,
Data => $Upload->{Content},
Type => $Upload->{ContentType},
Disposition => $Upload->{Disposition} || 'inline',
Encoding => $Upload->{Encoding} || '-SUGGEST',
);
}
}
# get sign options for detached
if ( $Param{Sign} && $Param{Sign}->{SubType} && $Param{Sign}->{SubType} eq 'Detached' ) {
my $CryptObject = Kernel::System::Crypt->new(
LogObject => $Self->{LogObject},
DBObject => $Self->{DBObject},
ConfigObject => $Self->{ConfigObject},
EncodeObject => $Self->{EncodeObject},
MainObject => $Self->{MainObject},
CryptType => $Param{Sign}->{Type},
);
if ( !$CryptObject ) {
$Self->{LogObject}->Log(
Message => 'Not possible to create crypt object',
Priority => 'error',
);
return;
}
if ( $Param{Sign}->{Type} eq 'PGP' ) {
# make_multipart -=> one attachment for sign
$Entity->make_multipart(
"signed; micalg=pgp-sha1; protocol=\"application/pgp-signature\";",
Force => 1,
);
# get string to sign
my $T = $Entity->parts(0)->as_string();
# according to RFC3156 all line endings MUST be CR/LF
$T =~ s/\x0A/\x0D\x0A/g;
$T =~ s/\x0D+/\x0D/g;
my $Sign = $CryptObject->Sign(
Message => $T,
Key => $Param{Sign}->{Key},
Type => 'Detached',
Charset => $Param{Charset},
);
# it sign failed, remove singned multi part
if ( !$Sign ) {
$Entity->make_singlepart();
}
else {
# addach sign to email
$Entity->attach(
Filename => 'pgp_sign.asc',
Data => $Sign,
Type => 'application/pgp-signature',
Encoding => '7bit',
);
}
}
elsif ( $Param{Sign}->{Type} eq 'SMIME' ) {
# make multi part
my $EntityCopy = $Entity->dup();
$EntityCopy->make_multipart( 'mixed;', Force => 1, );
# get header to remember
my $Head = $EntityCopy->head();
$Head->delete('MIME-Version');
$Head->delete('Content-Type');
$Head->delete('Content-Disposition');
$Head->delete('Content-Transfer-Encoding');
my $Header = $Head->as_string();
# get string to sign
my $T = $EntityCopy->parts(0)->as_string();
# according to RFC3156 all line endings MUST be CR/LF
$T =~ s/\x0A/\x0D\x0A/g;
$T =~ s/\x0D+/\x0D/g;
# remove empty line after multi-part preable as it will be removed later by MIME::Parser
# otherwise signed content will be different than the actual mail and verify will
# fail
$T =~ s{(This is a multi-part message in MIME format...\r\n)\r\n}{$1};
my $Sign = $CryptObject->Sign(
Message => $T,
Filename => $Param{Sign}->{Key},
Type => 'Detached',
);
if ($Sign) {
use MIME::Parser;
my $Parser = MIME::Parser->new();
$Parser->output_to_core('ALL');
$Parser->output_dir( $Self->{ConfigObject}->Get('TempDir') );
$Entity = $Parser->parse_data( $Header . $Sign );
}
}
}
# crypt detached!
#my $NotCryptedBody = $Entity->body_as_string();
if (
$Param{Crypt}
&& $Param{Crypt}->{Type}
&& $Param{Crypt}->{Type} eq 'PGP'
&& $Param{Crypt}->{SubType} eq 'Detached'
)
{
my $CryptObject = Kernel::System::Crypt->new(
LogObject => $Self->{LogObject},
DBObject => $Self->{DBObject},
ConfigObject => $Self->{ConfigObject},
EncodeObject => $Self->{EncodeObject},
MainObject => $Self->{MainObject},
CryptType => $Param{Crypt}->{Type},
);
return if !$CryptObject;
# make_multipart -=> one attachment for encryption
$Entity->make_multipart(
"encrypted; protocol=\"application/pgp-encrypted\";",
Force => 1,
);
# crypt it
my $Crypt = $CryptObject->Crypt(
Message => $Entity->parts(0)->as_string(),
# Key => '81877F5E',
# Key => '488A0B8F',
Key => $Param{Crypt}->{Key},
);
# it crypt failed, remove encrypted multi part
if ( !$Crypt ) {
$Entity->make_singlepart();
}
else {
# eliminate all parts
$Entity->parts( [] );
# add crypted parts
$Entity->attach(
Type => 'application/pgp-encrypted',
Disposition => 'attachment',
Data => [ "Version: 1", "" ],
Encoding => '7bit',
);
$Entity->attach(
Type => 'application/octet-stream',
Disposition => 'inline',
Filename => 'msg.asc',
Data => $Crypt,
Encoding => '7bit',
);
}
}
elsif ( $Param{Crypt} && $Param{Crypt}->{Type} && $Param{Crypt}->{Type} eq 'SMIME' ) {
my $CryptObject = Kernel::System::Crypt->new(
LogObject => $Self->{LogObject},
DBObject => $Self->{DBObject},
ConfigObject => $Self->{ConfigObject},
EncodeObject => $Self->{EncodeObject},
MainObject => $Self->{MainObject},
CryptType => $Param{Crypt}->{Type},
);
if ( !$CryptObject ) {
$Self->{LogObject}->Log(
Message => 'Failed creation of crypt object',
Priority => 'error',
);
return;
}
# make_multipart -=> one attachment for encryption
$Entity->make_multipart( 'mixed;', Force => 1, );
# get header to remember
my $Head = $Entity->head();
$Head->delete('MIME-Version');
$Head->delete('Content-Type');
$Head->delete('Content-Disposition');
$Head->delete('Content-Transfer-Encoding');
my $Header = $Head->as_string();
my $T = $Entity->parts(0)->as_string();
# according to RFC3156 all line endings MUST be CR/LF
$T =~ s/\x0A/\x0D\x0A/g;
$T =~ s/\x0D+/\x0D/g;
# crypt it
my $Crypt = $CryptObject->Crypt(
Message => $T,
Filename => $Param{Crypt}->{Key},
);
use MIME::Parser;
my $Parser = MIME::Parser->new();
$Parser->output_dir( $Self->{ConfigObject}->Get('TempDir') );
$Entity = $Parser->parse_data( $Header . $Crypt );
}
# get header from Entity
my $Head = $Entity->head();
$Param{Header} = $Head->as_string();
# remove not needed folding of email heads, we do have many problems with email clients
my @Headers = split( /\n/, $Param{Header} );
# reset orig header
$Param{Header} = '';
for my $Line (@Headers) {
$Line =~ s/^ (.*)$/ $1/;
$Param{Header} .= $Line . "\n";
}
# get body from Entity
$Param{Body} = $Entity->body_as_string();
# get recipients
my @ToArray;
my $To = '';
for (qw(To Cc Bcc)) {
next if !$Param{$_};
for my $Email ( Mail::Address->parse( $Param{$_} ) ) {
push( @ToArray, $Email->address() );
if ($To) {
$To .= ', ';
}
$To .= $Email->address();
}
}
# add Bcc recipients
my $SendmailBcc = $Self->{ConfigObject}->Get('SendmailBcc');
if ($SendmailBcc) {
push @ToArray, $SendmailBcc;
$To .= ', ' . $SendmailBcc;
}
# set envelope sender for replies
my $RealFrom = $Self->{ConfigObject}->Get('SendmailEnvelopeFrom') || '';
if ( !$RealFrom ) {
my @Sender = Mail::Address->parse( $Param{From} );
$RealFrom = $Sender[0]->address();
}
# set envelope sender for autoresponses and notifications
if ( $Param{Loop} ) {
$RealFrom = $Self->{ConfigObject}->Get('SendmailNotificationEnvelopeFrom') || '';
}
# debug
if ( $Self->{Debug} > 1 ) {
$Self->{LogObject}->Log(
Priority => 'notice',
Message => "Sent email to '$To' from '$RealFrom'. Subject => '$Param{Subject}';",
);
}
# send email to backend
my $Sent = $Self->{Backend}->Send(
From => $RealFrom,
ToArray => \@ToArray,
Header => \$Param{Header},
Body => \$Param{Body},
);
if ( !$Sent ) {
$Self->{LogObject}->Log(
Message => "Error sending message",
Priority => 'info',
);
return;
}
return ( \$Param{Header}, \$Param{Body} );
}
=item Check()
Check mail configuration
my %Check = $SendObject->Check();
=cut
sub Check {
my ( $Self, %Param ) = @_;
my %Check = $Self->{Backend}->Check();
if ( $Check{Successful} ) {
return ( Successful => 1 )
}
else {
return ( Successful => 0, Message => $Check{Message} );
}
}
=item Bounce()
Bounce an email
$SendObject->Bounce(
From => 'me@example.com',
To => 'friend@example.com',
Email => $Email,
);
=cut
sub Bounce {
my ( $Self, %Param ) = @_;
# check needed stuff
for (qw(From To Email)) {
if ( !$Param{$_} ) {
$Self->{LogObject}->Log( Priority => 'error', Message => "Need $_!" );
return;
}
}
# check and create message id
my $MessageID = '';
if ( $Param{'Message-ID'} ) {
$MessageID = $Param{'Message-ID'};
}
else {
$MessageID = $Self->_MessageIDCreate();
}
# split body && header
my @EmailPlain = split( /\n/, $Param{Email} );
my $EmailObject = new Mail::Internet( \@EmailPlain );
# get sender
my @Sender = Mail::Address->parse( $Param{From} );
my $RealFrom = $Sender[0]->address();
# add ReSent header
my $HeaderObject = $EmailObject->head();
my $OldMessageID = $HeaderObject->get('Message-ID') || '??';
$HeaderObject->replace( 'Message-ID', $MessageID );
$HeaderObject->replace( 'ReSent-Message-ID', $OldMessageID );
$HeaderObject->replace( 'Resent-To', $Param{To} );
$HeaderObject->replace( 'Resent-From', $RealFrom );
my $Body = $EmailObject->body();
my $BodyAsString = '';
for ( @{$Body} ) {
$BodyAsString .= $_ . "\n";
}
my $HeaderAsString = $HeaderObject->as_string();
# debug
if ( $Self->{Debug} > 1 ) {
$Self->{LogObject}->Log(
Priority => 'notice',
Message => "Bounced email to '$Param{To}' from '$RealFrom'. "
. "MessageID => '$OldMessageID';",
);
}
my $Sent = $Self->{Backend}->Send(
From => $RealFrom,
ToArray => [ $Param{To} ],
Header => \$HeaderAsString,
Body => \$BodyAsString,
);
return if !$Sent;
return ( \$HeaderAsString, \$BodyAsString );
}
=begin Internal:
=cut
sub _EncodeMIMEWords {
my ( $Self, %Param ) = @_;
# return if no content is given
return '' if !defined $Param{Line};
# check if MIME::EncWords is installed
if ( eval { require MIME::EncWords } ) { ## no critic
return MIME::EncWords::encode_mimewords(
Encode::encode(
$Param{Charset},
$Param{Line},
),
Charset => $Param{Charset},
# use 'a' for quoted printable or base64 choice automatically
Encoding => 'a',
# for line length calculation to fold lines
Field => $Param{Field},
);
}
# as fallback use MIME::Words of MIME::Tools (but it lakes on some utf8
# issues, see pod of MIME::Words)
else {
require MIME::Words; ## no critic
return MIME::Words::encode_mimewords(
Encode::encode(
$Param{Charset},
$Param{Line},
),
Charset => $Param{Charset},
# for line length calculation to fold lines (gets ignored by
# MIME::Words, see pod of MIME::Words)
Field => $Param{Field},
);
}
}
sub _MessageIDCreate {
my ( $Self, %Param ) = @_;
my $FQDN = $Self->{ConfigObject}->Get('FQDN');
return 'Message-ID: <' . time() . '.' . rand(999999) . '@' . $FQDN . '>';
}
1;
=end Internal:
=back
=head1 TERMS AND CONDITIONS
This software is part of the OTRS project (L<http://otrs.org/>).
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 L<http://www.gnu.org/licenses/agpl.txt>.
=cut
|