[BACK]Return to Mail.pm CVS log [TXT][DIR] Up to [local] / botnow

File: [local] / botnow / Mail.pm (download)

Revision 1.1, Sat May 15 15:12:32 2021 UTC (2 years, 11 months ago) by bountyht
Branch point for: MAIN

Initial revision

#!/usr/bin/perl

package Mail;

use strict;
use warnings;
use OpenBSD::Pledge;
use OpenBSD::Unveil;
use MIME::Base64;
use Digest::SHA qw(sha256_hex);

my %conf = %main::conf;
my $staff = $conf{staff};
my $hostname = $conf{hostname};
my $mailfrom = $conf{mailfrom};
my $mailname = $conf{mailname};
main::cbind("msg", "-", "mail", \&mmail);

sub init {
	#dependencies for encrypt
	unveil("/usr/bin/encrypt", "rx") or die "Unable to unveil $!";
	#dependencies for mail
	unveil("/usr/sbin/sendmail", "rx") or die "Unable to unveil $!";
	unveil("/usr/lib/libutil.so.13.1", "r") or die "Unable to unveil $!";
	unveil("/bin/sh", "rx") or die "Unable to unveil $!";
}
sub mmail {
	my ($bot, $nick, $host, $hand, $text) = @_;
	if ($staff !~ /$nick/) { return; }
	if ($text =~ /^([-_0-9a-zA-Z~@!\.]{3,})\s+([-_0-9a-zA-Z~@!\.]{3,})/) {
		my ($from, $to) = ($1, $2);
		if (mail($from, $to, "support", "alpha bravo", "charlie delta echo foxtrot")) {
			main::putserv($bot, "PRIVMSG $nick :mail sent from $from to $to");
		} else {
			main::putserv($bot, "PRIVMSG $nick :ERROR: failed to send mail");
		}
	}
}

sub mail {
	my( $from, $to, $fromname, $subject, $body )=@_;
my $msg = <<"EOF";
From: $from
To: $to
Subject: $subject
MIME-Version: 1.0 
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

$body
EOF
open(my $fh, "| /usr/sbin/sendmail -tv -F '$fromname' -f $from") or die "Could not send mail $!";
print $fh $msg;
close $fh;
return "true";
}


#sub mailfinish {
#	my( $username, $password, $email, $service )=@_;
#my $msg = <<"EOF";
#From: support \<support\@ircnow.org\>
#To: $email
#Subject: Welcome to IRCNow!
#MIME-Version: 1.0 
#Content-Type: text/plain; charset=us-ascii
#Content-Disposition: inline
#
#Welcome to IRCNow!
#
#Your account $username with password $password is now activated.
#
#For instructions on how to connect, please visit: https://ircnow.org
#
#For help, please visit our support channel on irc.ircnow.org #ircnow.
#
#IRCNow
#EOF
#open(my $fh, '| /usr/sbin/sendmail -tv -F support -f support@ircnow.org') or die "Could not send mail $!";
#print $fh $msg;
#close $fh;
#open($fh, '>>', "$database") or die "Could not open file '$database' $!";
#print $fh $msg;
#close $fh;
#}
#

#sub createmail {
#	my ($password, $username) = @_;
#	my $encrypted = `encrypt $password`;
#	chomp($encrypted);
#	my $line = "${username}\@ircnow.org:${encrypted}::::::userdb_quota_rule=*:storage=1G";
#	$line =~ s{\$}{\\\$}g;
#	my $line2 = "${username}\@ircnow.org	vmail";
#	my $line3 = "${username}:   ${username}\@ircnow.org";
#	`doas sh -c 'echo $line >> /etc/mail/passwd'`;
#	`doas sh -c 'echo $line2 >> /etc/mail/virtuals'`;
#	`doas sh -c 'echo $line3 >> /etc/mail/aliases'`;
#	`doas rcctl restart smtpd`;
#	`doas rcctl reload dovecot`;
#}

1; # MUST BE LAST STATEMENT IN FILE