Commit 73f8d7af authored by sikeda's avatar sikeda
Browse files

[dev] Refactoring: merging send_file() and send_global_file().

Now send_file() was moved to tools.pm and will take list OR robot as parameter.
Exception is new method send_probe_to_user() to send welcome and remind messages using VERP.

As a side work, {shelved}{tracking} attribute of messages can be "w" or "r" by which bulk.pl generates VERP sender of messages stored by send_probe_to_user().


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@11332 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent 7aa29b27
......@@ -4806,7 +4806,8 @@ sub sendssopasswd {
$param->{'init_passwd'} = 1
if ($param->{'user'}{'password'} =~ /^init/);
 
Sympa::Robot::send_global_file('sendssopasswd', $email, $robot, $param);
#FIXME: check error
tools::send_file($robot, 'sendssopasswd', $email, $param);
 
$param->{'email'} = $email;
web_db_log(
......@@ -4922,11 +4923,8 @@ sub do_requestpasswd {
}
if ($param->{'one_time_ticket'}) {
$param->{'login_error'} = 'ticket_sent';
unless (
Sympa::Robot::send_global_file(
'sendpasswd', $in{'email'}, $robot, $param
)
) {
unless (tools::send_file($robot, 'sendpasswd', $in{'email'}, $param))
{
wwslog('notice', 'Unable to send template "sendpasswd" to %s',
$in{'email'});
$param->{'login_error'} = 'unable_to_send_ticket';
......@@ -6263,13 +6261,14 @@ sub do_subscribe {
 
unless ($sub_is =~ /quiet/i) {
unless (
$list->send_file(
'welcome', $param->{'user'}{'email'},
$robot, {}
$list->send_probe_to_user(
'welcome', $param->{'user'}{'email'}
)
) {
wwslog('notice',
"Unable to send template 'welcome' to $param->{'user'}{'email'}"
wwslog(
'notice',
'Unable to send "welcome" probe to %s',
$param->{'user'}{'email'}
);
}
}
......@@ -6493,11 +6492,8 @@ sub do_subrequest {
$param->{'newuser'}{'escaped_email'} =
tools::escape_chars($param->{'newuser'}{'email'});
}
unless (
Sympa::Robot::send_global_file(
'sendpasswd', $in{'email'}, $robot, $param
)
) {
unless (tools::send_file($robot, 'sendpasswd', $in{'email'}, $param))
{
wwslog('notice', 'Unable to send template "sendpasswd" to %s',
$in{'email'});
$param->{'login_error'} = 'unable_to_send_ticket';
......@@ -6566,8 +6562,8 @@ sub do_auto_signoff {
'ip' => $ip,
};
unless (
Sympa::Robot::send_global_file(
'user_notification', $in{'email'}, $robot, $tt2_param
tools::send_file(
$robot, 'user_notification', $in{'email'}, $tt2_param
)
) {
Log::do_log('notice',
......@@ -6604,8 +6600,8 @@ sub do_family_signoff_request {
'ip' => $ip,
};
unless (
Sympa::Robot::send_global_file(
'user_notification', $in{'email'}, $robot, $tt2_param
tools::send_file(
$robot, 'user_notification', $in{'email'}, $tt2_param
)
) {
Log::do_log('notice',
......@@ -6820,7 +6816,7 @@ sub unsubscribe {
];
 
unless (
$list->send_file('bye', $authenticated_email_address, $robot, {}))
tools::send_file($list, 'bye', $authenticated_email_address, {}))
{
wwslog('notice',
"Unable to send template 'bye' to $authenticated_email_address"
......@@ -6876,8 +6872,8 @@ sub do_sigrequest {
'email' => $in{'email'}
};
unless (
Sympa::Robot::send_global_file(
'user_notification', $in{'email'}, $robot, $tt2_param
tools::send_file(
$robot, 'user_notification', $in{'email'}, $tt2_param
)
) {
Log::do_log('notice',
......@@ -8269,9 +8265,8 @@ sub do_add {
push @added_users, $email;
 
unless ($in{'quiet'} || $add_is =~ /quiet/i) {
unless ($list->send_file('welcome', $email, $robot, {})) {
wwslog('err', 'Unable to send template "welcome" to %s',
$email);
unless ($list->send_probe_to_user('welcome', $email)) {
wwslog('err', 'Unable to send "welcome" probe to %s', $email);
}
}
}
......@@ -8425,7 +8420,7 @@ sub do_del {
$email, $param->{'list'});
 
unless ($in{'quiet'}) {
unless ($list->send_file('removed', $email, $robot, {})) {
unless (tools::send_file($list, 'removed', $email, {})) {
wwslog('notice', 'Unable to send template "removed" to %s',
$email);
}
......@@ -8861,8 +8856,8 @@ sub do_d_install_shared {
 
my $sender = $desc_hash{'email'};
unless (
$list->send_file(
'd_install_shared', $sender, $robot, \%context
tools::send_file(
$list, 'd_install_shared', $sender, \%context
)
) {
wwslog('notice',
......@@ -8911,8 +8906,8 @@ sub do_d_reject_shared {
$sender = $desc_hash{'email'};
 
unless (
$list->send_file(
'd_reject_shared', $sender, $robot, \%context
tools::send_file(
$list, 'd_reject_shared', $sender, \%context
)
) {
wwslog('notice',
......@@ -9036,9 +9031,9 @@ sub do_reject {
$context{'rejected_by'} = $param->{'user'}{'email'};
$context{'template_used'} = $in{'message_template'};
unless (
$list->send_file(
$in{'message_template'}, #FIXME
$rejected_sender, $robot, \%context
tools::send_file(
$list, $in{'message_template'}, #FIXME
$rejected_sender, \%context
)
) {
wwslog('notice',
......@@ -11194,13 +11189,12 @@ sub do_install_pending_list {
my @listmasters = split /\s*,\s*/,
Conf::get_robot_conf($robot, 'listmaster');
if ($in{'status'} eq 'open') {
unless ($list->send_file('list_created', \@listmasters, $robot, {})) {
unless (tools::send_file($list, 'list_created', \@listmasters, {})) {
wwslog('notice',
'Unable to send template "list_created" to listmaster');
}
} elsif ($in{'status'} eq 'closed') {
unless ($list->send_file('list_rejected', \@listmasters, $robot, {}))
{
unless (tools::send_file($list, 'list_rejected', \@listmasters, {})) {
wwslog('notice',
'Unable to send template "list_rejected" to listmaster');
}
......@@ -11213,8 +11207,8 @@ sub do_install_pending_list {
next unless ($i->{'email'});
if ($in{'status'} eq 'open') {
unless (
$list->send_file(
'list_created', $i->{'email'}, $robot, {}
tools::send_file(
$list, 'list_created', $i->{'email'}, {}
)
) {
wwslog('notice',
......@@ -11223,8 +11217,8 @@ sub do_install_pending_list {
}
} elsif ($in{'status'} eq 'closed') {
unless (
$list->send_file(
'list_rejected', $i->{'email'}, $robot, {}
tools::send_file(
$list, 'list_rejected', $i->{'email'}, {}
)
) {
wwslog('notice',
......@@ -21399,8 +21393,8 @@ sub do_change_email_request {
'to' => $in{'new_email'},
};
unless (
Sympa::Robot::send_global_file(
'user_notification', $in{'new_email'}, $robot, $tt2_param
tools::send_file(
$robot, 'user_notification', $in{'new_email'}, $tt2_param
)
) {
Log::do_log('notice',
......@@ -22310,7 +22304,7 @@ sub do_send_mail {
TextCharset => 'utf-8',
TextEncoding => '8bit',
HTMLEncoding => '8bit',
remove_jscript => '1', #delete the scripts in the html
remove_jscript => '1', #delete the scripts in the html
);
# parse return the MIME::Lite part to send
my $part = $mail_html->parse($page_source) if $mail_html;
......
......@@ -192,8 +192,7 @@ sub help {
$data->{'subject'} = $language->gettext("User guide");
$data->{'auto_submitted'} = 'auto-replied';
unless (
Sympa::Robot::send_global_file("helpfile", $sender, $robot, $data)) {
unless (tools::send_file($robot, "helpfile", $sender, $data)) {
Log::do_log('notice', 'Unable to send template "helpfile" to %s',
$sender);
Sympa::Report::reject_report_cmd('intern_quiet', '', {}, $cmd_line,
......@@ -273,7 +272,7 @@ sub lists {
$data->{'lists'} = $lists;
$data->{'auto_submitted'} = 'auto-replied';
unless (Sympa::Robot::send_global_file('lists', $sender, $robot, $data)) {
unless (tools::send_file($robot, 'lists', $sender, $data)) {
Log::do_log('notice', 'Unable to send template "lists" to %s',
$sender);
Sympa::Report::reject_report_cmd('intern_quiet', '', {}, $cmd_line,
......@@ -351,9 +350,9 @@ sub stats {
if ($action =~ /reject/i) {
if (defined $result->{'tt2'}) {
unless (
$list->send_file(
$result->{'tt2'}, $sender,
$robot, {'auto_submitted' => 'auto-replied'}
tools::send_file(
$list, $result->{'tt2'},
$sender, {'auto_submitted' => 'auto-replied'}
)
) {
Log::do_log('notice', 'Unable to send template "%s" to %s',
......@@ -379,9 +378,10 @@ sub stats {
);
unless (
$list->send_file(
tools::send_file(
$list,
'stats_report',
$sender, $robot,
$sender,
{ 'stats' => \%stats,
'subject' => "STATS $list->{'name'}", # compat <= 6.1.17.
'auto_submitted' => 'auto-replied'
......@@ -601,8 +601,8 @@ sub index {
my @l = $list->archive_ls();
unless (
$list->send_file(
'index_archive', $sender, $robot,
tools::send_file(
$list, 'index_archive', $sender,
{'archives' => \@l, 'auto_submitted' => 'auto-replied'}
)
) {
......@@ -704,9 +704,9 @@ sub review {
if ($action =~ /reject/i) {
if (defined $result->{'tt2'}) {
unless (
$list->send_file(
$result->{'tt2'}, $sender,
$robot, {'auto_submitted' => 'auto-replied'}
tools::send_file(
$list, $result->{'tt2'},
$sender, {'auto_submitted' => 'auto-replied'}
)
) {
Log::do_log('notice', 'Unable to send template "%s" to %s',
......@@ -745,8 +745,8 @@ sub review {
}
} while ($user = $list->get_next_list_member());
unless (
$list->send_file(
'review', $sender, $robot,
tools::send_file(
$list, 'review', $sender,
{ 'users' => \@users,
'total' => $list->get_total(),
'subject' => "REVIEW $listname", # Compat <= 6.1.17.
......@@ -919,9 +919,9 @@ sub subscribe {
if ($action =~ /reject/i) {
if (defined $result->{'tt2'}) {
unless (
$list->send_file(
$result->{'tt2'}, $sender,
$robot, {'auto_submitted' => 'auto-replied'}
tools::send_file(
$list, $result->{'tt2'},
$sender, {'auto_submitted' => 'auto-replied'}
)
) {
Log::do_log('notice', 'Unable to send template "%s" to %s',
......@@ -1061,9 +1061,9 @@ sub subscribe {
## Now send the welcome file to the user
unless ($quiet || ($action =~ /quiet/i)) {
unless ($list->send_file('welcome', $sender, $robot, {})) {
Log::do_log('notice',
'Unable to send template "welcome" to %s', $sender);
unless ($list->send_probe_to_user('welcome', $sender)) {
Log::do_log('notice', 'Unable to send "welcome" probe to %s',
$sender);
}
}
......@@ -1166,7 +1166,7 @@ sub info {
if ($action =~ /reject/i) {
if (defined $result->{'tt2'}) {
unless ($list->send_file($result->{'tt2'}, $sender, $robot, {})) {
unless (tools::send_file($list, $result->{'tt2'}, $sender, {})) {
Log::do_log('notice', 'Unable to send template "%s" to %s',
$result->{'tt2'}, $sender);
Sympa::Report::reject_report_cmd('auth', $result->{'reason'},
......@@ -1221,7 +1221,7 @@ sub info {
my $wwsympa_url = Conf::get_robot_conf($robot, 'wwsympa_url');
$data->{'url'} = $wwsympa_url . '/info/' . $list->{'name'};
unless ($list->send_file('info_report', $sender, $robot, $data)) {
unless (tools::send_file($list, 'info_report', $sender, $data)) {
Log::do_log('notice',
'Unable to send template "info_report" to %s', $sender);
Sympa::Report::reject_report_cmd('intern_quiet', '',
......@@ -1374,7 +1374,7 @@ sub signoff {
if ($action =~ /reject/i) {
if (defined $result->{'tt2'}) {
unless ($list->send_file($result->{'tt2'}, $sender, $robot, {})) {
unless (tools::send_file($list, $result->{'tt2'}, $sender, {})) {
Log::do_log('notice', 'Unable to send template "%s" to %s',
$result->{'tt2'}, $sender);
Sympa::Report::reject_report_cmd('auth', $result->{'reason'},
......@@ -1488,7 +1488,7 @@ sub signoff {
unless ($quiet || ($action =~ /quiet/i)) {
## Send bye file to subscriber
unless ($list->send_file('bye', $email, $robot, {})) {
unless (tools::send_file($list, 'bye', $email, {})) {
Log::do_log('notice', 'Unable to send template "bye" to %s',
$email);
}
......@@ -1586,7 +1586,7 @@ sub add {
if ($action =~ /reject/i) {
if (defined $result->{'tt2'}) {
unless ($list->send_file($result->{'tt2'}, $sender, $robot, {})) {
unless (tools::send_file($list, $result->{'tt2'}, $sender, {})) {
Log::do_log('notice', 'Unable to send template "%s" to %s',
$result->{'tt2'}, $sender);
Sympa::Report::reject_report_cmd('auth', $result->{'reason'},
......@@ -1669,9 +1669,9 @@ sub add {
## Now send the welcome file to the user if it exists and notification
## is supposed to be sent.
unless ($quiet || $action =~ /quiet/i) {
unless ($list->send_file('welcome', $email, $robot, {})) {
Log::do_log('notice',
'Unable to send template "welcome" to %s', $email);
unless ($list->send_probe_to_user('welcome', $email)) {
Log::do_log('notice', 'Unable to send "welcome" probe to %s',
$email);
}
}
......@@ -1782,7 +1782,7 @@ sub invite {
if ($action =~ /reject/i) {
if (defined $result->{'tt2'}) {
unless ($list->send_file($result->{'tt2'}, $sender, $robot, {})) {
unless (tools::send_file($list, $result->{'tt2'}, $sender, {})) {
Log::do_log('notice', 'Unable to send template "%s" to %s',
$result->{'tt2'}, $sender);
Sympa::Report::reject_report_cmd('auth', $result->{'reason'},
......@@ -1858,7 +1858,7 @@ sub invite {
$context{'subject'} = $command;
$context{'url'} = "mailto:$sympa?subject=$command";
$context{'url'} =~ s/\s/%20/g;
unless ($list->send_file('invite', $email, $robot, \%context))
unless (tools::send_file($list, 'invite', $email, \%context))
{
Log::do_log('notice',
'Unable to send template "invite" to %s', $email);
......@@ -1888,7 +1888,7 @@ sub invite {
$context{'subject'} = "sub $which $comment";
$context{'url'} = "mailto:$sympa?subject=$context{'subject'}";
$context{'url'} =~ s/\s/%20/g;
unless ($list->send_file('invite', $email, $robot, \%context))
unless (tools::send_file($list, 'invite', $email, \%context))
{
Log::do_log('notice',
'Unable to send template "invite" to %s', $email);
......@@ -1926,9 +1926,8 @@ sub invite {
);
if (defined $result->{'tt2'}) {
unless (
$list->send_file(
$result->{'tt2'},
$sender, $robot, {}
tools::send_file(
$list, $result->{'tt2'}, $sender, {}
)
) {
Log::do_log('notice',
......@@ -2073,7 +2072,7 @@ sub remind {
Log::do_log('info', 'Remind for list %s from %s refused',
$listname, $sender);
if (defined $result->{'tt2'}) {
unless ($list->send_file($result->{'tt2'}, $sender, $robot, {})) {
unless (tools::send_file($list, $result->{'tt2'}, $sender, {})) {
Log::do_log('notice', 'Unable to send template "%s" to %s',
$result->{'tt2'}, $sender);
......@@ -2135,12 +2134,11 @@ sub remind {
}
do {
unless (
$list->send_file('remind', $user->{'email'}, $robot, {}))
unless ($list->send_probe_to_user('remind', $user->{'email'}))
{
Log::do_log('notice',
"Unable to send template 'remind' to $user->{'email'}"
);
'Unable to send "remind" probe to %s',
$user->{'email'});
Sympa::Report::reject_report_cmd('intern_quiet', '',
{'listname' => $listname},
$cmd_line, $sender, $robot);
......@@ -2231,13 +2229,13 @@ sub remind {
$context{'user'}{'password'} =
$global_info{$email}{'password'};
$context{'user'}{'gecos'} = $global_info{$email}{'gecos'};
$context{'use_bulk'} = 1;
@{$context{'lists'}} = @{$global_subscription{$email}};
$context{'use_bulk'} = 1;
$context{'use_bulk'} = 1; #Is it used?
#FIXME: needs VERP?
unless (
Sympa::Robot::send_global_file(
'global_remind', $email, $robot, \%context
tools::send_file(
$robot, 'global_remind', $email, \%context
)
) {
Log::do_log('notice',
......@@ -2345,7 +2343,7 @@ sub del {
if ($action =~ /reject/i) {
if (defined $result->{'tt2'}) {
unless ($list->send_file($result->{'tt2'}, $sender, $robot, {})) {
unless (tools::send_file($list, $result->{'tt2'}, $sender, {})) {
Log::do_log('notice', 'Unable to send template "%s" to %s',
$result->{'tt2'}, $sender);
Sympa::Report::reject_report_cmd('auth', $result->{'reason'},
......@@ -2410,7 +2408,7 @@ sub del {
## Send a notice to the removed user, unless the owner indicated
## quiet del.
unless ($quiet || $action =~ /quiet/i) {
unless ($list->send_file('removed', $who, $robot, {})) {
unless (tools::send_file($list, 'removed', $who, {})) {
Log::do_log('notice',
'Unable to send template "removed" to %s', $who);
}
......@@ -2994,7 +2992,7 @@ sub confirm {
unless ($2 eq 'quiet') {
if (defined $result->{'tt2'}) {
unless (
$list->send_file($result->{'tt2'}, $sender, $robot, {})) {
tools::send_file($list, $result->{'tt2'}, $sender, {})) {
Log::do_log('notice',
"Commands::confirm(): Unable to send template '$result->{'tt2'}' to $sender"
);
......@@ -3208,8 +3206,8 @@ sub reject {
## Notify author of message
unless ($quiet) {
unless (
$list->send_file(
'reject', $rejected_sender, $robot, \%context
tools::send_file(
$list, 'reject', $rejected_sender, \%context
)
) {
Log::do_log('notice',
......@@ -3360,9 +3358,10 @@ sub modindex {
}
unless (
$list->send_file(
tools::send_file(
$list,
'modindex',
$sender, $robot,
$sender,
{ 'spool' => \@spool, #FIXME: Use msg_list.
'total' => $n,
'boundary1' => "==main $now[6].$now[5].$now[4].$now[3]==",
......@@ -3461,7 +3460,7 @@ sub which {
$data->{'is_editor'} = 1;
}
unless (Sympa::Robot::send_global_file('which', $sender, $robot, $data)) {
unless (tools::send_file($robot, 'which', $sender, $data)) {
Log::do_log('notice', 'Unable to send template "which" to %s',
$sender);
Sympa::Report::reject_report_cmd('intern_quiet', '',
......
......@@ -2175,9 +2175,9 @@ sub distribute_digest {
if (exists $available_recipients->{'digest'}) {
## Send digest
unless (
$self->send_file(
'digest', $available_recipients->{'digest'},
$robot, $param
tools::send_file(
$self, 'digest',
$available_recipients->{'digest'}, $param
)
) {
Log::do_log(
......@@ -2192,9 +2192,9 @@ sub distribute_digest {
if (exists $available_recipients->{'digestplain'}) {
## Send digest-plain
unless (
$self->send_file(
'digest_plain', $available_recipients->{'digestplain'},
$robot, $param
tools::send_file(
$self, 'digest_plain',
$available_recipients->{'digestplain'}, $param
)
) {
Log::do_log(
......@@ -2208,9 +2208,9 @@ sub distribute_digest {
## send summary
if (exists $available_recipients->{'summary'}) {
unless (
$self->send_file(
'summary', $available_recipients->{'summary'},
$robot, $param
tools::send_file(
$self, 'summary',
$available_recipients->{'summary'}, $param
)
) {
Log::do_log(
......@@ -2393,237 +2393,39 @@ sub send_dsn {
(eval { DateTime->now(time_zone => 'local') } || DateTime->now)
->strftime('%a, %{day} %b %Y %H:%M:%S %z');
unless (
_generic_send_file(
$that, 'dsn', $sender,
{ %$param,
'recipient' => $recipient,
'to' => $sender,
'date' => $date,
'header' => $header,
'auto_submitted' => 'auto-replied',
'action' => $action,
'status' => $status,
'diagnostic_code' => $diag,
'return_path' => '<>'
}
)
) {
Log::do_log('err', 'Unable to send DSN to %s', $sender);
return undef;
}
return 1;
}
# NOTE: send_file() and Sympa::Robot::send_global_file() should be merged.
sub _generic_send_file {
Log::do_log('debug2', '(%s, %s, %s, %s, %s)', @_);
my $that = shift;
my $tpl = shift;
my $who = shift;
my $param = shift;
my $options = shift;
if (ref $that eq 'Sympa::List') {
return $that->send_file($tpl, $who, $that->{'domain'}, $param);
} else {
return Sympa::Robot::send_global_file($tpl, $who, $that, $param,
$options);
}
}
####################################################
# send_file
####################################################
# Send a message to user(s), relative to a list.
# Find the tt2 file according to $tpl, set up
# $data for the next parsing (with $context and
# configuration)
# Message is signed if the list has a key and a
# certificate
#
# IN : -$self (+): ref(List)
# -$tpl (+): template file name (file.tt2),
# without tt2 extension
# -$who (+): SCALAR |ref(ARRAY) - recipient(s)
# -$robot (+): robot
# -$context : ref(HASH) - for the $data set up
# to parse file tt2, keys can be :
# -user : ref(HASH), keys can be :
# -email
# -lang
# -password
# -auto_submitted auto-generated|auto-replied|auto-forwarded
# -...
# OUT : 1 | undef
####################################################
sub send_file {
my ($self, $tpl, $who, $robot, $context) = @_;
Log::do_log('debug2', '(%s, %s, %s)', $tpl, $who, $robot);
my $data = tools::dup_var($context);
## Any recipients
if ( (ref($who) && ($#{$who} < 0))
|| (!ref($who) && ($who eq ''))) {
Log::do_log('err', 'No recipient for sending %s', $tpl);