Skip to content

Commit 88e81ba

Browse files
authored
Merge pull request #842 from ikedas/issue-841 by ikedas
Addition to fixes for #831 (#833)
2 parents 42eb880 + a330f04 commit 88e81ba

File tree

2 files changed

+58
-39
lines changed

2 files changed

+58
-39
lines changed

doc/sympa_scenario.pod

+10-10
Original file line numberDiff line numberDiff line change
@@ -180,22 +180,22 @@ Default value is "nobody".
180180
=item C<[topic]>
181181

182182
Topic of the message.
183-
This variable has a value if any of the previous
184-
C<[topic-*]> variable has a value.
183+
This variable has a value if any of the following
184+
C<[topic_*]> variables has a value.
185185

186-
=item C<[topic-auto]>
186+
=item C<[topic_auto]>
187187

188188
Topic of the message if it has been automatically tagged.
189189

190-
=item C<[topic-editor]>
190+
=item C<[topic_editor]>
191191

192192
Topic of the message if it has been tagged by editor.
193193

194-
=item C<[topic-needed]>
194+
=item C<[topic_needed]>
195195

196196
The message has not got any topic and message topic are required for the list.
197197

198-
=item C<[topic-sender]>
198+
=item C<[topic_sender]>
199199

200200
Topic of the message if it has been tagged by sender.
201201

@@ -349,10 +349,10 @@ var : "[email]"
349349
| "[sender]"
350350
| "[subscriber->" subscriber_key_word "]"
351351
| "[topic]"
352-
| "[topic-auto]"
353-
| "[topic-editor]"
354-
| "[topic-needed]"
355-
| "[topic-sender]"
352+
| "[topic_auto]"
353+
| "[topic_editor]"
354+
| "[topic_needed]"
355+
| "[topic_sender]"
356356
| "[user->" user_key_word "]"
357357
| "[user_attributes->" user_attributes_keyword "]"
358358
| string

src/lib/Sympa/Scenario.pm

+48-29
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,7 @@ sub authz {
387387
$context->{'sender'} ||= 'nobody';
388388
$context->{'email'} ||= $context->{'sender'};
389389
$context->{'remote_host'} ||= 'unknown_host';
390-
$context->{'msg_encrypted'} = 'smime'
391-
if defined $context->{'message'}
392-
and $context->{'message'}->{'smime_crypted'};
393-
394-
$context->{'execution_date'} = time
395-
unless defined $context->{'execution_date'};
390+
$context->{'execution_date'} //= time;
396391

397392
if (ref $that eq 'Sympa::List') {
398393
foreach my $var (@{$that->{'admin'}{'custom_vars'} || []}) {
@@ -403,18 +398,6 @@ sub authz {
403398
$context->{domain} = $that->{'domain'};
404399
# Compat.<6.2.32
405400
$context->{host} = $that->{'domain'};
406-
407-
if ($context->{message}) {
408-
#FIXME: need more accurate test.
409-
$context->{is_bcc} = (
410-
0 <= index(
411-
lc join(', ',
412-
$context->{message}->get_header('To'),
413-
$context->{message}->get_header('Cc')),
414-
lc $that->{'name'}
415-
)
416-
) ? 0 : 1;
417-
}
418401
} else {
419402
$context->{domain} = Conf::get_robot_conf($that || '*', 'domain');
420403
}
@@ -585,9 +568,9 @@ sub _compile_scenario {
585568
if ($_ eq 'list_object') {
586569
$req = 'die "No list context" unless ref $that eq \'Sympa::List\';';
587570
} elsif ($_ eq 'message') {
588-
$req = sprintf '$context->{message} ||= Sympa::Message->new("\n");';
571+
$req = '$context->{message} ||= Sympa::Message->new("\n");';
589572
} else {
590-
$req = sprintf 'die "Missing parameter \'%s\'" unless exists $context->{%s};', $_, $_;
573+
$req = sprintf '$context->{\'%s\'} //= \'\';', $_;
591574
}
592575
" $req";
593576
} sort keys %required;
@@ -815,21 +798,35 @@ sub _compile_condition {
815798
$value =
816799
sprintf
817800
'(exists $context->{message}{%s} ? $context->{message}{%s} : undef)',
818-
$key;
801+
$key, $key;
802+
$required_keys{message} = 1;
803+
} elsif ($value =~ /\[is_bcc\]/i) {
804+
$value =
805+
'Sympa::Scenario::message_is_bcc($that, $context->{message})';
806+
$required_keys{list_object} = 1;
807+
$required_keys{message} = 1;
808+
} elsif ($value =~ /\[msg_encrypted\]/i) {
809+
$value =
810+
'Sympa::Scenario::message_encrypted($context->{message})';
811+
$required_keys{message} = 1;
812+
} elsif ($value =~ /\[(topic(?:_\w+)?)\]/i) {
813+
# Useful only with send scenario.
814+
my $key = $1;
815+
$value = sprintf '$context->{%s}', $key;
816+
$required_keys{$key} = 1;
819817
$required_keys{message} = 1;
820818
} elsif ($value =~ /\[current_date\]/i) {
821819
$value = 'time()';
820+
} elsif ($value =~ /\[listname\]/i) {
821+
# Context should be a List from which value will be taken.
822+
$value = '$that->{name}';
823+
$required_keys{list_object} = 1;
822824
} elsif ($value =~ /\[(\w+)\]/i) {
823-
# Quoted string
824825
my $key = $1;
825-
if ($key eq 'listname') {
826-
$value = sprintf '$that->{name}';
827-
$required_keys{list_object} = 1;
828-
} else {
829-
$value = sprintf '$context->{%s}', $key;
830-
$required_keys{$key} = 1;
831-
}
826+
$value = sprintf '$context->{%s}', $key;
827+
$required_keys{$key} = 1;
832828
} elsif ($value =~ /^'(.*)'$/ || $value =~ /^"(.*)"$/) {
829+
# Quoted string
833830
my $str = $1;
834831
$str =~ s{(\\.|.)}{($1 eq "'" or $1 eq "\\")? "\\\'" : $1}eg;
835832
$value = sprintf "'%s'", $str;
@@ -935,6 +932,28 @@ sub _compile_hashref {
935932
) . '}';
936933
}
937934

935+
sub message_is_bcc {
936+
my $that = shift;
937+
my $message = shift;
938+
939+
return '' unless $message;
940+
#FIXME: need more accurate test.
941+
return (
942+
0 <= index(
943+
lc join(', ',
944+
$message->get_header('To'),
945+
$message->get_header('Cc')),
946+
lc $that->{'name'}
947+
)
948+
) ? 0 : 1;
949+
}
950+
951+
sub message_encrypted {
952+
my $message = shift;
953+
954+
return ($message and $message->{smime_crypted}) ? 'smime' : '';
955+
}
956+
938957
sub safe_qr {
939958
my $re = shift;
940959
my $context = shift;

0 commit comments

Comments
 (0)