]> ruin.nu Git - NDIRC.git/commitdiff
Added .sendmail command noeos
authorMichael Andreen <harv@ruin.nu>
Thu, 15 Sep 2011 21:02:13 +0000 (23:02 +0200)
committerMichael Andreen <harv@ruin.nu>
Thu, 15 Sep 2011 21:02:13 +0000 (23:02 +0200)
Commands/SMS.pm

index 452e31754d21e472fc182d93d9c7a957f99537c9..55405d03959001931f084c3d8e192580d4cbf43d 100644 (file)
@@ -88,4 +88,47 @@ WHERE id = $1
        }
 };
 
        }
 };
 
+command sendmail => {
+       help => q(.sendmail <username or email addy> 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 <nd@ruin.nu>',
+                       '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;
 1;