Created
March 9, 2010 12:44
-
-
Save typester/326535 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Getopt::Long; | |
use AnyEvent; | |
use AnyEvent::IRC::Client; | |
use AnyEvent::SMTP 'smtp_server'; | |
use Email::MIME; | |
GetOptions( | |
\my %opt, | |
qw/host=s port=i nick=s password=s ssl/ | |
); | |
$opt{port} ||= 6667; | |
$opt{nick} ||= 'smtp2irc'; | |
die 'require irc hostname' | |
unless $opt{host}; | |
my $cv = AE::cv; | |
my %joined; | |
my $irc = AnyEvent::IRC::Client->new; | |
$irc->reg_cb( | |
registered => sub { | |
my ($irc) = @_; | |
}, | |
debug_send => sub { | |
my ($irc, $command, @params) = @_; | |
warn '> ', $command, join ' ', @params; | |
}, | |
debug_recvd => sub { | |
my ($irc, $msg) = @_; | |
warn '< ', $msg; | |
}, | |
); | |
$irc->enable_ssl if $opt{ssl}; | |
$irc->connect($opt{host}, $opt{port}, { | |
nick => $opt{nick}, | |
$opt{password} ? (password => $opt{password}) : (), | |
}); | |
smtp_server undef, 2525, sub { | |
my ($mail) = @_; | |
my $msg = Email::MIME->new($mail->{data}); | |
my ($label) = $mail->{to}[0] =~ /^(.+)\@/ | |
or return; | |
my $channel = '#' . $label; | |
unless ($joined{$label}++) { | |
$irc->send_srv('JOIN' => $channel ); | |
} | |
$irc->send_srv('PRIVMSG' => $channel, $msg->header('Subject')); | |
}; | |
$cv->wait; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment