LJSUP-17669: Login.bml form refactoring
[livejournal.git] / cgi-bin / ljemailgateway-web.pl
blob54b7d5195236a744489b4d6a65765ba6fd654ede
1 # these are the email gateway functions needed from web land. they're
2 # also available from ljemailgateway.pl (which contains the full
3 # libraries)
5 package LJ::Emailpost;
6 use strict;
8 # Retreives an allowed email addr list for a given user object.
9 # Returns a hashref with addresses / flags.
10 # Used for ljemailgateway and manage/emailpost.bml
11 sub get_allowed_senders {
12 my $u = shift;
13 my (%addr, @address);
15 LJ::load_user_props($u, 'emailpost_allowfrom');
16 @address = split(/\s*,\s*/, $u->{emailpost_allowfrom});
17 return undef unless scalar(@address) > 0;
19 my %flag_english = ( 'E' => 'get_errors' );
21 foreach my $add (@address) {
22 my $flags;
23 $flags = $1 if $add =~ s/\((.+)\)$//;
24 $addr{$add} = {};
25 if ($flags) {
26 $addr{$add}->{$flag_english{$_}} = 1 foreach split(//, $flags);
30 return \%addr;
33 # Inserts email addresses into the database.
34 # Adds flags if needed.
35 # Used in manage/emailpost.bml
36 # $addr is hashref of { $email_address -> {$flag -> 1} } where possible values of $flag
37 # currently include only 'get_errors', to receive errors at that email address
38 sub set_allowed_senders {
39 my ($u, $addr) = @_;
40 my %flag_letters = ( 'get_errors' => 'E' );
42 my @addresses;
43 foreach (keys %$addr) {
44 my $email = $_;
45 my $flags = $addr->{$_};
46 if (%$flags) {
47 $email .= '(';
48 foreach my $flag (keys %$flags) {
49 $email .= $flag_letters{$flag};
51 $email .= ')';
53 push(@addresses, $email);
55 $u->set_prop("emailpost_allowfrom", join(", ", @addresses));