xref: /aoo41x/main/solenv/bin/modules/installer/mail.pm (revision 9780544f)
1*9780544fSAndrew Rist#**************************************************************
2*9780544fSAndrew Rist#
3*9780544fSAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
4*9780544fSAndrew Rist#  or more contributor license agreements.  See the NOTICE file
5*9780544fSAndrew Rist#  distributed with this work for additional information
6*9780544fSAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
7*9780544fSAndrew Rist#  to you under the Apache License, Version 2.0 (the
8*9780544fSAndrew Rist#  "License"); you may not use this file except in compliance
9*9780544fSAndrew Rist#  with the License.  You may obtain a copy of the License at
10*9780544fSAndrew Rist#
11*9780544fSAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
12*9780544fSAndrew Rist#
13*9780544fSAndrew Rist#  Unless required by applicable law or agreed to in writing,
14*9780544fSAndrew Rist#  software distributed under the License is distributed on an
15*9780544fSAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9780544fSAndrew Rist#  KIND, either express or implied.  See the License for the
17*9780544fSAndrew Rist#  specific language governing permissions and limitations
18*9780544fSAndrew Rist#  under the License.
19*9780544fSAndrew Rist#
20*9780544fSAndrew Rist#**************************************************************
21*9780544fSAndrew Rist
22*9780544fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweirpackage installer::mail;
25cdf0e10cSrcweir
26cdf0e10cSrcweiruse Net::SMTP;
27cdf0e10cSrcweiruse installer::converter;
28cdf0e10cSrcweiruse installer::exiter;
29cdf0e10cSrcweiruse installer::ziplist;
30cdf0e10cSrcweir
31cdf0e10cSrcweir#########################################
32cdf0e10cSrcweir# Sending a mail
33cdf0e10cSrcweir#########################################
34cdf0e10cSrcweir
35cdf0e10cSrcweirsub send_mail
36cdf0e10cSrcweir{
37cdf0e10cSrcweir	my ($message, $listenerstring, $mailinfostring, $languagesref, $destdir) = @_;
38cdf0e10cSrcweir
39cdf0e10cSrcweir	my $listener = installer::converter::convert_stringlist_into_array($listenerstring, ",");
40cdf0e10cSrcweir	my $mailinfo = installer::converter::convert_stringlist_into_array($mailinfostring, ",");
41cdf0e10cSrcweir
42cdf0e10cSrcweir	my @listener = ();
43cdf0e10cSrcweir
44cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$listener}; $i++ ) { push(@listener, ${$listener}[$i]); }
45cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$mailinfo}; $i++ ) { ${$mailinfo}[$i] =~ s/\s*$//g; }
46cdf0e10cSrcweir
47cdf0e10cSrcweir	my $smtphost = ${$mailinfo}[0];
48cdf0e10cSrcweir	my $account = ${$mailinfo}[1];
49cdf0e10cSrcweir	my $sender = ${$mailinfo}[2];
50cdf0e10cSrcweir
51cdf0e10cSrcweir	if ( ! $smtphost ) { installer::exiter::exit_program("ERROR: Could not read SMTP Host in list file!", "send_mail"); }
52cdf0e10cSrcweir	if ( ! $account ) { installer::exiter::exit_program("ERROR: Could not read Account in list file!", "send_mail"); }
53cdf0e10cSrcweir	if ( ! $sender ) { installer::exiter::exit_program("ERROR: Could not read Sender in list file!", "send_mail"); }
54cdf0e10cSrcweir
55cdf0e10cSrcweir	my $subject = "";
56cdf0e10cSrcweir	my $basestring = $installer::globals::product . " " . $installer::globals::compiler . $installer::globals::productextension . " " . $installer::globals::build. " " . $installer::globals::buildid . " " . $$languagesref . "\n";
57cdf0e10cSrcweir	if ( $message eq "ERROR" ) { $subject = "ERROR: $basestring" }
58cdf0e10cSrcweir	if ( $message eq "SUCCESS" ) { $subject = "SUCCESS: $basestring" }
59cdf0e10cSrcweir
60cdf0e10cSrcweir	my @message = ();
61cdf0e10cSrcweir
62cdf0e10cSrcweir	my $recipient_string = join ',', @listener;
63cdf0e10cSrcweir	push(@message, "Subject: $subject");
64cdf0e10cSrcweir	push(@message, "To: $recipient_string");
65cdf0e10cSrcweir	push(@message, "\n");
66cdf0e10cSrcweir	push(@message, "Located at $destdir");
67cdf0e10cSrcweir
68cdf0e10cSrcweir	if ( $message eq "ERROR" )
69cdf0e10cSrcweir	{
70cdf0e10cSrcweir		for ( my $j = 0; $j <= $#installer::globals::errorlogfileinfo; $j++ )
71cdf0e10cSrcweir		{
72cdf0e10cSrcweir			my $line = $installer::globals::errorlogfileinfo[$j];
73cdf0e10cSrcweir			$line =~ s/\s*$//g;
74cdf0e10cSrcweir			push(@message, $line);
75cdf0e10cSrcweir		}
76cdf0e10cSrcweir	}
77cdf0e10cSrcweir
78cdf0e10cSrcweir	for ( my $i = 0; $i <= $#message; $i++ ) { $message[$i] = $message[$i] . "\015\012"; }
79cdf0e10cSrcweir
80cdf0e10cSrcweir	my $smtp = Net::SMTP->new( $smtphost, Hello => $account, Debug => 0 );
81cdf0e10cSrcweir
82cdf0e10cSrcweir	# set sender
83cdf0e10cSrcweir	$smtp->mail($sender);
84cdf0e10cSrcweir
85cdf0e10cSrcweir	# listener
86cdf0e10cSrcweir	my @good_addresses = ();
87cdf0e10cSrcweir	$smtp->recipient( @listener, { SkipBad => 1 } );
88cdf0e10cSrcweir
89cdf0e10cSrcweir	# send message
90cdf0e10cSrcweir	$smtp->data(\@message);
91cdf0e10cSrcweir
92cdf0e10cSrcweir	# quit server
93cdf0e10cSrcweir	$smtp->quit();
94cdf0e10cSrcweir}
95cdf0e10cSrcweir
96cdf0e10cSrcweirsub send_fail_mail
97cdf0e10cSrcweir{
98cdf0e10cSrcweir	my ($allsettingsarrayref, $languagestringref, $errordir) = @_;
99cdf0e10cSrcweir
100cdf0e10cSrcweir	# sending a mail into the error board
101cdf0e10cSrcweir	my $listener = "";
102cdf0e10cSrcweir	$listener = installer::ziplist::getinfofromziplist($allsettingsarrayref, "fail");
103cdf0e10cSrcweir
104cdf0e10cSrcweir	if ( $$listener )
105cdf0e10cSrcweir	{
106cdf0e10cSrcweir		my $mailinfo = installer::ziplist::getinfofromziplist($allsettingsarrayref, "mailinfo");
107cdf0e10cSrcweir
108cdf0e10cSrcweir		if ( $$mailinfo ) { send_mail("ERROR", $listener, $mailinfo, $languagestringref, $errordir); }
109cdf0e10cSrcweir		else { installer::exiter::exit_program("ERROR: Could not read mailinfo in list file!", "send_fail_mail"); }
110cdf0e10cSrcweir    }
111cdf0e10cSrcweir}
112cdf0e10cSrcweir
113cdf0e10cSrcweirsub send_success_mail
114cdf0e10cSrcweir{
115cdf0e10cSrcweir	my ($allsettingsarrayref, $languagestringref, $completeshipinstalldir) = @_;
116cdf0e10cSrcweir
117cdf0e10cSrcweir	# sending success mail
118cdf0e10cSrcweir	my $listener = "";
119cdf0e10cSrcweir	$listener = installer::ziplist::getinfofromziplist($allsettingsarrayref, "success");
120cdf0e10cSrcweir
121cdf0e10cSrcweir	if ( $$listener )
122cdf0e10cSrcweir	{
123cdf0e10cSrcweir		my $mailinfo = installer::ziplist::getinfofromziplist($allsettingsarrayref, "mailinfo");
124cdf0e10cSrcweir
125cdf0e10cSrcweir		if ( $$mailinfo ) { send_mail("SUCCESS", $listener, $mailinfo, $languagestringref, $completeshipinstalldir); }
126cdf0e10cSrcweir		else { installer::exiter::exit_program("ERROR: Could not read mailinfo in list file!", "send_success_mail"); }
127cdf0e10cSrcweir
128cdf0e10cSrcweir	}
129cdf0e10cSrcweir}
130cdf0e10cSrcweir
131cdf0e10cSrcweir
132cdf0e10cSrcweir1;
133