@@ -387,12 +387,7 @@ sub authz {
387
387
$context -> {' sender' } ||= ' nobody' ;
388
388
$context -> {' email' } ||= $context -> {' sender' };
389
389
$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 ;
396
391
397
392
if (ref $that eq ' Sympa::List' ) {
398
393
foreach my $var (@{$that -> {' admin' }{' custom_vars' } || []}) {
@@ -403,18 +398,6 @@ sub authz {
403
398
$context -> {domain } = $that -> {' domain' };
404
399
# Compat.<6.2.32
405
400
$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
- }
418
401
} else {
419
402
$context -> {domain } = Conf::get_robot_conf($that || ' *' , ' domain' );
420
403
}
@@ -585,9 +568,9 @@ sub _compile_scenario {
585
568
if ($_ eq ' list_object' ) {
586
569
$req = ' die "No list context" unless ref $that eq \' Sympa::List\' ;' ;
587
570
} elsif ($_ eq ' message' ) {
588
- $req = sprintf ' $context->{message} ||= Sympa::Message->new("\n");' ;
571
+ $req = ' $context->{message} ||= Sympa::Message->new("\n");' ;
589
572
} else {
590
- $req = sprintf ' die "Missing parameter \' %s \' " unless exists $context->{%s}; ' , $_ , $_ ;
573
+ $req = sprintf ' $context->{\' %s \' } //= \'\' ; ' , $_ ;
591
574
}
592
575
" $req " ;
593
576
} sort keys %required ;
@@ -815,21 +798,35 @@ sub _compile_condition {
815
798
$value =
816
799
sprintf
817
800
' (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;
819
817
$required_keys {message } = 1;
820
818
} elsif ($value =~ / \[ current_date\] /i ) {
821
819
$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;
822
824
} elsif ($value =~ / \[ (\w +)\] /i ) {
823
- # Quoted string
824
825
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;
832
828
} elsif ($value =~ / ^'(.*)'$ / || $value =~ / ^"(.*)"$ / ) {
829
+ # Quoted string
833
830
my $str = $1 ;
834
831
$str =~ s { (\\ .|.)} { ($1 eq "'" or $1 eq "\\ ")? "\\\' " : $1 } eg ;
835
832
$value = sprintf " '%s '" , $str ;
@@ -935,6 +932,28 @@ sub _compile_hashref {
935
932
) . ' }' ;
936
933
}
937
934
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
+
938
957
sub safe_qr {
939
958
my $re = shift ;
940
959
my $context = shift ;
0 commit comments