KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.4.62
System : FreeBSD fbsdweb2.web.rcn.net 14.1-RELEASE FreeBSD 14.1-RELEASE releng/14.1-n267679-10e31f0946d8 GENERIC amd64
User : www ( 80)
PHP Version : 8.3.8
Disable Function : NONE
Directory :  /domains/compasssysweb/calendar/CalciumDir39/Calendar/Mail/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /domains/compasssysweb/calendar/CalciumDir39/Calendar/Mail/MailSender.pm
# Copyright 1999-2003, Fred Steinberg, Brown Bear Software

# MailSender.pm - generic interface to some mailing situation
#                 if local 'sendmail' binary found, use that; otherwise, use
#                 Mail::Sendmail

use strict;
package MailSender;
use Calendar::MasterDB;

my @locations = qw (/usr/sbin/sendmail /usr/bin/sendmail /usr/lib/sendmail);

sub new {
    my $package = shift;
    my %args = (To   => '',
                From => 'Calcium',
                SMTP => 'localhost',
             'X-Mailer' => 'Calcium Web Calendar; http://www.brownbearsw.com',
                @_);
    my $self = \%args;
    bless $self, $package;
    $self;
}

# $hashOrMessage is either a scalar, which will be used as message body, or
# a ref to a hash, containing one or more of 'text' and 'html' keys for
# multipart mail
sub send {
    my $self = shift;
    my ($subject, $hashOrMessage) = @_;
    my $message = $hashOrMessage unless (ref $hashOrMessage);

    if (ref $hashOrMessage) {
        my $textPart = $hashOrMessage->{text} || '';
        my $htmlPart = $hashOrMessage->{html} || '';
        if ($textPart and $htmlPart) {
            my $bound = 'UrsusHorribilis' . time;
            $self->{'Content-type'} =
                               "multipart/alternative; boundary=\"$bound\"";
            $self->{'MIME-Version'} = "1.0";
            my $x = "--$bound\n";
            $x .= "Content-type: text/plain; charset=us-ascii;\n";
            $x .= "Content-transfer-encoding: 7bit\n\n";
            $x .= $textPart;
            $x .= "\n--$bound\n";
            $x .= "Content-type: text/html; charset=us-ascii;\n";
            $x .= "Content-transfer-encoding: 7bit\n\n";
            $x .= $htmlPart;
            $x .= "\n--$bound--\n\n";
            $message = $x;
        } elsif ($textPart) {
            $message = $textPart;
        } elsif ($htmlPart) {
            $self->{'Content-type'} = "text/html; charset=us-ascii";
            $message = $htmlPart;
        }
    }

    my %params;
    foreach (qw (To From CC BCC MIME-Version Content-type X-Mailer)) {
        $params{$_} = $self->{$_} if $self->{$_};     # allowed headers
    }

    $params{smtp}    = $self->{SMTP};
    $params{Subject} = $subject || $self->{subject};
    $params{body}    = $message || $self->{message};

    # if any address has no @, try expanding our built-in Aliases
    my $prefs = MasterDB->new->getPreferences;
    foreach my $field (qw (To CC BCC)) {
        my $addrs = $params{$field};
        next unless defined $addrs;
        my @addrs = split /[, ]+/, $addrs;
        foreach (@addrs) {
            next if /@/;
            $_ = join (',', $prefs->getMailAlias ($_)) || $_;
        }
        $params{$field} = join ',', @addrs;
    }

#DEBUGGING
# $params{body} .= "Originally-To: $params{To}";
# $params{To}    = 'fred@localhost';

    # look for sendmail binary
    my $sendmail;
    foreach (@locations) {
        $sendmail = $_ if -x;
        last if $sendmail;
    }

    # didn't found it, use Mail::Sendmail
    unless ($sendmail) {
        # note that sendmail is not sendmail, it's just called sendmail.
        require Calendar::Mail::Sendmail;
        my $ok = Calendar::Mail::Sendmail::sendmail (%params);
        $self->{error} = $Calendar::Mail::Sendmail::error unless ($ok);
        $self->{log}   = $Calendar::Mail::Sendmail::log;
        return $ok;         # returns true if ok
    }

    # found it, use sendmail
    my $headers;
    foreach (qw (To From CC BCC Subject MIME-Version Content-type X-Mailer)) {
        $headers .= "$_: $params{$_}\n" if $params{$_};
    }

    my $ok = open (SENDMAIL, "|$sendmail -oi -t");

    if ($ok) {
        print SENDMAIL <<"END_MAIL";
$headers
$params{body}
END_MAIL
        close SENDMAIL;
    } else {
        $self->{error} = "Can't run $sendmail: $!\n";
    }

    my $to = '';
    $to .= "To $params{To} " if $params{To};
    $to .= "CC $params{CC} " if $params{CC};
    $to .= "BCC $params{BCC} " if $params{BCC};
    $self->{log}   = "Sent message $to";
    $ok;         # returns true if ok
}

sub error {
    $_[0]->{error};
}
sub log {
    $_[0]->{log};
}

1;

Anon7 - 2021