| ############################################################################### |
| ############################################################################### |
| # Mailer.pl # |
| # Mailer.pm # |
| |
| # $Date: 01.05.16 $ # |
| ############################################################################### |
| ############################################################################### |
| # YaBB: Yet another Bulletin Board # |
| # YaBB: Yet another Bulletin Board # |
| # Open-Source Community Software for Webmasters # |
| # Open-Source Community Software for Webmasters # |
| # Version: YaBB 2.5.2 # |
| # Version: YaBB 2.6.12 # |
| # Packaged: October 21, 2012 # |
| # Packaged: January 5, 2016 # |
| # Distributed by: http://www.yabbforum.com # |
| # Distributed by: http://www.yabbforum.com # |
| # =========================================================================== # |
| # =========================================================================== # |
| # Copyright (c) 2000-2012 YaBB (www.yabbforum.com) - All Rights Reserved. # |
| # Copyright (c) 2000-2016 YaBB (www.yabbforum.com) - All Rights Reserved. # |
| # Software by: The YaBB Development Team # |
| # Software by: The YaBB Development Team # |
| # with assistance from the YaBB community. # |
| # with assistance from the YaBB community. # |
| ############################################################################### |
| ############################################################################### |
| |
| use CGI::Carp qw(fatalsToBrowser); |
| $mailerplver = 'YaBB 2.5.2 $Revision: 1.1 $'; |
| use English '-no_match_vars'; |
| if ($action eq 'detailedversion') { return 1; } |
| our $VERSION = '2.6.12'; |
| |
| |
| |
| $mailerpmver = 'YaBB 2.6.12 $Revision: 1722 $'; |
| |
| if ( $action eq 'detailedversion' ) { return 1; } |
| |
| |
| |
| $pre = q~style="padding:5px 40px; box-sizing:border-box; -moz-box-sizing:border-box; -webkit-box-sizing:border-box; display:block; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word; width:100%; overflow-x:auto;"~; |
| |
| $charsetheader = $mailcharset ? $mailcharset : $yymycharset; |
| |
| my $cte = "Content-Transfer-Encoding: 7bit\r"; |
| |
| if ( $charsetheader eq 'UTF-8') { |
| |
| $cte = "Content-Transfer-Encoding: 8bit\r"; |
| |
| } |
| |
| |
| sub sendmail { |
| sub sendmail { |
| my ($to, $subject, $message, $from, $mailcharset) = @_; |
| my ( $to, $subject, $message, $from, $mailcharset ) = @_; |
| |
| |
| # Do a FromHTML here for $to, and for $mbname |
| # Do a FromHTML here for $to, and for $mbname |
| # Just in case has special chars like & in addresses |
| # Just in case has special chars like & in addresses |
| &FromHTML($to); |
| FromHTML($to); |
| &FromHTML($mbname); |
| FromHTML($mbname); |
| |
| |
| # Change commas to HTML entity - ToHTML doesn't catch this |
| # Change commas to HTML entity - ToHTML doesn't catch this |
| # It's only a problem when sending emails, so no change to ToHTML. |
| # It's only a problem when sending emails, so no change to ToHTML. |
| # The html character conversion does not work properly for many email clients - DAR. |
| # Changed to dash -  misread in mail clients that use semi-colons as a delimiter |
| $mbname =~ s/,/-/ig; |
| $mbname =~ s/,/-/igsm; |
| |
| |
| $charsetheader = $mailcharset ? $mailcharset : $yycharset; |
| if ( !$from ) { |
| |
| $from = $webmaster_email; |
| if (!$from) { |
| $fromheader = qq~"$mbname" <$from>~; |
| $from = $webmaster_email; |
| } |
| $fromheader = qq~"$mbname" <$from>~; |
| else { |
| } else { |
| $fromheader = "$from"; |
| $fromheader = $from; |
| } |
| } |
| |
| |
| if ( !$to ) { |
| if (!$to) { |
| $to = $webmaster_email; |
| $to = $webmaster_email; |
| $toheader = "$mbname $smtp_txt{'555'} <$to>"; |
| $toheader = "$mbname $smtp_txt{'555'} <$to>"; |
| } |
| } else { |
| else { |
| $to =~ s/[ \t]+/, /g; |
| $to =~ s/[ \t]+/, /gsm; |
| $toheader = $to; |
| $toheader = $to; |
| } |
| } |
| |
| |
| $message =~ s/^\./../m; |
| $message =~ s/^\./../sm; |
| $message =~ s/[\r\n]/\n/g; |
| $message =~ s/[\r\n]/\n/gsm; |
| |
| |
| if ($mailtype == 0) { |
| if ( $mailtype == 0 ) { |
| open(MAIL, "|$mailprog -t"); |
| my $mailprogram = qq~$mailprog -t~; |
| print MAIL "To: $toheader\n"; |
| open my $MAIL, q{|-}, $mailprogram or croak "$croak{'open'} MAIL"; |
| print MAIL "From: $fromheader\n"; |
| @mailout = |
| print MAIL "X-Mailer: YaBB Sendmail\n"; |
| ( $fromheader, $toheader, $subject, $message, $charsetheader ); |
| print MAIL "Subject: $subject\n"; |
| tomail( $MAIL, \@mailout ); |
| print MAIL "Content-Type: text/plain\; charset=$charsetheader\n\n"; |
| close $MAIL; # or croak "$croak{'close'} MAIL"; |
| $message =~ s/\r\n/\n/g; |
| |
| print MAIL "$message\n"; |
| return 1; |
| close(MAIL); |
| } |
| return 1; |
| elsif ( $mailtype == 1 ) { |
| |
| $smtp_to = $to; |
| } elsif ($mailtype == 1) { |
| $smtp_from = $from; |
| $smtp_to = $to; |
| $smtp_message = qq~<pre $pre>$message</pre>~; |
| $smtp_from = $from; |
| $smtp_subject = $subject; |
| $smtp_message = $message; |
| $smtp_charset = $charsetheader; |
| $smtp_subject = $subject; |
| require Sources::Smtp; |
| $smtp_charset = $charsetheader; |
| use_smtp(); |
| require "$sourcedir/Smtp.pl"; |
| |
| &use_smtp; |
| } |
| |
| elsif ( $mailtype == 2 || $mailtype == 3 ) { |
| } elsif ($mailtype == 2 || $mailtype == 3) { |
| my @arg = ( "$smtp_server", Hello => "$smtp_server", Timeout => 30 ); |
| my $smtp; |
| if ( $mailtype == 2 ) { |
| my @arg = ("$smtp_server", Hello => "$smtp_server", Timeout => 30); |
| eval q^ |
| if ($mailtype == 2) { |
| use Net::SMTP; |
| eval q^ |
| push @arg, Debug => 0; |
| eval 'use Net::SMTP;'; |
| $smtp = Net::SMTP->new(@arg) || croak "Unable to create Net::SMTP object. Server: '$smtp_server'\n\n" . $OS_ERROR; |
| push(@arg, Debug => 0); |
| ^; |
| $smtp = Net::SMTP->new(@arg) || die "Unable to create Net::SMTP object. Server: '$smtp_server'\n\n" . $!; |
| } |
| ^; |
| else { |
| } else { |
| eval q^ |
| eval q^ |
| use Net::SMTP::TLS; |
| use Net::SMTP::TLS;'; |
| my $port = 25; |
| my $port = 25; |
| if ($smtp_server =~ s/:(\d+)$//sm) { $port = $1; } |
| if ($smtp_server =~ s/:(\d+)$//) { $port = $1; } |
| push @arg, Port => $port; |
| push(@arg, Port => $port); |
| if ($authuser) { push @arg, User => "$authuser" ;} |
| push(@arg, User => "$authuser") if $authuser; |
| if ($authpass) { push @arg, Password => "$authpass" ;} |
| push(@arg, Password => "$authpass") if $authpass; |
| $smtp = Net::SMTP::TLS->new(@arg) || croak "Unable to create Net::SMTP::TLS object. Server: '$smtp_server', port '$port'\n\n" . $OS_ERROR; |
| $smtp = Net::SMTP::TLS->new(@arg) || die "Unable to create Net::SMTP::TLS object. Server: '$smtp_server', port '$port'\n\n" . $!; |
| ^; |
| ^; |
| } |
| } |
| if ($EVAL_ERROR) { |
| if ($@) { &fatal_error("net_fatal","$error_txt{'error_verbose'}: $@"); } |
| fatal_error( 'net_fatal', |
| |
| "$error_txt{'error_verbose'}: $EVAL_ERROR" ); |
| eval q^ |
| } |
| $smtp->mail($from); |
| |
| foreach (split(/, /, $to)) { $smtp->to($_); } |
| eval q^ |
| $smtp->data(); |
| $smtp->mail($from); |
| $smtp->datasend("To: $toheader\r\n"); |
| foreach (split /, /sm, $to) { $smtp->to($_); } |
| $smtp->datasend("From: $fromheader\r\n"); |
| $smtp->data(); |
| $smtp->datasend("X-Mailer: YaBB Net::SMTP\r\n"); |
| $smtp->datasend("To: $toheader\r\n"); |
| $smtp->datasend("Subject: $subject\r\n"); |
| $smtp->datasend("From: $fromheader\r\n"); |
| $smtp->datasend("Content-Type: text/plain\; charset=$charsetheader\r\n"); |
| $smtp->datasend("X-Mailer: YaBB Net::SMTP\r\n"); |
| $smtp->datasend("\r\n"); |
| $smtp->datasend("Subject: $subject\r\n"); |
| $smtp->datasend($message); |
| $smtp->datasend("MIME-Version: 1.0\r\n$cte\nContent-Type: text/html\; charset=$charsetheader\r\n"); |
| $smtp->dataend(); |
| $smtp->datasend("\r\n"); |
| $smtp->quit(); |
| $smtp->datasend("<pre $pre>$message</pre>"); |
| ^; |
| $smtp->dataend(); |
| if ($@) { &fatal_error("net_fatal","$error_txt{'error_verbose'}: $@"); } |
| $smtp->quit(); |
| return 1; |
| ^; |
| |
| if ($EVAL_ERROR) { |
| } elsif ($mailtype == 4) { |
| fatal_error( 'net_fatal', |
| # Dummy mail engine |
| "$error_txt{'error_verbose'}: $EVAL_ERROR" ); |
| fopen(MAIL, ">>$vardir/mail.log"); |
| } |
| print MAIL "Mail sent at " . scalar localtime() . "\n"; |
| return 1; |
| print MAIL "To: $toheader\n"; |
| |
| print MAIL "From: $fromheader\n"; |
| } |
| print MAIL "X-Mailer: YaBB Sendmail\n"; |
| elsif ( $mailtype == 4 ) { |
| print MAIL "Subject: $subject\n\n"; |
| |
| $message =~ s/\r\n/\n/g; |
| # Dummy mail engine |
| print MAIL "$message\n"; |
| fopen( MAIL, ">>$vardir/mail.log" ); |
| print MAIL "End of Message\n\n"; |
| print {MAIL} 'Mail sent at ' . scalar gmtime() . "\n" |
| fclose(MAIL); |
| or croak "$croak{'print'} mail"; |
| return 1; |
| 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} "<pre $pre>$message</pre>\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. |
| # Before &sendmail is called, the message MUST be run through here. |
| # First argument is the message |
| # First argument is the message |
| # Second argument is a hashref to the replacements |
| # Second argument is a hashref to the replacements |
| # Example: |
| # Example: |
| # $message = qq~Hello, {yabb username}! The answer is {yabb answer}!~; |
| # $message = qq~Hello, {yabb username}! The answer is {yabb answer}!~; |
| # $message = &template_email($message, {username => $username, answer => 42}); |
| # $message = &template_email($message, {username => $username, answer => 42}); |
| # Result (with $username being the actual username): |
| # Result (with $username being the actual username): |
| # Hello, $username! The answer is 42! |
| # Hello, $username! The answer is 42! |
| sub template_email { |
| sub template_email { |
| my ($message, $info) = @_; |
| my ( $message, $info ) = @_; |
| foreach my $key (keys(%$info)) { $message =~ s/(<|{)yabb $key(}|>)/$info->{$key}/g; } |
| foreach my $key ( keys %{$info} ) { |
| $message =~ s/(<|{)yabb scripturl(}|>)/$scripturl/g; |
| $message =~ s/{yabb $key}/$info->{$key}/gsm; |
| $message =~ s/(<|{)yabb adminurl(}|>)/$adminurl/g; |
| } |
| $message =~ s/(<|{)yabb mbname(}|>)/$mbname/g; |
| $message =~ s/{yabb scripturl}/$scripturl/gsm; |
| $message; |
| $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} "MIME-Version: 1.0\r\n" or croak "$croak{'print'} mail"; |
| |
| print {$MAIL} "$cte\n" or croak "$croak{'print'} mail"; |
| |
| print {$MAIL} "Content-Type: text/html\; charset=$charsetheader\r\n" |
| |
| or croak "$croak{'print'} mail"; |
| |
| $message =~ s/\r\n/\n/gsm; |
| |
| print {$MAIL} "<pre $pre>$message</pre>\n" or croak "$croak{'print'} mail"; |
| |
| return; |
| } |
| } |
| |
| |
| 1; |
| 1; |
| |
| |