[dw-free] move cgi-bin/lj*.pl files into proper modules (in cgi-bin/LJ)
[commit: http://hg.dwscoalition.org/dw-free/rev/019aba8303dc]
http://bugs.dwscoalition.org/show_bug.cgi?id=1726
Move ljemailgateway-web.pl to LJ/Emailpost/Web.pm. Update package and
require statements.
Patch by
kareila.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=1726
Move ljemailgateway-web.pl to LJ/Emailpost/Web.pm. Update package and
require statements.
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- cgi-bin/LJ/Emailpost/Web.pm
- cgi-bin/LJ/Setting/EmailPosting.pm
- cgi-bin/ljemailgateway-web.pl
- cgi-bin/ljemailgateway.pl
- cgi-bin/modperl_subs.pl
- htdocs/manage/emailpost.bml
- t/emailpost.t
-------------------------------------------------------------------------------- diff -r 1859f7e73c3f -r 019aba8303dc cgi-bin/LJ/Emailpost/Web.pm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cgi-bin/LJ/Emailpost/Web.pm Fri Sep 30 00:20:57 2011 +0800 @@ -0,0 +1,72 @@ +# This code was forked from the LiveJournal project owned and operated +# by Live Journal, Inc. The code has been modified and expanded by +# Dreamwidth Studios, LLC. These files were originally licensed under +# the terms of the license supplied by Live Journal, Inc, which can +# currently be found at: +# +# http://code.livejournal.org/trac/livejournal/browser/trunk/LICENSE-LiveJournal.txt +# +# In accordance with the original license, this code and all its +# modifications are provided under the GNU General Public License. +# A copy of that license can be found in the LICENSE file included as +# part of this distribution. + +# these are the email gateway functions needed from web land. they're +# also available from ljemailgateway.pl (which contains the full +# libraries) + +package LJ::Emailpost::Web; +use strict; + +# Retrieves an allowed email addr list for a given user object. +# Returns a hashref with addresses / flags. +# Used for ljemailgateway and manage/emailpost.bml +sub get_allowed_senders { + my $u = shift; + return undef unless LJ::isu( $u ); + my (%addr, @address); + + @address = split( /\s*,\s*/, $u->prop( 'emailpost_allowfrom' ) ); + return undef unless scalar(@address) > 0; + + my %flag_english = ( 'E' => 'get_errors' ); + + foreach my $add (@address) { + my $flags; + $flags = $1 if $add =~ s/\((.+)\)$//; + $addr{$add} = {}; + if ($flags) { + $addr{$add}->{$flag_english{$_}} = 1 foreach split(//, $flags); + } + } + + return \%addr; +} + +# Inserts email addresses into the database. +# Adds flags if needed. +# Used in manage/emailpost.bml +# $addr is hashref of { $email_address -> {$flag -> 1} } where possible values of $flag +# currently include only 'get_errors', to receive errors at that email address +sub set_allowed_senders { + my ($u, $addr) = @_; + my %flag_letters = ( 'get_errors' => 'E' ); + + my @addresses; + foreach (keys %$addr) { + my $email = $_; + my $flags = $addr->{$_}; + if (%$flags) { + $email .= '('; + foreach my $flag (keys %$flags) { + $email .= $flag_letters{$flag}; + } + $email .= ')'; + } + push(@addresses, $email); + } + $u->set_prop("emailpost_allowfrom", join(", ", @addresses)); +} + +1; + diff -r 1859f7e73c3f -r 019aba8303dc cgi-bin/LJ/Setting/EmailPosting.pm --- a/cgi-bin/LJ/Setting/EmailPosting.pm Fri Sep 30 00:17:34 2011 +0800 +++ b/cgi-bin/LJ/Setting/EmailPosting.pm Fri Sep 30 00:20:57 2011 +0800 @@ -41,7 +41,7 @@ my $can_emailpost = $u->can_emailpost; my $upgrade_link = $can_emailpost ? "" : LJ::Hooks::run_hook("upgrade_link", $u, "plus"); - my $addrlist = LJ::Emailpost::get_allowed_senders($u); + my $addrlist = LJ::Emailpost::Web::get_allowed_senders( $u ); my @addresses = sort keys %$addrlist; my $pin = $class->get_arg($args, "emailposting_pin") || $u->prop("emailpost_pin"); @@ -146,7 +146,7 @@ $addrcount++; } - LJ::Emailpost::set_allowed_senders($u, \%allowed); + LJ::Emailpost::Web::set_allowed_senders( $u, \%allowed ); $class->email_helpmessage( $u, $_ ) foreach @send_helpmessage; $pin_val =~ s/\s+//g; diff -r 1859f7e73c3f -r 019aba8303dc cgi-bin/ljemailgateway-web.pl --- a/cgi-bin/ljemailgateway-web.pl Fri Sep 30 00:17:34 2011 +0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -# This code was forked from the LiveJournal project owned and operated -# by Live Journal, Inc. The code has been modified and expanded by -# Dreamwidth Studios, LLC. These files were originally licensed under -# the terms of the license supplied by Live Journal, Inc, which can -# currently be found at: -# -# http://code.livejournal.org/trac/livejournal/browser/trunk/LICENSE-LiveJournal.txt -# -# In accordance with the original license, this code and all its -# modifications are provided under the GNU General Public License. -# A copy of that license can be found in the LICENSE file included as -# part of this distribution. - -# these are the email gateway functions needed from web land. they're -# also available from ljemailgateway.pl (which contains the full -# libraries) - -package LJ::Emailpost; -use strict; - -# Retreives an allowed email addr list for a given user object. -# Returns a hashref with addresses / flags. -# Used for ljemailgateway and manage/emailpost.bml -sub get_allowed_senders { - my $u = shift; - return undef unless LJ::isu( $u ); - my (%addr, @address); - - @address = split( /\s*,\s*/, $u->prop( 'emailpost_allowfrom' ) ); - return undef unless scalar(@address) > 0; - - my %flag_english = ( 'E' => 'get_errors' ); - - foreach my $add (@address) { - my $flags; - $flags = $1 if $add =~ s/\((.+)\)$//; - $addr{$add} = {}; - if ($flags) { - $addr{$add}->{$flag_english{$_}} = 1 foreach split(//, $flags); - } - } - - return \%addr; -} - -# Inserts email addresses into the database. -# Adds flags if needed. -# Used in manage/emailpost.bml -# $addr is hashref of { $email_address -> {$flag -> 1} } where possible values of $flag -# currently include only 'get_errors', to receive errors at that email address -sub set_allowed_senders { - my ($u, $addr) = @_; - my %flag_letters = ( 'get_errors' => 'E' ); - - my @addresses; - foreach (keys %$addr) { - my $email = $_; - my $flags = $addr->{$_}; - if (%$flags) { - $email .= '('; - foreach my $flag (keys %$flags) { - $email .= $flag_letters{$flag}; - } - $email .= ')'; - } - push(@addresses, $email); - } - $u->set_prop("emailpost_allowfrom", join(", ", @addresses)); -} - -1; - diff -r 1859f7e73c3f -r 019aba8303dc cgi-bin/ljemailgateway.pl --- a/cgi-bin/ljemailgateway.pl Fri Sep 30 00:17:34 2011 +0800 +++ b/cgi-bin/ljemailgateway.pl Fri Sep 30 00:20:57 2011 +0800 @@ -29,7 +29,7 @@ } require 'ljlib.pl'; -require 'ljemailgateway-web.pl'; +use LJ::Emailpost::Web; require 'ljprotocol.pl'; use Date::Parse; use HTML::Entities; @@ -73,7 +73,7 @@ return unless $u && $u->is_visible; # Pick what address to send potential errors to. - $addrlist = LJ::Emailpost::get_allowed_senders($u); + $addrlist = LJ::Emailpost::Web::get_allowed_senders( $u ); $from = ${(Mail::Address->parse( $head->get('From:') ))[0] || []}[1]; return unless $from; my $err_addr; diff -r 1859f7e73c3f -r 019aba8303dc cgi-bin/modperl_subs.pl --- a/cgi-bin/modperl_subs.pl Fri Sep 30 00:17:34 2011 +0800 +++ b/cgi-bin/modperl_subs.pl Fri Sep 30 00:20:57 2011 +0800 @@ -92,7 +92,7 @@ use LJ::Sysban; use LJ::Community; use LJ::Tags; -require "ljemailgateway-web.pl"; +use LJ::Emailpost::Web; use LJ::Customize; use DW::Captcha; diff -r 1859f7e73c3f -r 019aba8303dc htdocs/manage/emailpost.bml --- a/htdocs/manage/emailpost.bml Fri Sep 30 00:17:34 2011 +0800 +++ b/htdocs/manage/emailpost.bml Fri Sep 30 00:20:57 2011 +0800 @@ -333,7 +333,7 @@ return LJ::bad_input(@errors) if @errors; - LJ::Emailpost::set_allowed_senders($u, \%allowed); + LJ::Emailpost::Web::set_allowed_senders( $u, \%allowed ); foreach my $prop (@props) { next if $prop =~ /emailpost_(allowfrom|pin)/; next if $u->{'prop'} eq $POST{$prop}; @@ -364,7 +364,7 @@ #-------------------------------------------------------------------------- # Initial page - my $addrlist = LJ::Emailpost::get_allowed_senders($u); + my $addrlist = LJ::Emailpost::Web::get_allowed_senders( $u ); my (@address, $res, $ret); push @address, $_ foreach sort keys %$addrlist; diff -r 1859f7e73c3f -r 019aba8303dc t/emailpost.t --- a/t/emailpost.t Fri Sep 30 00:17:34 2011 +0800 +++ b/t/emailpost.t Fri Sep 30 00:20:57 2011 +0800 @@ -4,7 +4,7 @@ use Test::More tests => 13; use lib "$ENV{LJHOME}/cgi-bin"; require 'ljlib.pl'; -require 'ljemailgateway-web.pl'; +use LJ::Emailpost::Web; require 'ljemailgateway.pl'; use LJ::Test; use FindBin qw($Bin); @@ -32,7 +32,7 @@ like($msg, qr/No allowed senders have been saved for your account/, "rejected due to no allowed senders"); is($dequeue, 1, "and it's deqeueued"); -LJ::Emailpost::set_allowed_senders($u, { 'foo@example.com' => { get_errors => 1 } }); +LJ::Emailpost::Web::set_allowed_senders( $u, { 'foo@example.com' => { get_errors => 1 } } ); is($u->prop("emailpost_allowfrom"), "foo\@example.com(E)", "allowed sender set correctly"); --------------------------------------------------------------------------------