Commit 88ec2caa authored by sikeda's avatar sikeda
Browse files

[dev] Refactoring on Sympa::Bulk::store() and Sympa::Mail::sending().

- Now Sympa::Bulk::store() returns messagekey instead of "1" when it succeeded.
- Return-Path of outbound messages will be taken from {envelope_sender} attribute of the message object.
- Priority of them will be taken from {priority} item.
- {date} item is used for delivery date.
- use_bulk flag for Sympa::Mail::sending() was deprecated.  Sympa::Bulk::store() would be called directly.


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@11373 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent b2dd3382
......@@ -126,13 +126,8 @@ sub process {
unless $options{dry_run};
Log::do_log('info', '%s: Moved to msg spool', $message);
} else {
Sympa::Bulk::store(
$message,
rcpts => [split /\s*,\s*/, $message->{rcpt}],
priority_message => $message->{'priority'},
delivery_date => $message->{'date'},
tag_as_last => 1,
) unless $options{dry_run};
Sympa::Bulk::store($message, [split /\s*,\s*/, $message->{rcpt}])
unless $options{dry_run};
Log::do_log('info', '%s: Moved to bulk spool', $message);
}
return 1;
......
......@@ -10452,14 +10452,11 @@ sub do_send_me {
$message->delete_header('Resent-Sender');
$message->replace_header('X-no-archive', 'yes');
 
# Overwrite original envelope sender. It is REQUIRED for delivery.
$message->{envelope_sender} = $list->get_list_address('return_path');
unless (
defined Sympa::Mail::sending(
$message, $param->{'user'}{'email'},
$list->get_list_address('return_path'),
'priority' => $list->{'admin'}{'priority'},
use_bulk => 1
)
) {
defined Sympa::Bulk::store($message, $param->{'user'}{'email'})) {
$param->{'status'} = 'message_err';
wwslog(
'err',
......@@ -22295,14 +22292,11 @@ sub do_send_mail {
# In this case message will have "md5" authentication level.
# - Message bound for user will be injected into bulk spool.
if ($in{'sub_action'} eq 'sendmailtome') {
unless (
defined Sympa::Mail::sending(
$message, $to,
Conf::get_robot_conf($robot, 'sympa'),
'priority' => Conf::get_robot_conf($robot, 'sympa_priority'),
use_bulk => 1,
)
) {
#FIXME: envelope sender would be sympa-request address, isn't it?
$message->{envelope_sender} = Conf::get_robot_conf($robot, 'sympa');
$message->{priority} = Conf::get_robot_conf($robot, 'sympa_priority');
unless (defined Sympa::Bulk::store($message, $to)) {
Sympa::Report::reject_report_web(
'intern',
'cannot_send_mail',
......
......@@ -64,11 +64,14 @@ sub store {
{$email}}, $message->as_string;
return 1;
} else {
return Sympa::Mail::sending(
$message, $email,
Conf::get_robot_conf($robot_id, 'request'),
priority => Conf::get_robot_conf($robot_id, 'sympa_priority')
);
# Overwrite envelope sender
$message->{envelope_sender} =
Conf::get_robot_conf($robot_id, 'request');
#FIXME: Priority would better to be '0', isn't it?
$message->{priority} =
Conf::get_robot_conf($robot_id, 'sympa_priority');
return Sympa::Mail::sending($message, $email);
}
}
......@@ -122,16 +125,8 @@ sub flush {
Sympa::Message->new_from_template($robot_id,
'listmaster_groupednotifications',
$email, $param);
unless (
$message
and defined Sympa::Mail::sending(
$message,
$email,
Conf::get_robot_conf($robot_id, 'request'),
priority =>
Conf::get_robot_conf($robot_id, 'sympa_priority')
)
) {
unless ($message
and defined Sympa::Mail::sending($message, $email)) {
Log::do_log(
'notice',
'Unable to send template "listmaster_groupnotification" to %s listmaster %s',
......
......@@ -143,12 +143,12 @@ sub next {
receipients_bulkmailer AS recipients,
listname_bulkmailer AS listname,
robot_bulkmailer AS robot,
priority_message_bulkmailer AS priority_message,
priority_message_bulkmailer AS "priority",
priority_packet_bulkmailer AS priority_packet,
reception_date_bulkmailer AS reception_date,
delivery_date_bulkmailer AS delivery_date
delivery_date_bulkmailer AS "date"
FROM bulkmailer_table
WHERE lock_bulkmailer=? %s},
WHERE lock_bulkmailer = ? %s},
$order
),
$lock
......@@ -261,13 +261,10 @@ sub fetch_content {
sub store {
Log::do_log('debug2', '(%s, ...)', @_);
my $message = shift;
my $rcpt = shift;
my %data = @_;
my $rcpt = $data{'rcpts'};
my $priority_message = $data{'priority_message'};
my $priority_packet = $data{'priority_packet'};
my $delivery_date = $data{'delivery_date'};
my $tag_as_last = $data{'tag_as_last'};
my $tag_as_last = $data{'tag_as_last'};
my ($list, $robot_id);
if (ref $message->{context} eq 'Sympa::List') {
......@@ -279,24 +276,20 @@ sub store {
$robot_id = '*';
}
# Compatibility. Enclosed by <...>.
my $msg_id = '<' . $message->{'message_id'} . '>';
$priority_message ||= Conf::get_robot_conf($robot_id, 'sympa_priority');
$priority_packet ||=
my $priority_message = $message->{priority};
$priority_message =
$list
? $list->{admin}{priority}
: Conf::get_robot_conf($robot_id, 'sympa_priority')
unless defined $priority_message and length $priority_message;
my $priority_packet =
Conf::get_robot_conf($robot_id, 'sympa_packet_priority');
#creation of a MIME entity to extract the real sender of a message
my $parser = MIME::Parser->new();
$parser->output_to_core(1);
my $msg = $message->to_string;
my $message_sender = $message->{'sender'};
$msg = MIME::Base64::encode($msg);
my $delivery_date = $message->{date};
$delivery_date = time() unless defined $delivery_date;
##-----------------------------##
my $msg = MIME::Base64::encode($message->to_string);
my $messagekey = tools::md5_fingerprint($msg);
# first store the message in bulk_spool_table
......@@ -356,16 +349,16 @@ sub store {
# Ignore messages sent by robot or -request
# FIMXE: Is it effective?
unless (not $list
and $message_sender eq
and $message->{sender} eq
Conf::get_robot_conf($robot_id, 'sympa')
or $list
and $message_sender eq $list->get_list_address('owner')) {
and $message->{sender} eq $list->get_list_address('owner')) {
Log::db_stat_log(
{ 'robot' => $robot_id,
'list' => ($list ? $list->{'name'} : undef),
'operation' => 'send_mail',
'parameter' => length($msg),
'mail' => $message_sender,
'parameter' => $message->{size},
'mail' => $message->{sender},
'client' => '',
'daemon' => 'sympa.pl'
}
......@@ -391,7 +384,7 @@ sub store {
my $packet_rank = 0;
foreach my $packet (@rcpts) {
$priority_for_packet = $priority_packet;
if ($tag_as_last && !$already_tagged) {
if ($tag_as_last and not $already_tagged) {
$priority_for_packet = $priority_packet + 5;
$already_tagged = 1;
}
......@@ -471,7 +464,7 @@ sub store {
$messagekey);
return undef;
}
return 1;
return $messagekey;
}
# Old name: (part of) Sympa::Mail::mail_message().
......
......@@ -2232,7 +2232,6 @@ sub remind {
$global_info{$email}{'password'};
$context{'user'}{'gecos'} = $global_info{$email}{'gecos'};
@{$context{'lists'}} = @{$global_subscription{$email}};
$context{'use_bulk'} = 1; #Is it used?
#FIXME: needs VERP?
unless (
......
......@@ -2408,16 +2408,11 @@ sub send_dsn {
'diagnostic_code' => $diag,
}
);
$dsn_message->{envelope_sender} = '<>';
unless (
$dsn_message
and Sympa::Mail::sending(
$dsn_message, $sender, '<>',
#priority => ...,
use_bulk => 1
)
) {
if ($dsn_message) {
# Set envelope sender. DSN _must_ have null envelope sender.
$dsn_message->{envelope_sender} = '<>';
}
unless ($dsn_message and Sympa::Bulk::store($dsn_message, $sender)) {
Log::do_log('err', 'Unable to send DSN to %s', $sender);
return undef;
}
......@@ -2557,8 +2552,8 @@ sub send_msg {
);
return undef;
}
$tags_to_use->{'tag_noverp'} = 0 if ($result > 0);
$nbr_smtp += $result;
$tags_to_use->{'tag_noverp'} = 0 if $result;
$nbr_smtp++;
} else {
Log::do_log(
'notice',
......@@ -2603,9 +2598,9 @@ sub send_msg {
);
return undef;
}
$tags_to_use->{'tag_verp'} = 0 if ($result > 0);
$nbr_smtp += $result;
$nbr_verp += $result;
$tags_to_use->{'tag_verp'} = 0 if $result;
$nbr_smtp++;
$nbr_verp++;
} else {
Log::do_log(
'notice',
......@@ -2647,18 +2642,14 @@ sub _mail_message {
# if not specified, delivery time is right now (used for sympa messages
# etc.)
my $delivery_date =
$list->get_next_delivery_date
|| $message->{'date'}
|| time;
my $delivery_date = $list->get_next_delivery_date;
$message->{'date'} = $delivery_date if defined $delivery_date;
# Overwrite original envelope sender. It is REQUIRED for delivery.
$message->{envelope_sender} = $list->get_list_address('return_path');
return Sympa::Mail::sending(
$message, $rcpt, $list->get_list_address('return_path'),
'priority' => $list->{'admin'}{'priority'},
'delivery_date' => $delivery_date,
'use_bulk' => 1,
'tag_as_last' => $tag_as_last
) || undef;
return Sympa::Bulk::store($message, $rcpt, tag_as_last => $tag_as_last)
|| undef;
}
sub get_recipients_per_mode {
......@@ -3729,28 +3720,24 @@ sub send_probe_to_user {
my $who = shift;
my $message = Sympa::Message->new_from_template($self, $type, $who, {});
# Shelve VERP for welcome or remind message if necessary
if ( $self->{'admin'}{'welcome_return_path'} eq 'unique'
and $type eq 'welcome') {
$message->{shelved}{tracking} = 'w';
} elsif ($self->{'admin'}{'remind_return_path'} eq 'unique'
and $type eq 'remind') {
$message->{shelved}{tracking} = 'r';
} else {
#FIXME: Return-Path would be better to be -request address, isn't it?
$message->{envelope_sender} = $self->get_list_address('return_path');
if ($message) {
# Shelve VERP for welcome or remind message if necessary
if ( $self->{'admin'}{'welcome_return_path'} eq 'unique'
and $type eq 'welcome') {
$message->{shelved}{tracking} = 'w';
} elsif ($self->{'admin'}{'remind_return_path'} eq 'unique'
and $type eq 'remind') {
$message->{shelved}{tracking} = 'r';
} else {
#FIXME: Currently, Return-Path for '*_return_path' parameter with
# 'owner' value is LIST-owner address. LIST-request address would
# be better, isn't it?
}
#FIXME: Why overwrite priority?
$message->{priority} =
Conf::get_robot_conf($self->{'domain'}, 'sympa_priority');
}
unless (
$message
and defined Sympa::Mail::sending(
$message, $who, $self->get_list_address('return_path'),
'priority' =>
Conf::get_robot_conf($self->{'domain'}, 'sympa_priority'),
'use_bulk' => 1,
)
) {
unless ($message and defined Sympa::Bulk::store($message, $who)) {
Log::do_log('err', 'Could not send template %s to %s', $type, $who);
return undef;
}
......
......@@ -119,9 +119,8 @@ sub reaper {
#
# IN : -$message: ref(Sympa::Message) - message to be sent
# -$rcpt: SCALAR | ref(ARRAY) - recipients for SMTP "RCPT To:" field.
# -$from: for SMTP, "MAIL From:" field; for spool sending, "X-Sympa-From"
# field
# -use_bulk => boolean
# -$message->{envelope_sender}: for SMTP, "MAIL From:" field; for spool
# sending, "Return-Path" field
#
# OUT : 1 - call to smtpto (sendmail) | 0 - push in spool
# | undef
......@@ -130,7 +129,6 @@ sub reaper {
sub sending {
my $message = shift;
my $rcpt = shift;
my $from = shift;
my %params = @_;
my $that = $message->{context};
......@@ -144,31 +142,13 @@ sub sending {
$robot_id = '*';
}
my $priority_message = $params{'priority'};
my $priority_packet =
Conf::get_robot_conf($robot_id, 'sympa_packet_priority');
my $delivery_date = $params{'delivery_date'};
$delivery_date = time() unless ($delivery_date);
my $use_bulk = $always_use_bulk || $params{'use_bulk'};
my $tag_as_last = $params{'tag_as_last'};
my $sympa_file;
my $fh;
if ($use_bulk) {
if ($always_use_bulk) {
# in that case use bulk tables to prepare message distribution
$message->{envelope_sender} = $from;
my $bulk_code = Sympa::Bulk::store(
$message,
'rcpts' => $rcpt,
'priority_message' => $priority_message,
'priority_packet' => $priority_packet,
'delivery_date' => $delivery_date,
'tag_as_last' => $tag_as_last,
);
unless (defined $bulk_code) {
unless (defined Sympa::Bulk::store($message, $rcpt)) {
Log::do_log('err', 'Failed to store message %s for %s',
$message, $that);
tools::send_notify_to_listmaster(
......@@ -182,7 +162,7 @@ sub sending {
}
} else { # send it now
Log::do_log('debug', "NOT USING BULK");
*SMTP = smtpto($from, $rcpt, $robot_id);
*SMTP = smtpto($message->{envelope_sender}, $rcpt, $robot_id);
# Send message stripping Return-Path pseudo-header field.
my $msg_string = $message->as_string;
......@@ -204,7 +184,7 @@ sub sending {
# descriptor in the smtp table which can be imported by other parties.
# Before, waits for number of children process < number allowed by sympa.conf
#
# IN : $from :(+) for SMTP "MAIL From:" field
# IN : $return_path :(+) for SMTP "MAIL From:" field
# $rcpt :(+) ref(SCALAR)|ref(ARRAY)- for SMTP "RCPT To:" field
# $robot :(+) robot
# $envid : an ID of this message submission in notification table
......@@ -215,16 +195,16 @@ sub sending {
# TODO: Split rcpt by max length of command line (_SC_ARG_MAX).
sub smtpto {
Log::do_log('debug2', '(%s, %s, %s, %s)', @_);
my ($from, $rcpt, $robot, $envid) = @_;
my ($return_path, $rcpt, $robot, $envid) = @_;
unless ($from) {
unless ($return_path) {
Log::do_log('err', 'Missing Return-Path');
}
if (ref($rcpt) eq 'SCALAR') {
Log::do_log('debug3', '(%s, %s)', $from, $$rcpt);
Log::do_log('debug3', '(%s, %s)', $return_path, $$rcpt);
} elsif (ref($rcpt) eq 'ARRAY') {
Log::do_log('debug3', '(%s, %s)', $from, join(',', @{$rcpt}));
Log::do_log('debug3', '(%s, %s)', $return_path, join(',', @{$rcpt}));
}
my ($pid, $str);
......@@ -261,18 +241,18 @@ sub smtpto {
close(OUT);
open(STDIN, "<&IN");
$from = '' if $from eq '<>'; # null sender
$return_path = '' if $return_path eq '<>'; # null sender
# Terminate options by "--" to prevent addresses beginning with "-"
# being treated as options.
if (!ref($rcpt)) {
exec $sendmail, @sendmail_args, '-f', $from, '--', $rcpt;
exec $sendmail, @sendmail_args, '-f', $return_path, '--', $rcpt;
} elsif (ref($rcpt) eq 'SCALAR') {
exec $sendmail, @sendmail_args, '-f', $from, '--', $$rcpt;
exec $sendmail, @sendmail_args, '-f', $return_path, '--', $$rcpt;
} elsif (ref($rcpt) eq 'ARRAY') {
exec $sendmail, @sendmail_args, '-f', $from, '--', @$rcpt;
exec $sendmail, @sendmail_args, '-f', $return_path, '--', @$rcpt;
}
exit 1; # Should never get there.
exit 1; # Should never get there.
}
if ($log_smtp) {
my $r;
......@@ -286,7 +266,7 @@ sub smtpto {
Log::do_log(
'debug3', 'safefork: %s %s -f \'%s\' -- %s',
$sendmail, join(' ', @sendmail_args),
$from, $r
$return_path, $r
);
}
unless (close(IN)) {
......
......@@ -1132,20 +1132,7 @@ sub send_file {
Sympa::Message->new_from_template($that, $tpl, $who, $context,
%options);
my $return_path;
if (ref $that eq 'Sympa::List') {
$return_path = $that->get_list_address('return_path');
} else {
$return_path = Conf::get_robot_conf($that || '*', 'request');
}
unless (
$message
and defined Sympa::Mail::sending(
$message, $who, $return_path,
#'priority' => Conf::get_robot_conf($robot_id, 'sympa_priority'),
'use_bulk' => 1,
)
) {
unless ($message and defined Sympa::Bulk::store($message, $who)) {
Log::do_log('err', 'Could not send template %s to %s', $tpl, $who);
return undef;
}
......
......@@ -377,8 +377,8 @@ while (!$end) {
'Start sending message %s to %s (priority %s) (starting %s seconds after scheduled expedition date)',
$message,
$message->{context},
$message->{'priority_message'},
time() - $message->{'delivery_date'}
$message->{'priority'},
time() - $message->{'date'}
);
# trace_smime($message, 'init');
$messagekey = $bulk->{'messagekey'};
......@@ -596,8 +596,8 @@ while (!$end) {
'Done sending message %s to %s (priority %s) in %s seconds since scheduled expedition date',
$message,
($list || $robot),
$bulk->{'priority_message'},
time() - $bulk->{'delivery_date'}
$message->{'priority'},
time() - $message->{'date'}
);
}
$date_of_last_activity = time();
......
......@@ -2304,7 +2304,7 @@ sub DoForward {
my $listmasters = Conf::get_robot_conf($robot, 'listmasters');
@rcpt = @{$listmasters};
Log::do_log('notice', 'Warning: No listmaster defined in sympa.conf')
unless (@rcpt);
unless @rcpt;
} elsif ($function eq "owner") { # -request
@rcpt = $list->get_owners_email();
......@@ -2313,7 +2313,7 @@ sub DoForward {
'notice',
'Warning: No owner defined or all of them use nomail option in list %s',
$name
) unless (@rcpt);
) unless @rcpt;
} elsif ($function eq "editor") {
@rcpt = $list->get_editors_email();
......@@ -2322,11 +2322,11 @@ sub DoForward {
'notice',
'Warning: No owner and editor defined or all of them use nomail option in list %s',
$name
) unless (@rcpt);
) unless @rcpt;
}
## Did we find a recipient?
if ($#rcpt < 0) {
unless (@rcpt) {
if ($function ne "listmaster") {
Log::do_log(
'err',
......@@ -2342,7 +2342,7 @@ sub DoForward {
Log::do_log('notice',
'Warning: No owner defined at all in list %s', $name)
unless (@rcpt);
unless @rcpt;
} elsif ($function eq "editor") {
@rcpt = $list->get_editors_email({'ignore_nomail', 1});
......@@ -2351,11 +2351,11 @@ sub DoForward {
'notice',
'Warning: No owner and editor defined at all in list %s',
$name
) unless (@rcpt);
) unless @rcpt;
}
}
## Could we find a recipient by ignoring the "nomail" option?
if ($#rcpt >= 0) {
if (@rcpt) {
Log::do_log(
'notice',
'All the intended recipients of message %s in list %s have set the "nomail" option. Ignoring it and sending it to all of them',
......@@ -2414,13 +2414,12 @@ sub DoForward {
Conf::get_robot_conf($robot, 'request'));
$message->delete_header('Resent-Sender');
unless (
defined Sympa::Mail::sending(
$message, \@rcpt,
Conf::get_robot_conf($robot, 'request'),
'priority' => Conf::get_robot_conf($robot, 'request_priority')
)
) {
# Overwrite envelope sender. It is REQUIRED for delivery.
$message->{envelope_sender} = Conf::get_robot_conf($robot, 'request');
#FIXME: Why overwrite priority?
$message->{priority} = Conf::get_robot_conf($robot, 'request_priority');
unless (defined Sympa::Mail::sending($message, \@rcpt)) {
Log::do_log('err', 'Impossible to forward mail for %s function %s',
$name, $function);
my $string =
......
......@@ -1989,16 +1989,8 @@ sub process_bouncers {
};
my $message = Sympa::Message->new_from_template($list,
'automatic_bounce_management', $to, $param);
unless (
$message
and defined Sympa::Mail::sending(
$message, $rcpt,
$list->get_list_address('return_path'),
priority =>
Conf::get_robot_conf($robot_id, 'sympa_priority'),
use_bulk => 1
)
) {
unless ($message
and defined Sympa::Bulk::store($message, $rcpt)) {
Log::do_log(
'err',
'Unable to send template "automatic_bounce_management" to %s',
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment