From: Michael Andreen Date: Thu, 15 Sep 2011 21:02:13 +0000 (+0200) Subject: Added .sendmail command X-Git-Url: https://ruin.nu/git/?p=NDIRC.git;a=commitdiff_plain;h=4cc6a095219bfd82ce9f37c89cd941f4da278b64 Added .sendmail command --- diff --git a/Commands/SMS.pm b/Commands/SMS.pm index 452e317..55405d0 100644 --- a/Commands/SMS.pm +++ b/Commands/SMS.pm @@ -88,4 +88,47 @@ WHERE id = $1 } }; +command sendmail => { + help => q(.sendmail message), + acl => q(irc_sendmail), + type => q(member), +}, class extends NDIRC::Command { + use Mail::Sendmail; + use Encode; + method execute($c,$msg) { + my ($user,$message) = $msg =~ /^(\S+) (.+)$/ or die 'ARGS'; + my $dbh = $c->model; + my $mail; + + if ($user =~ /@/){ + $mail = $user + }else{ + $mail = $dbh->selectrow_array(q{ +SELECT email FROM users WHERE username ilike $1 + AND uid IN (SELECT uid FROM groupmembers WHERE gid = 'M') + },undef,$user); + $mail //= 'No mail, or invalid user'; + if ($mail =~ /^\S+@\S+$/){ + }else{ + $c->reply("User $user has email addy '$mail' which looks odd"); + return; + } + } + my %mail = ( + smtp => 'ruin.nu:587', + To => $mail, + From => 'NewDawn Command ', + 'Content-type' => 'text/plain; charset="UTF-8"', + Subject => "ND: " . (substr $message, 0, 60), + Message => encode("UTF-8",$message), + ); + + if (sendmail %mail) { + $c->reply("Mail sent to $user"); + }else { + $c->reply("Could not send mail to $user: " . $Mail::Sendmail::error); + } + } +}; + 1;