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