Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[r1390]: branches / 2.5.4RC1 / cgi-bin / yabb2 / Sources / Mailer.pm Maximize Restore History

Download this file

Mailer.pm    179 lines (161 with data), 7.1 kB

  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
###############################################################################
# Mailer.pm #
# $Date: 11.08.13 $ #
###############################################################################
# YaBB: Yet another Bulletin Board #
# Open-Source Community Software for Webmasters #
# Version: YaBB 2.5.41 #
# Packaged: September 1, 2013 #
# Distributed by: http://www.yabbforum.com #
# =========================================================================== #
# Copyright (c) 2000-2013 YaBB (www.yabbforum.com) - All Rights Reserved. #
# Software by: The YaBB Development Team #
# with assistance from the YaBB community. #
###############################################################################
use CGI::Carp qw(fatalsToBrowser);
use English '-no_match_vars';
our $VERSION = '2.5.41';
$mailerpmver = 'YaBB 2.5.4 RC1 $Revision: 1390 $';
if ( $action eq 'detailedversion' ) { return 1; }
sub sendmail {
my ( $to, $subject, $message, $from, $mailcharset ) = @_;
# Do a FromHTML here for $to, and for $mbname
# Just in case has special chars like & in addresses
FromHTML($to);
FromHTML($mbname);
# Change commas to HTML entity - ToHTML doesn't catch this
# It's only a problem when sending emails, so no change to ToHTML.
# Changed to dash -  misread in mail clients that use semi-colons as a delimiter
$mbname =~ s/,/-/igsm;
# $charsetheader = $mailcharset ? $mailcharset : $yycharset;
$charsetheader = 'UTF-8';
if ( !$from ) {
$from = $webmaster_email;
$fromheader = qq~"$mbname" <$from>~;
}
else {
$fromheader = "$from";
}
if ( !$to ) {
$to = $webmaster_email;
$toheader = "$mbname $smtp_txt{'555'} <$to>";
}
else {
$to =~ s/[ \t]+/, /gsm;
$toheader = $to;
}
$message =~ s/^\./../sm;
$message =~ s/[\r\n]/\n/gsm;
if ( $mailtype == 0 ) {
my $mailprogram = qq~$mailprog -t~;
open my $MAIL, q{|-}, $mailprogram or croak "$croak{'open'} MAIL";
@mailout =
( $fromheader, $toheader, $subject, $message, $charsetheader );
tomail( $MAIL, \@mailout );
close $MAIL; # or croak "$croak{'close'} MAIL";
return 1;
}
elsif ( $mailtype == 1 ) {
$smtp_to = $to;
$smtp_from = $from;
$smtp_message = $message;
$smtp_subject = $subject;
$smtp_charset = $charsetheader;
require Sources::Smtp;
use_smtp();
}
elsif ( $mailtype == 2 || $mailtype == 3 ) {
my @arg = ( "$smtp_server", Hello => "$smtp_server", Timeout => 30 );
if ( $mailtype == 2 ) {
eval q^
use Net::SMTP;
push @arg, Debug => 0;
$smtp = Net::SMTP->new(@arg) || croak "Unable to create Net::SMTP object. Server: '$smtp_server'\n\n" . $OS_ERROR;
^;
}
else {
eval q^
use Net::SMTP::TLS;
my $port = 25;
if ($smtp_server =~ s/:(\d+)$//sm) { $port = $1; }
push @arg, Port => $port;
if ($authuser) { push @arg, User => "$authuser" ;}
if ($authpass) { push @arg, Password => "$authpass" ;}
$smtp = Net::SMTP::TLS->new(@arg) || croak "Unable to create Net::SMTP::TLS object. Server: '$smtp_server', port '$port'\n\n" . $OS_ERROR;
^;
}
if ($EVAL_ERROR) {
fatal_error( 'net_fatal',
"$error_txt{'error_verbose'}: $EVAL_ERROR" );
}
eval q^
$smtp->mail($from);
foreach (split /, /sm, $to) { $smtp->to($_); }
$smtp->data();
$smtp->datasend("To: $toheader\r\n");
$smtp->datasend("From: $fromheader\r\n");
$smtp->datasend("X-Mailer: YaBB Net::SMTP\r\n");
$smtp->datasend("Subject: $subject\r\n");
$smtp->datasend("Content-Type: text/html\; charset=$charsetheader\r\n");
$smtp->datasend("\r\n");
$smtp->datasend($message);
$smtp->dataend();
$smtp->quit();
^;
if ($EVAL_ERROR) {
fatal_error( 'net_fatal',
"$error_txt{'error_verbose'}: $EVAL_ERROR" );
}
return 1;
}
elsif ( $mailtype == 4 ) {
# Dummy mail engine
fopen( MAIL, ">>$vardir/mail.log" );
print {MAIL} 'Mail sent at ' . scalar localtime() . "\n"
or croak "$croak{'print'} mail";
print {MAIL} "To: $toheader\n" or croak "$croak{'print'} mail";
print {MAIL} "From: $fromheader\n" or croak "$croak{'print'} mail";
print {MAIL} "X-Mailer: YaBB Sendmail\n"
or croak "$croak{'print'} mail";
print {MAIL} "Subject: $subject\n\n" or croak "$croak{'print'} mail";
$message =~ s/\r\n/\n/gsm;
print {MAIL} "$message\n" or croak "$croak{'print'} mail";
print {MAIL} "End of Message\n\n" or croak "$croak{'print'} mail";
fclose(MAIL);
return 1;
}
return;
}
# Before &sendmail is called, the message MUST be run through here.
# First argument is the message
# Second argument is a hashref to the replacements
# Example:
# $message = qq~Hello, {yabb username}! The answer is {yabb answer}!~;
# $message = &template_email($message, {username => $username, answer => 42});
# Result (with $username being the actual username):
# Hello, $username! The answer is 42!
sub template_email {
my ( $message, $info ) = @_;
foreach my $key ( keys %{$info} ) {
$message =~ s/(<|{)yabb $key(}|>)/$info->{$key}/gsm;
}
$message =~ s/(<|{)yabb scripturl(}|>)/$scripturl/gsm;
$message =~ s/(<|{)yabb adminurl(}|>)/$adminurl/gsm;
$message =~ s/(<|{)yabb mbname(}|>)/$mbname/gsm;
return $message;
}
sub tomail {
my ( $MAIL, $mailout ) = @_;
my ( $fromheader, $toheader, $subject, $message, $charsetheader ) =
@{$mailout};
print {$MAIL} "To: $toheader\n" or croak "$croak{'print'} mail";
print {$MAIL} "From: $fromheader\n" or croak "$croak{'print'} mail";
print {$MAIL} "X-Mailer: YaBB Sendmail\n" or croak "$croak{'print'} mail";
print {$MAIL} "Subject: $subject\n" or croak "$croak{'print'} mail";
print {$MAIL} "Content-Type: text/html\; charset=$charsetheader\n\n"
or croak "$croak{'print'} mail";
$message =~ s/\r\n/\n/gsm;
print {$MAIL} "$message\n" or croak "$croak{'print'} mail";
return;
}
1;