Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@typester
Created March 9, 2010 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save typester/326535 to your computer and use it in GitHub Desktop.
Save typester/326535 to your computer and use it in GitHub Desktop.
#!/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