--- /dev/null
+package App::Promulger::Command::msgbounce;
+use strictures 1;
+use autodie;
+
+use App::Promulger -command;
+use parent 'App::Promulger::Command';
+use Promulger::Dispatch;
+
+sub abstract {
+ return "handle a potential bounce";
+}
+
+sub run {
+ my ($self, $opt, $args) = @_;
+ my $message = do {
+ local $/;
+ <STDIN>
+ };
+ Promulger::Dispatch->new->handle_bounce($message);
+}
+
+1;
use Moo;
use autodie ':all';
use Scalar::Util 'blessed';
+use Try::Tiny;
use Email::Address;
use Email::MIME;
#use Mail::Verp;
use Promulger::Config;
+use Promulger::List;
has transport => (
is => 'rw',
},
);
-# XXX no bounce parsing yet -- apeiron, 2010-03-13
sub dispatch {
my ($self, $message) = @_;
my $config = Promulger::Config->config;
}
}
+# XXX this needs to be better -- apeiron, 2012-07-18
+sub handle_bounce {
+ my ($self, $raw_message) = @_;
+ my $message = Email::MIME->new($raw_message);
+ require Mail::DeliveryStatus::BounceParser;
+ my $bounce;
+ my $recipient = $message->header('To');
+ my $recipient_address = Email::Address->parse($recipient);
+ try {
+ my $bounce = Mail::DeliveryStatus::BounceParser->new($message);
+ } catch {
+ my $domain = $recipient_address->host;
+ my $redirect = Email::MIME->create(
+ header_str => [
+ From => $message->header('From'),
+ To => "postmaster@${domain}",
+ Subject => $message->header('Subject'),
+ ],
+ body_str => $message->body_str,
+ );
+ $self->send_message($redirect);
+ };
+ my @addresses = $bounce->addresses;
+ my $list = Promulger::List->resolve($recipient_address->address);
+ for my $addr (@addresses) {
+ my $a = Email::Address->parse($addr);
+ my $raw_address = $a->address;
+ $list->unsubscribe($raw_address);
+ }
+}
+
sub post_message {
my ($self, $list, $email, $config) = @_;
my $sender = $email->header('From');
sub resolve {
my ($self, $proto) = @_;
$proto =~ s/-request$//;
+ $proto =~ s/^owner-//;
my $path = find_path_for($proto);
my $maybe_list;
try {
$tie->flock;
my @list_aliases = ($name, "${name}-request");
+ # XXX add a flag to determine whether to write the aliases file or no
+ # -- apeiron, 2012-07-18
for my $list_alias (@list_aliases) {
if(grep { /^${list_alias}:/ } @aliases) {
croak "${list_alias} already in $config->{aliases}";
}
push @aliases,
- qq(${list_alias}: "|$Bin msg -c $config->{config_file}"\n);
+ qq(${list_alias}: "|$Bin msg -c $config->{config_file}"\n),
+ qq(${list_alias}-owner: "|$Bin msgbounce -c $config->{config_file}"\n);
}
$self->store($path->stringify);