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