Commit f1418f42 authored by sikeda's avatar sikeda
Browse files

[dev] Refactoring: Now "verp" and "tracking" flags need not be stored into bulkmailer table.

- $message->{shelved}{tracking} attribute is set to indicate tracking is required.  Possible values are "verp", "dsn", "mdn" and "dsn+mdn".
- As a result, verp_bulkmailer and tracking_bulkmailer columns are no longer used.

ToDo: Migration of {shelved}{tracking} attributes during upgrade.



git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@11295 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent 70d9295d
......@@ -68,7 +68,7 @@ sub next {
my $limit_other = '';
## Only the first record found is locked, thanks to the "LIMIT 1" clause
$order =
'ORDER BY priority_message_bulkmailer ASC, priority_packet_bulkmailer ASC, delivery_date_bulkmailer ASC, reception_date_bulkmailer ASC, verp_bulkmailer ASC';
'ORDER BY priority_message_bulkmailer ASC, priority_packet_bulkmailer ASC, delivery_date_bulkmailer ASC, reception_date_bulkmailer ASC';
if ( $Conf::Conf{'db_type'} eq 'mysql'
or $Conf::Conf{'db_type'} eq 'Pg'
or $Conf::Conf{'db_type'} eq 'SQLite') {
......@@ -146,7 +146,6 @@ sub next {
robot_bulkmailer AS robot,
priority_message_bulkmailer AS priority_message,
priority_packet_bulkmailer AS priority_packet,
verp_bulkmailer AS verp, tracking_bulkmailer AS tracking,
reception_date_bulkmailer AS reception_date,
delivery_date_bulkmailer AS delivery_date
FROM bulkmailer_table
......@@ -275,23 +274,17 @@ sub store {
my $priority_message = $data{'priority_message'};
my $priority_packet = $data{'priority_packet'};
my $delivery_date = $data{'delivery_date'};
my $verp = $data{'verp'};
my $tracking = $data{'tracking'};
$tracking = '' unless (($tracking eq 'dsn') || ($tracking eq 'mdn'));
$verp = 0 unless ($verp);
my $tag_as_last = $data{'tag_as_last'};
my $tag_as_last = $data{'tag_as_last'};
Log::do_log(
'debug',
'(%s, <rcpts>, from=%s, robot=%s, listname=%s, priority_message=%s, delivery_date=%s, verp=%s, tracking=%s, last=%s)',
'(%s, <rcpts>, from=%s, robot=%s, listname=%s, priority_message=%s, delivery_date=%s, last=%s)',
$message,
$from,
$robot,
$listname,
$priority_message,
$delivery_date,
$verp,
$tracking,
$tag_as_last
);
......@@ -463,16 +456,14 @@ sub store {
packetid_bulkmailer, receipients_bulkmailer,
returnpath_bulkmailer,
robot_bulkmailer, listname_bulkmailer,
verp_bulkmailer, tracking_bulkmailer,
priority_message_bulkmailer,
priority_packet_bulkmailer, reception_date_bulkmailer,
delivery_date_bulkmailer)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)},
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)},
$messagekey, $msg_id,
$packetid, $rcptasstring,
$from,
$robot, $listname,
$verp, $tracking,
$priority_message,
$priority_for_packet, SDM::AS_DOUBLE($current_date),
$delivery_date
......@@ -567,7 +558,6 @@ sub store_test {
my $robot = 'notarobot';
my $listname = 'notalist';
my $priority_message = 9;
my $verp = 'on';
print "maxtest: $maxtest\n";
print "barmax: $barmax\n";
......
......@@ -305,17 +305,17 @@ my %full_db_struct = (
'doc' => '',
'order' => 7,
},
'verp_bulkmailer' => {
'struct' => 'int(1)',
'doc' =>
'A boolean to specify if VERP is requiered, in this cas return_path will be formated using verp form',
'order' => 8,
},
'tracking_bulkmailer' => {
'struct' => "enum('mdn','dsn')",
'doc' => 'Is DSN or MDM requiered when sending this message?',
'order' => 9,
},
#'verp_bulkmailer' => {
# 'struct' => 'int(1)',
# 'doc' =>
# 'A boolean to specify if VERP is requiered, in this case return_path will be formatted using VERP form',
# 'order' => 8,
#},
#'tracking_bulkmailer' => {
# 'struct' => "enum('mdn','dsn')",
# 'doc' => 'Is DSN or MDN requiered when sending this message?',
# 'order' => 9,
#},
#'merge_bulkmailer' => {
# 'struct' => 'int(1)',
# 'doc' =>
......
......@@ -831,15 +831,14 @@ sub update_stats {
return $stats->[0];
}
## Extract a set of rcpt for which verp must be use from a rcpt_tab.
## Input : percent : the rate of subscribers that must be threaded using
## verp
## xseq : the message sequence number
## @rcpt : a tab of emails
## return : a tab of rcpt for which rcpt must be use depending on the message
## sequence number, this way every subscriber is "verped" from time to time
## input table @rcpt is spliced : rcpt for which verp must be used
## are extracted from this table
# Extract a set of rcpt for which VERP must be use from a rcpt_tab.
# Input : percent : the rate of subscribers that must be threaded using VERP
# xseq : the message sequence number
# @rcpt : a tab of emails
# return : a tab of recipients for which recipients must be used depending on
# the message sequence number, this way every subscriber is "VERPed"
# from time to time input table @rcpt is spliced: recipients for
# which VERP must be used are extracted from this table
sub extract_verp_rcpt {
my $percent = shift;
my $xseq = shift;
......@@ -856,11 +855,9 @@ sub extract_verp_rcpt {
if ($percent =~ /^(\d+)\%/) {
$nbpart = 100 / $1;
} else {
Log::do_log(
'err',
'Wrong format for parameter extract_verp: %s. Can\'t process VERP',
$percent
);
Log::do_log('err',
'Wrong format for parameter: %s. Can\'t process VERP',
$percent);
return undef;
}
......@@ -1914,20 +1911,24 @@ sub distribute_msg {
}
## Prepare tracking if list config allow it
my $apply_tracking = 'off';
$apply_tracking = 'dsn'
if $self->{'admin'}{'tracking'}->{'delivery_status_notification'} eq
'on';
$apply_tracking = 'mdn'
if $self->{'admin'}{'tracking'}->{'message_delivery_notification'} eq
'on';
$apply_tracking = 'mdn'
if $self->{'admin'}{'tracking'}->{'message_delivery_notification'} eq
'on_demand'
and $message->get_header('Disposition-Notification-To');
if ($apply_tracking ne 'off') {
my @apply_tracking = ();
push @apply_tracking, 'dsn'
if tools::smart_eq(
$self->{'admin'}{'tracking'}->{'delivery_status_notification'}, 'on');
push @apply_tracking, 'mdn'
if tools::smart_eq(
$self->{'admin'}{'tracking'}->{'message_delivery_notification'}, 'on')
or (
tools::smart_eq(
$self->{'admin'}{'tracking'}->{'message_delivery_notification'},
'on_demand')
and $message->get_header('Disposition-Notification-To')
);
if (@apply_tracking) {
$message->{shelved}{tracking} = join '+', @apply_tracking;
# remove notification request becuse a new one will be inserted if
# needed
$message->delete_header('Disposition-Notification-To');
......@@ -2046,8 +2047,7 @@ sub distribute_msg {
}
## Blindly send the message to all users.
my $numsmtp =
$self->send_msg($message, 'apply_tracking' => $apply_tracking);
my $numsmtp = $self->send_msg($message);
$self->savestats() if (defined($numsmtp));
return $numsmtp;
......@@ -2604,8 +2604,8 @@ sub send_file {
and
Conf::get_robot_conf($self->{'domain'}, 'dkim_add_signature_to')
=~ /robot/;
# use verp excepted for alarms. We should make this configurable in order
# to support Sympa server on a machine without any MTA service
# Use VERP excepted for alarms. We should make this configurable in order
# to support Sympa server on a machine without any MTA service.
my $use_bulk = 1 unless $data->{'alarm'};
unless (
......@@ -2647,8 +2647,6 @@ sub send_msg {
my $message = shift;
my %param = @_;
my $apply_tracking = $param{'apply_tracking'};
my $original_message_id = $message->{'message_id'};
my $robot = $self->{'domain'};
my $admin = $self->{'admin'};
......@@ -2679,15 +2677,15 @@ sub send_msg {
# prepare verp parameter
my $verp_rate = $self->{'admin'}{'verp_rate'};
# force verp if tracking is requested.
# force VERP if tracking is requested.
$verp_rate = '100%'
if (($apply_tracking eq 'dsn') || ($apply_tracking eq 'mdn'));
if tools::smart_eq($message->{shelved}{tracking}, qr/dsn|mdn/);
my $xsequence = $self->{'stats'}->[0];
my $tags_to_use;
# Define messages which can be tagged as first or last according to the
# verp rate.
# VERP rate.
# If the VERP is 100%, then all the messages are VERP. Don't try to tag
# not VERP
# messages as they won't even exist.
......@@ -2699,7 +2697,7 @@ sub send_msg {
$tags_to_use->{'tag_noverp'} = 0;
}
# Separate subscribers depending on user reception option and also if verp
# Separate subscribers depending on user reception option and also if VERP
# a dicovered some bounce for them.
# Storing the not empty subscribers' arrays into a hash.
my $available_recipients = $self->get_recipients_per_mode($message);
......@@ -2740,20 +2738,18 @@ sub send_msg {
my @verp_selected_tabrcpt =
extract_verp_rcpt($verp_rate, $xsequence, \@selected_tabrcpt,
\@possible_verptabrcpt);
my $verp = 'off';
if ($#selected_tabrcpt > -1) {
my $result = Sympa::Mail::mail_message(
'message' => $new_message,
'rcpt' => \@selected_tabrcpt,
'list' => $self,
'verp' => 'off',
'tag_as_last' => $tags_to_use->{'tag_noverp'}
);
unless (defined $result) {
Log::do_log(
'err',
'Could not send message to distribute from %s (verp desabled)',
'Could not send message to distribute from %s (VERP disabled)',
$from
);
return undef;
......@@ -2769,10 +2765,9 @@ sub send_msg {
);
}
$verp = 'on';
$new_message->{shelved}{tracking} ||= 'verp';
if (($apply_tracking eq 'dsn') || ($apply_tracking eq 'mdn')) {
$verp = $apply_tracking;
if ($new_message->{shelved}{tracking} =~ /dsn|mdn/) {
Sympa::Tracking::db_init_notification_table(
'listname' => $self->{'name'},
'robot' => $robot,
......@@ -2798,13 +2793,12 @@ sub send_msg {
'message' => $new_message,
'rcpt' => \@verp_selected_tabrcpt,
'list' => $self,
'verp' => 'on',
'tag_as_last' => $tags_to_use->{'tag_verp'}
);
unless (defined $result) {
Log::do_log(
'err',
'Could not send message to distribute from %s (verp enabled)',
'Could not send message to distribute from %s (VERP enabled)',
$from
);
return undef;
......
......@@ -91,8 +91,6 @@ sub set_send_spool {
# IN : -$message(+) : ref(Sympa::Message)
# -$from(+) : message from
# -$robot(+) : robot
# -{verp=>[on|off]} : a hash to introduce verp parameters, starting just
# on or off, later will probably introduce optionnal parameters
# -@rcpt(+) : recepients
# OUT : -$numsmtp : number of sendmail process | undef
#
......@@ -102,7 +100,6 @@ sub mail_message {
my %params = @_;
my $message = $params{'message'};
my $list = $params{'list'};
my $verp = $params{'verp'};
my @rcpt = @{$params{'rcpt'}};
my $tag_as_last = $params{'tag_as_last'};
......@@ -113,17 +110,17 @@ sub mail_message {
return undef;
}
# normal return_path (ie used if verp is not enabled)
# normal return_path (ie used if VERP is not enabled)
my $from = $list->get_list_address('return_path');
Log::do_log(
'debug',
'(from: %s, file:%s, %s, verp->%s, %d rcpt, last: %s)',
'(%s, from=%s, filename=%s, smime_crypted=%s, rcpt=%d, last=%s)',
$message,
$from,
$message->{'filename'},
$message->{'smime_crypted'},
$verp,
$#rcpt + 1,
scalar(@rcpt),
$tag_as_last
);
return 0 unless @rcpt;
......@@ -224,7 +221,6 @@ sub mail_message {
'robot' => $robot,
'encrypt' => $message->{'smime_crypted'},
'use_bulk' => 1,
'verp' => $verp,
'tag_as_last' => $tag_as_last
)
);
......@@ -317,7 +313,6 @@ sub reaper {
# $listname : use only to format return_path if VERP on
# $robot(+) : robot
# $encrypt : 'smime_crypted' | undef
# $verp : 1| undef
# $use_bulk : if defined, send message using bulk
#
# OUT : 1 - call to sending
......@@ -333,17 +328,16 @@ sub sendto {
my $robot = $params{'robot'};
my $priority = $params{'priority'};
my $encrypt = $params{'encrypt'};
my $verp = $params{'verp'};
my $use_bulk = $params{'use_bulk'};
my $tag_as_last = $params{'tag_as_last'};
Log::do_log(
'debug',
'(from: %s, listname: %s, encrypt: %s, verp: %s, priority = %s, last: %s, use_bulk: %s',
'(%s, from=%s, listname=%s, encrypt=%s, priority=%s, last=%s, use_bulk=%s',
$message,
$from,
$listname,
$encrypt,
$verp,
$priority,
$tag_as_last,
$use_bulk
......@@ -401,7 +395,6 @@ sub sendto {
$message, $rcpt, $from,
'priority' => $priority,
'delivery_date' => $delivery_date,
'verp' => $verp,
'use_bulk' => $use_bulk,
'tag_as_last' => $tag_as_last
);
......@@ -423,7 +416,6 @@ sub sendto {
# -$from: for SMTP, "MAIL From:" field; for spool sending, "X-Sympa-From"
# field
# -sign_mode => mode: 'smime' for signing
# -verp => 'on' | 'mdn' | 'dsn' | undef
# -use_bulk => boolean
#
# OUT : 1 - call to smtpto (sendmail) | 0 - push in spool
......@@ -454,7 +446,6 @@ sub sending {
Conf::get_robot_conf($robot_id, 'sympa_packet_priority');
my $delivery_date = $params{'delivery_date'};
$delivery_date = time() unless ($delivery_date);
my $verp = $params{'verp'};
my $use_bulk = $params{'use_bulk'};
my $tag_as_last = $params{'tag_as_last'};
my $sympa_file;
......@@ -468,15 +459,6 @@ sub sending {
}
}
my $verpfeature =
($verp and ($verp eq 'on' or $verp eq 'mdn' or $verp eq 'dsn'));
my $trackingfeature;
if ($verp and ($verp eq 'mdn' or $verp eq 'dsn')) {
$trackingfeature = $verp;
} else {
$trackingfeature = '';
}
if ($use_bulk) {
# in that case use bulk tables to prepare message distribution
my $bulk_code = Sympa::Bulk::store(
......@@ -488,8 +470,6 @@ sub sending {
'priority_message' => $priority_message,
'priority_packet' => $priority_packet,
'delivery_date' => $delivery_date,
'verp' => $verpfeature,
'tracking' => $trackingfeature,
'tag_as_last' => $tag_as_last,
);
......
......@@ -157,7 +157,12 @@ sub new {
} elsif ($k eq 'X-Sympa-Spam-Status') { # New in 6.2a.41
$self->{'spam_status'} = $v;
} elsif ($k eq 'X-Sympa-Shelved') { # New in 6.2a.41
$self->{'shelved'} = {map { ($_ => 1) } split /\s*,\s*/, $v};
$self->{'shelved'} = {
map {
my ($ak, $av) = split /=/, $_, 2;
($ak => ($av || 1))
} split(/\s*;\s*/, $v)
};
} else {
Log::do_log('err', 'Unknown meta information: "%s: %s"', $k, $v);
}
......@@ -719,7 +724,15 @@ sub to_string {
}
if (defined $self->{'shelved'} and %{$self->{'shelved'}}) {
$serialized .= sprintf "X-Sympa-Shelved: %s\n",
join(',',
join('; ',
map {
my $v = $self->{shelved}{$_};
if ("$v" eq '1') {
$_;
} else {
sprintf '%s=%s', $_, $v;
}
}
grep { $self->{shelved}{$_} }
sort keys %{$self->{shelved}});
}
......@@ -3112,8 +3125,16 @@ sub get_id {
my $shelved;
if (%{$self->{shelved} || {}}) {
$shelved = sprintf 'shelved=%s',
join(',',
$shelved = sprintf 'shelved:%s',
join(';',
map {
my $v = $self->{shelved}{$_};
if ("$v" eq '1') {
$_;
} else {
sprintf '%s=%s', $_, $v;
}
}
grep { $self->{shelved}{$_} }
sort keys %{$self->{shelved}});
}
......
......@@ -148,7 +148,7 @@ sub send_global_file {
if Conf::get_robot_conf($robot, 'dkim_feature') eq 'on'
and Conf::get_robot_conf($robot, 'dkim_add_signature_to') =~
/robot/;
# use verp excepted for alarms. We should make this configurable in order
# use VERP excepted for alarms. We should make this configurable in order
# to support Sympa server on a machine without any MTA service
my $use_bulk = 1 unless $data->{'alarm'};
......
......@@ -438,19 +438,13 @@ while (!$end) {
# ---
# If the DSN notification is correct and the tracking mode is enable,
# it will be inserted in the database
my $tracking_in_use;
$tracking_in_use = 1
if (
$list->{'admin'}{'tracking'}{'delivery_status_notification'} eq
"on");
$tracking_in_use = 1
if (
$list->{'admin'}{'tracking'}{'message_delivery_notification'} eq
"on");
$tracking_in_use = 1
if (
$list->{'admin'}{'tracking'}{'message_delivery_notification'} eq
"on_demand");
my $tracking_in_use = 1
if tools::smart_eq(
$list->{'admin'}{'tracking'}{'delivery_status_notification'},
'on')
or tools::smart_eq(
$list->{'admin'}{'tracking'}{'message_delivery_notification'},
qr/\A(on|on_demand)\z/);
my $eff_type = $entity->effective_type || '';
my $report_type =
......@@ -596,15 +590,14 @@ while (!$end) {
}
}
# ---
# If the MDN notification is correct and the tracking mode is enable,
# If the MDN notification is correct and the tracking mode is enabled,
# it will be inserted in the database
if ( $eff_type eq 'multipart/report'
and $report_type eq 'disposition-notification'
and ($list->{'admin'}{'tracking'}{'message_delivery_notification'}
eq "on"
or
$list->{'admin'}{'tracking'}{'message_delivery_notification'}
eq "on_demand")
and tools::smart_eq(
$list->{'admin'}{'tracking'}{'message_delivery_notification'},
qr/\A(on|on_demand)\z/
)
) {
my @parts = $entity->parts();
......@@ -1158,9 +1151,9 @@ sub canonicalize_status {
## update subscriber information
# $bouncefor : the email address the bounce is related for (may be extracted
# using verp)
# using VERP)
# $rcpt : the email address recognized in the bounce itself. In most case
# $rcpt eq $bouncefor
# $rcpt eq $bouncefor
sub update_subscriber_bounce_history {
......
......@@ -416,9 +416,7 @@ while (!$end) {
}
if ( $message->{shelved}{merge}
or $bulk->{'verp'}
or $bulk->{'tracking'} eq 'dsn'
or $bulk->{'tracking'} eq 'mdn') {
or $message->{shelved}{tracking}) {
# message needs personalization
my $key;
......@@ -428,8 +426,10 @@ while (!$end) {
my $notification_id;
my $return_path;
if ( $bulk->{'tracking'} eq 'dsn'
or $bulk->{'tracking'} eq 'mdn') {
if (tools::smart_eq(
$new_message->{shelved}{tracking}, qr/dsn|mdn/
)
) {
# tracking by MDN required tracking by DSN to
my $msgid = $new_message->{'message_id'};
$notification_id =
......@@ -439,7 +439,7 @@ while (!$end) {
$list->get_bounce_address($rcpt, $notification_id);
$new_message->replace_header(
'Disposition-Notification-To', $return_path)
if $bulk->{'tracking'} eq 'mdn';
if $new_message->{shelved}{tracking} =~ /mdn/;
# trace_smime($new_message, 'tracking');
} else { # VERP
$return_path = $list->get_bounce_address($rcpt);
......
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