1 package Promulger::Dispatch;
6 # XXX allow the user to specify their own Email::Sender::Transport -- apeiron,
8 use Email::Sender::Simple qw(sendmail);
12 my($message, $config) = @_;
14 my $email = Email::Simple->new($message);
15 my $recipient = $email->header('To');
16 my $sender = $email->header('From');
17 my $subject = $email->header('Subject');
19 my $list = Promulger::List->resolve($recipient);
21 reject($recipient, $sender);
24 if($recipient =~ /-request$/) {
25 handle_request($list, $sender, $recipient, $subject, $config);
28 # they don't have a request for us, so they want to post a message
29 post_message($list, $email, $config);
33 my ($list, $sender, $recipient, $subject, $config) = @_;
35 if($subject =~ /^subscribe/i) {
36 $list->subscribe($sender, $config)
37 or already_subscribed($list, $sender, $config);
38 } elsif($subject =~ /^unsubscribe/i) {
39 $list->unsubscribe($sender, $config)
40 or not_subscribed($list, $sender, $config);
45 my($list, $email, $config) = @_;
47 my $sender = $email->header('From');
48 my $recipient = $email->header('To');
50 reject($recipient, $sender) unless $list->accept_posts_from($sender);
51 reject($recipient, $sender) unless $list->active;
53 # they're allowed to post (subscribed or not), the list is active. let's do
56 # XXX no MIME or other fancy handling for now -- apeiron, 2010-03-13
57 my $body = $email->body;
58 for my $subscriber ($list->subscribers) {
59 my $verped_from = Mail::Verp->encode($list->address, $subscriber);
60 # XXX we let the MTA create the message-id for us for now -- apeiron,
62 my $new_message = Email::Simple->create(
66 Subject => $email->subject,
70 # XXX no queuing or job distribution for now beyond what the MTA provides
71 # -- apeiron, 2010-03-13
72 sendmail($new_message);
78 sub already_subscribed {}
80 'http://www.shadowcat.co.uk/blog/matt-s-trout/oh-subdispatch-oh-subdispatch/';