1*cdf0e10cSrcweir#************************************************************************* 2*cdf0e10cSrcweir# 3*cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir# 5*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir# 7*cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir# 9*cdf0e10cSrcweir# This file is part of OpenOffice.org. 10*cdf0e10cSrcweir# 11*cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir# only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir# 15*cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir# 21*cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir# version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir# <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir# for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir# 26*cdf0e10cSrcweir#************************************************************************* 27*cdf0e10cSrcweir 28*cdf0e10cSrcweirpackage installer::mail; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweiruse Net::SMTP; 31*cdf0e10cSrcweiruse installer::converter; 32*cdf0e10cSrcweiruse installer::exiter; 33*cdf0e10cSrcweiruse installer::ziplist; 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir######################################### 36*cdf0e10cSrcweir# Sending a mail 37*cdf0e10cSrcweir######################################### 38*cdf0e10cSrcweir 39*cdf0e10cSrcweirsub send_mail 40*cdf0e10cSrcweir{ 41*cdf0e10cSrcweir my ($message, $listenerstring, $mailinfostring, $languagesref, $destdir) = @_; 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir my $listener = installer::converter::convert_stringlist_into_array($listenerstring, ","); 44*cdf0e10cSrcweir my $mailinfo = installer::converter::convert_stringlist_into_array($mailinfostring, ","); 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir my @listener = (); 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$listener}; $i++ ) { push(@listener, ${$listener}[$i]); } 49*cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$mailinfo}; $i++ ) { ${$mailinfo}[$i] =~ s/\s*$//g; } 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir my $smtphost = ${$mailinfo}[0]; 52*cdf0e10cSrcweir my $account = ${$mailinfo}[1]; 53*cdf0e10cSrcweir my $sender = ${$mailinfo}[2]; 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir if ( ! $smtphost ) { installer::exiter::exit_program("ERROR: Could not read SMTP Host in list file!", "send_mail"); } 56*cdf0e10cSrcweir if ( ! $account ) { installer::exiter::exit_program("ERROR: Could not read Account in list file!", "send_mail"); } 57*cdf0e10cSrcweir if ( ! $sender ) { installer::exiter::exit_program("ERROR: Could not read Sender in list file!", "send_mail"); } 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir my $subject = ""; 60*cdf0e10cSrcweir my $basestring = $installer::globals::product . " " . $installer::globals::compiler . $installer::globals::productextension . " " . $installer::globals::build. " " . $installer::globals::buildid . " " . $$languagesref . "\n"; 61*cdf0e10cSrcweir if ( $message eq "ERROR" ) { $subject = "ERROR: $basestring" } 62*cdf0e10cSrcweir if ( $message eq "SUCCESS" ) { $subject = "SUCCESS: $basestring" } 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir my @message = (); 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir my $recipient_string = join ',', @listener; 67*cdf0e10cSrcweir push(@message, "Subject: $subject"); 68*cdf0e10cSrcweir push(@message, "To: $recipient_string"); 69*cdf0e10cSrcweir push(@message, "\n"); 70*cdf0e10cSrcweir push(@message, "Located at $destdir"); 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir if ( $message eq "ERROR" ) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir for ( my $j = 0; $j <= $#installer::globals::errorlogfileinfo; $j++ ) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir my $line = $installer::globals::errorlogfileinfo[$j]; 77*cdf0e10cSrcweir $line =~ s/\s*$//g; 78*cdf0e10cSrcweir push(@message, $line); 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir for ( my $i = 0; $i <= $#message; $i++ ) { $message[$i] = $message[$i] . "\015\012"; } 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir my $smtp = Net::SMTP->new( $smtphost, Hello => $account, Debug => 0 ); 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir # set sender 87*cdf0e10cSrcweir $smtp->mail($sender); 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir # listener 90*cdf0e10cSrcweir my @good_addresses = (); 91*cdf0e10cSrcweir $smtp->recipient( @listener, { SkipBad => 1 } ); 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir # send message 94*cdf0e10cSrcweir $smtp->data(\@message); 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir # quit server 97*cdf0e10cSrcweir $smtp->quit(); 98*cdf0e10cSrcweir} 99*cdf0e10cSrcweir 100*cdf0e10cSrcweirsub send_fail_mail 101*cdf0e10cSrcweir{ 102*cdf0e10cSrcweir my ($allsettingsarrayref, $languagestringref, $errordir) = @_; 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir # sending a mail into the error board 105*cdf0e10cSrcweir my $listener = ""; 106*cdf0e10cSrcweir $listener = installer::ziplist::getinfofromziplist($allsettingsarrayref, "fail"); 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir if ( $$listener ) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir my $mailinfo = installer::ziplist::getinfofromziplist($allsettingsarrayref, "mailinfo"); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir if ( $$mailinfo ) { send_mail("ERROR", $listener, $mailinfo, $languagestringref, $errordir); } 113*cdf0e10cSrcweir else { installer::exiter::exit_program("ERROR: Could not read mailinfo in list file!", "send_fail_mail"); } 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir} 116*cdf0e10cSrcweir 117*cdf0e10cSrcweirsub send_success_mail 118*cdf0e10cSrcweir{ 119*cdf0e10cSrcweir my ($allsettingsarrayref, $languagestringref, $completeshipinstalldir) = @_; 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir # sending success mail 122*cdf0e10cSrcweir my $listener = ""; 123*cdf0e10cSrcweir $listener = installer::ziplist::getinfofromziplist($allsettingsarrayref, "success"); 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir if ( $$listener ) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir my $mailinfo = installer::ziplist::getinfofromziplist($allsettingsarrayref, "mailinfo"); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir if ( $$mailinfo ) { send_mail("SUCCESS", $listener, $mailinfo, $languagestringref, $completeshipinstalldir); } 130*cdf0e10cSrcweir else { installer::exiter::exit_program("ERROR: Could not read mailinfo in list file!", "send_success_mail"); } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir} 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir1; 137