1 package Promulger::Dispatch;
6 # XXX allow the user to specify their own Email::Sender::Transport -- apeiron,
8 use Email::Sender::Simple qw(sendmail);
11 use Promulger::Config;
13 # XXX no bounce parsing yet -- apeiron, 2010-03-13
16 my $config = Promulger::Config->config;
18 my $email = Email::Simple->new($message);
19 my $recipient = $email->header('To');
20 my $sender = $email->header('From');
21 my $subject = $email->header('Subject');
23 my $list = Promulger::List->resolve($recipient);
25 reject($recipient, $sender);
28 if($recipient =~ /-request$/) {
29 handle_request($list, $sender, $recipient, $subject, $config);
32 # they don't have a request for us, so they want to post a message
33 post_message($list, $email, $config);
37 my ($list, $sender, $recipient, $subject) = @_;
39 if($subject =~ /^subscribe/i) {
40 $list->subscribe($sender)
41 or already_subscribed($list, $sender);
42 } elsif($subject =~ /^unsubscribe/i) {
43 $list->unsubscribe($sender)
44 or not_subscribed($list, $sender);
49 my($list, $email, $config) = @_;
51 my $sender = $email->header('From');
52 my $recipient = $email->header('To');
54 reject($recipient, $sender) unless $list->accept_posts_from($sender);
55 reject($recipient, $sender) unless $list->active;
57 # they're allowed to post (subscribed or not), the list is active. let's do
60 # XXX no MIME or other fancy handling for now -- apeiron, 2010-03-13
61 my $body = $email->body;
62 for my $subscriber ($list->subscribers) {
63 my $verped_from = Mail::Verp->encode($list->address, $subscriber);
64 # XXX we let the MTA create the message-id for us for now -- apeiron,
66 my $new_message = Email::Simple->create(
70 Subject => $email->subject,
74 # XXX no queuing or job distribution for now beyond what the MTA provides
75 # -- apeiron, 2010-03-13
76 sendmail($new_message);
80 # XXX make this actually not suck -- apeiron, 2010-03-13
82 my($recipient, $sender) = @_;
83 my $email = Email::Simple->create(
87 Subject => 'Rejected',
90 Sorry, your message to $recipient has been denied.
97 my($list, $sender) = @_;
98 my $list_address = $list->address;
99 my $email = Email::Simple->create(
101 From => $list->admin_address,
103 Subject => 'Not subscribed',
106 Sorry, you are not subscribed to $list_address;
112 sub already_subscribed {
113 my($list, $sender) = @_;
114 my $list_address = $list->address;
115 my $email = Email::Simple->create(
117 From => $list->admin_address,
119 Subject => 'Already subscribed',
122 Sorry, you are already subscribed to $list_address;
128 'http://www.shadowcat.co.uk/blog/matt-s-trout/oh-subdispatch-oh-subdispatch/';