6 use AnyEvent::SMTP::Server;
7 use AnyEvent::SMTP::Client qw(sendmail);
8 use Data::Dump qw(dump);
13 my $host = $ENV{SMTP_HOST} || '0.0.0.0';
14 my $port = $ENV{SMTP_PORT} || 2525;
15 my $server = $ENV{SMTP_SERVER};
17 MQR::Redis->redis->psubscribe( "SEND $host:$port smtp *", sub {
18 my ( $message, $channel ) = @_;
19 my ( undef, undef, undef, $from, $to ) = split(/\s/,$channel);
20 warn "sendmail $from -> $to | $message\n";
24 $f .= '@mqr.rot13.org';
29 data => "Subject: $message\n\n$message",
32 warn "# sendmail ", $ok && "OK $ok" || "ERROR: $error", "\n";
38 my $smtp = AnyEvent::SMTP::Server->new( host => $host, port => $port );
43 warn "Client from $con->{host}:$con->{port} connected\n";
47 warn "Client from $con->{host}:$con->{port} gone\n";
51 my $from = $mail->{from};
52 warn "Received mail from $from to ",join(' and ',@{$mail->{to}}), "\n$mail->{data}\n";
53 foreach my $to ( @{ $mail->{to} } ) {
54 my $subject = $1 if $mail->{data} =~ m/^Subject:\s*(.+)$/m;
55 $subject =~ s/[\s\r\n]+$//; # XXX important!
56 MQR::Redis->publish( "MSG $host:$port smtp $from $to" => $subject );
62 AnyEvent->condvar->recv;