+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);
+ }
+ }
+};
+