Skip to Content.
Sympa Menu

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

Subject: The mailing list for listmasters using Sympa

List archive

Chronological Thread  
  • From: Thomas Berry <address@concealed>
  • To: "address@concealed" <address@concealed>
  • Subject: [sympa-users] Scenario condition message variables: lessons learned
  • Date: Tue, 27 Oct 2009 11:22:41 -0700

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



Archive powered by MHonArc 2.6.19+.

Top of Page