Annotation of botnow/Mail.pm, Revision 1.1.1.1
1.1 bountyht 1: #!/usr/bin/perl
2:
3: package Mail;
4:
5: use strict;
6: use warnings;
7: use OpenBSD::Pledge;
8: use OpenBSD::Unveil;
9: use MIME::Base64;
10: use Digest::SHA qw(sha256_hex);
11:
12: my %conf = %main::conf;
13: my $staff = $conf{staff};
14: my $hostname = $conf{hostname};
15: my $mailfrom = $conf{mailfrom};
16: my $mailname = $conf{mailname};
17: main::cbind("msg", "-", "mail", \&mmail);
18:
19: sub init {
20: #dependencies for encrypt
21: unveil("/usr/bin/encrypt", "rx") or die "Unable to unveil $!";
22: #dependencies for mail
23: unveil("/usr/sbin/sendmail", "rx") or die "Unable to unveil $!";
24: unveil("/usr/lib/libutil.so.13.1", "r") or die "Unable to unveil $!";
25: unveil("/bin/sh", "rx") or die "Unable to unveil $!";
26: }
27: sub mmail {
28: my ($bot, $nick, $host, $hand, $text) = @_;
29: if ($staff !~ /$nick/) { return; }
30: if ($text =~ /^([-_0-9a-zA-Z~@!\.]{3,})\s+([-_0-9a-zA-Z~@!\.]{3,})/) {
31: my ($from, $to) = ($1, $2);
32: if (mail($from, $to, "support", "alpha bravo", "charlie delta echo foxtrot")) {
33: main::putserv($bot, "PRIVMSG $nick :mail sent from $from to $to");
34: } else {
35: main::putserv($bot, "PRIVMSG $nick :ERROR: failed to send mail");
36: }
37: }
38: }
39:
40: sub mail {
41: my( $from, $to, $fromname, $subject, $body )=@_;
42: my $msg = <<"EOF";
43: From: $from
44: To: $to
45: Subject: $subject
46: MIME-Version: 1.0
47: Content-Type: text/plain; charset=us-ascii
48: Content-Disposition: inline
49:
50: $body
51: EOF
52: open(my $fh, "| /usr/sbin/sendmail -tv -F '$fromname' -f $from") or die "Could not send mail $!";
53: print $fh $msg;
54: close $fh;
55: return "true";
56: }
57:
58:
59: #sub mailfinish {
60: # my( $username, $password, $email, $service )=@_;
61: #my $msg = <<"EOF";
62: #From: support \<support\@ircnow.org\>
63: #To: $email
64: #Subject: Welcome to IRCNow!
65: #MIME-Version: 1.0
66: #Content-Type: text/plain; charset=us-ascii
67: #Content-Disposition: inline
68: #
69: #Welcome to IRCNow!
70: #
71: #Your account $username with password $password is now activated.
72: #
73: #For instructions on how to connect, please visit: https://ircnow.org
74: #
75: #For help, please visit our support channel on irc.ircnow.org #ircnow.
76: #
77: #IRCNow
78: #EOF
79: #open(my $fh, '| /usr/sbin/sendmail -tv -F support -f support@ircnow.org') or die "Could not send mail $!";
80: #print $fh $msg;
81: #close $fh;
82: #open($fh, '>>', "$database") or die "Could not open file '$database' $!";
83: #print $fh $msg;
84: #close $fh;
85: #}
86: #
87:
88: #sub createmail {
89: # my ($password, $username) = @_;
90: # my $encrypted = `encrypt $password`;
91: # chomp($encrypted);
92: # my $line = "${username}\@ircnow.org:${encrypted}::::::userdb_quota_rule=*:storage=1G";
93: # $line =~ s{\$}{\\\$}g;
94: # my $line2 = "${username}\@ircnow.org vmail";
95: # my $line3 = "${username}: ${username}\@ircnow.org";
96: # `doas sh -c 'echo $line >> /etc/mail/passwd'`;
97: # `doas sh -c 'echo $line2 >> /etc/mail/virtuals'`;
98: # `doas sh -c 'echo $line3 >> /etc/mail/aliases'`;
99: # `doas rcctl restart smtpd`;
100: # `doas rcctl reload dovecot`;
101: #}
102:
103: 1; # MUST BE LAST STATEMENT IN FILE
CVSweb