Skip to Content.
Sympa Menu

en - Re: [sympa-users] Scenario condition message variables: lessons learned

Subject: The mailing list for listmasters using Sympa

List archive

Chronological Thread  
  • From: David Verdin <address@concealed>
  • To: Thomas Berry <address@concealed>
  • Cc: "address@concealed" <address@concealed>
  • Subject: Re: [sympa-users] Scenario condition message variables: lessons learned
  • Date: Fri, 13 Nov 2009 17:38:25 +0100

Hi Thomas,

Sorry for this late answer. It's a good tip. I added - almost verbatim - to the Sympa user's manual: https://www.sympa.org/manual/authorization-scenarios#how_to_use_message_related_variables_within_scenario_rule_conditions

Thanks for that contribution!

Regards,

David

Thomas Berry a écrit :
Correction:

The scenario INCLUDE rule works. The include rules didn't work in my initial testing for the same reasons the rules weren't working in the main rule. The include works when it contains two rules: one with msg_body and with msg_part->body.

Thomas

Thomas Berry wrote:
I have finally sorted out how to use message related variables (vars) within scenario rule conditions.

Scenario condition, message vars include:
[msg_body]
[msg_part->body]


When creating scenario rules that evaluate message content, two rules must be created when passing the contents of a message to a condition: one rule for plain text messages (msg_body) and a second rule for multi-part MIME messages (msg_part).

For example, I wrote a CustomCondition module that parses the URLs in a message and compares them with a list of approved URLs:

(send.url_eval)

title.us Moderated with URL verification
CustomCondition::urlreview([listname],[sender],[msg_body]) smtp,smime,md5 -> reject()
CustomCondition::urlreview([listname],[sender],[msg_part->body]) smtp,smime,md5 -> reject()
true() smtp,smime,md5 -> editorkey

The CustomCondition module returns undef if the message contents are not provided by the rule. If the message contents are multi-part MIME, then the [msg_body] passed by the first rule is undefined, and the CustomCondition module returns undef causing the scenario to move on to the next rule which passes the parts of the multi-part MIME message to the module.


As for the CustomCondition module, it was written to evaluate both plain text (SCALAR) and multi-part MIME (ARRAY reference) being passed to the condition:

(urlreview.pm)

package CustomCondition::urlreview;
...
sub verify {
my $listname = shift or return;
my $sender = shift or return;
my $body;
foreach my $part (@_) {
$body .= ref $part eq "ARRAY" ? join " ", @{$part} : $part;
}
return unless defined $body;
...
}
...
1;


Scenario INCLUDE rule option:

Another thing to keep in mind when developing send rules that parse message content is that these rules must be added directly to the parent send scenario; when I was testing, it appears that the message vars (msg_body|msg_part) were not available to rules added to a scenario using the "include" [rule] option.

Thomas


--
David Verdin
Comité réseau des universités



  • Re: [sympa-users] Scenario condition message variables: lessons learned, David Verdin, 11/13/2009

Archive powered by MHonArc 2.6.19+.

Top of Page