arraysperlpolicyqmailmail-sender

Verify if email sender has permission to send to a certain address


I am forced to implement a sender policy in qmail.

I have a file describing the policies:

User1@domain1.com:*@domain1.com,x@Domain2.COM,y@DOMAIN.com
user2@domain1.com:*@*
USER3@domain1.com:

This file describes the following situation:

user1@domain1.com can send messages to anyone having the address defined on domain1.com, to x@domain2.com and to y@domain.com
user2@domain1.com can send messages to anyone
user3@domain1.com can not send messages at all

The letter case should be ignored.

I have to implement those restrictions in qmail, using qmailqueue and PERL (Mail::Qmail::Queue::Message) but I have no knowledge of PERL at all.

Any help is sincerely appreciated.


Solution

  • but I have no knowledge of PERL at all.

    Then the solution is

    (As an aside, the language is called Perl, and the interpreter used to run Perl programs is called perl. Other capitalizations are a bit frowned upon).


    Should you decide to try solving this problem on your own, here are a few pointers:

    The problem can be decomposed into subproblems:


    Code examples

    Parsing a line

    where the line is given in $_, and a hashref $rules_for_sender is in scope

    chomp;
    my ($sender, $rules) = map lc, split /:/, $_, 2;
    my @rules = map [split /@/], split /,/, $rules;
    $rules_for_sender->{$sender} = \@rules;
    

    Iterating through all rules for a sender

    for my $rule (@{ $rules->{$sender} } {
      my ($rule_user, $rule_domain) = @$rule;
      ...; # do stuff here
    }
    

    The rest…

    …is almost trivial if you remember