Commit eb78c965 authored by sikeda's avatar sikeda
Browse files

[-dev] Refactoring. Sympa::Message::decorate() was obsoleted. ...

[-dev] Refactoring.  Sympa::Message::decorate() was obsoleted.  Sympa::Message::test_personalize() was moved to Sympa::Spindle::AuthorizeMessage::_test_personalize() only where it is used.


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@12578 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent 1be67193
......@@ -10140,7 +10140,7 @@ sub do_send_me {
Sympa::Spindle::TransformOutgoing->post_archive($message); #FIXME
 
# Add footer/header.
$message->decorate;
$message->prepare_message_according_to_mode('mail', $list);
 
# Shelve DMARC protection.
$message->{shelved}{dmarc_protect} = 1
......@@ -21655,7 +21655,7 @@ sub do_send_mail {
# Since some users may send message to themselves to test message
# decoration and/or personalization, add such processing.
# - Add footer / header.
$u_message->decorate;
$u_message->prepare_message_according_to_mode('mail', $list);
# - Shelve personalization.
$u_message->{shelved}{merge} = 1
if Sympa::Tools::Data::smart_eq($list->{'admin'}{'merge_feature'},
......
......@@ -1754,38 +1754,8 @@ sub _merge_msg {
return $entity;
}
sub test_personalize {
my $self = shift;
my $list = shift;
return 1
unless Sympa::Tools::Data::smart_eq($list->{'admin'}{'merge_feature'},
'on');
# Get available recipients to test.
my $available_recipients = $list->get_recipients_per_mode($self) || {};
# Always test all available reception modes using sender.
foreach my $mode ('mail',
grep { $_ and $_ ne 'nomail' and $_ ne 'not_me' }
@{$list->{'admin'}{'available_user_options'}->{'reception'} || []}) {
push @{$available_recipients->{$mode}{'verp'}}, $self->{'sender'};
}
foreach my $mode (sort keys %$available_recipients) {
my $message = $self->dup;
$message->prepare_message_according_to_mode($mode, $list);
foreach my $rcpt (
@{$available_recipients->{$mode}{'verp'} || []},
@{$available_recipients->{$mode}{'noverp'} || []}
) {
unless ($message->personalize($list, $rcpt, {})) {
return undef;
}
}
}
return 1;
}
# Moved to Sympa::Spindle::AuthorizeMessage::_test_personalize().
#sub test_personalize;
# Old name: Bulk::merge_data()
sub personalize_text {
......@@ -1902,15 +1872,11 @@ sub prepare_message_according_to_mode {
return $self;
}
# OBSOLETED. Use prepare_message_according_to_mode('mail').
sub decorate {
my $self = shift;
my $list = $self->{context};
return undef unless ref($self->{context}) eq 'Sympa::List';
my $entity = $self->as_entity->dup;
_decorate_parts($entity, $list);
$self->set_entity($entity);
return $self->prepare_message_according_to_mode('mail', $self->{context});
}
# Old name:
......@@ -4161,6 +4127,9 @@ Modified message itself, or C<undef> if error occurred.
=item test_personalize ( $list )
DEPRECATED by Sympa 6.2.13.
No longer available.
I<Instance method>.
Tests if personalization can be performed successfully over all subscribers
of list.
......@@ -4213,8 +4182,13 @@ C<'mail'>, C<'notice'>, C<'txt'> or C<'html'>.
By C<'nomail'>, C<'digest'>, C<'digestplain'> or C<'summary'> mode,
the message is not modified.
Returns modified message object itself, or C<undef> if transformation failed.
=item decorate ( )
OBSOLETED.
Use prepare_message_according_to_mode('mail', $list).
I<Instance method>.
Adds footer/header to a message.
......
......@@ -172,7 +172,7 @@ sub _twist {
}
# Check TT2 syntax for merge_feature.
unless ($message->test_personalize($list)) {
unless (_test_personalize($message, $list)) {
$log->syslog(
'err',
'Failed to personalize. Message %s for list %s was rejected',
......@@ -193,7 +193,7 @@ sub _twist {
and $action =~ /^request_auth\b/
) {
## Check syntax for merge_feature.
unless ($message->test_personalize($list)) {
unless (_test_personalize($message, $list)) {
$log->syslog(
'err',
'Failed to personalize. Message %s for list %s was rejected',
......@@ -209,7 +209,7 @@ sub _twist {
$self->{quiet} ||= ($action =~ /,\s*quiet\b/); # Overwrite
# Check syntax for merge_feature.
unless ($message->test_personalize($list)) {
unless (_test_personalize($message, $list)) {
$log->syslog(
'err',
'Failed to personalize. Message %s for list %s was rejected',
......@@ -225,7 +225,7 @@ sub _twist {
$self->{quiet} ||= ($action =~ /,\s*quiet\b/); # Overwrite
# Check syntax for merge_feature.
unless ($message->test_personalize($list)) {
unless (_test_personalize($message, $list)) {
$log->syslog(
'err',
'Failed to personalize. Message %s for list %s was rejected',
......@@ -310,6 +310,45 @@ sub _twist {
}
}
# Private subroutine.
# Tests if personalization can be performed successfully over all subscribers
# of list.
# Returns: 1 if succeed, or undef.
# Old name: Sympa::Message::test_personalize().
sub _test_personalize {
my $message = shift;
my $list = shift;
return 1
unless Sympa::Tools::Data::smart_eq($list->{'admin'}{'merge_feature'},
'on');
# Get available recipients to test.
my $available_recipients = $list->get_recipients_per_mode($message) || {};
# Always test all available reception modes using sender.
foreach my $mode ('mail',
grep { $_ and $_ ne 'nomail' and $_ ne 'not_me' }
@{$list->{'admin'}{'available_user_options'}->{'reception'} || []}) {
push @{$available_recipients->{$mode}{'verp'}}, $message->{'sender'};
}
foreach my $mode (sort keys %$available_recipients) {
my $new_message = $message->dup;
$new_message->prepare_message_according_to_mode($mode, $list);
foreach my $rcpt (
@{$available_recipients->{$mode}{'verp'} || []},
@{$available_recipients->{$mode}{'noverp'} || []}
) {
unless ($new_message->personalize($list, $rcpt, {})) {
return undef;
}
}
}
return 1;
}
1;
__END__
......
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