index   home
Control script for a mailing list with semi-moderated policy

1. Abstract
   Here is a Perl script supporting semi-moderated policy of a mailing list. The semi-moderated policy is as follows:    This script, standing in front of the mailing list program, controls a posted message to be transferred to the mailing list program or to be sent to the mailing list manager. A message sent to the mailing list manager will be delivered when he/she approves it and then reposts it by forwarding.
   The mailing list is not supposed to aime at active discussion, so the mailing list program is not supposed to add the "Reply-To" field to each delivered message for directing replies to the mailing list.

2. Specification of the script
   This script transfers a posted message to the mailing list program for immediate delivery when it satisfies all the following conditions:
   Unless satisfying all these conditions, the posted message is sent to the mailing list manager. When he/she approves it and then reposts it by forwarding (removing attached files if necessary), it is delivered regardless of these conditions.
   This script regards the address in the "Resent-From" field, preceding the "From" field, as the poster's address, considering the use of the "Redirect" function of the mailer Becky!. This function enables forwarding without changing the "Date", "From", "To", "CC" and "Subject" fields and the text (but attached files in the multipart format are removable). When the mailing list manager reposts a posted message using this function, his/her address is recorded in the "Resent-From" field.
   If you worry that some mailing list member makes up the "To" field of a reply message against the policy, you can avoid immediate delivery by checking the existence of the "In-Reply-To" field. However, if you do so, a message of a new topic made by reply operation for quoting another message will not be delivered immediately. I don't recommend you to do so as long as no mailing list members are so malicious to be against the policy.

3. How to configure
   The mailing list address is assumed <society@example.jp>. The mailing list program is assumed Majordomo. The mailing list managers are assumed two members, whose addresses are <taro@example.jp> and <hanako@example.jp>. This script file is assumed /usr/local/ml-scripts/society (the directory position and the file name are any).
   In the /etc/aliases file, comment out the former alias definition of the mailing list, and specify this script instead. Replace the red parts into the actual mailing list name and mailing list manager's name(s).

Configuration of /etc/aliases
#society:            "|/usr/local/majordomo/wrapper resend -l society society-outgoing"
society:            "|/usr/local/ml-scripts/society"
society-outgoing:   :include:/usr/local/majordomo/lists/society
owner-society:      taro, hanako
society-request:    owner-society
society-owner:      owner-society

4. Script code
   Drag the following script code, copy and paste it to a file, and replace the red parts.
   In case the mailing list manager is only one, remove the second line including "$from =~ /.../ ||". In case the mailing list managers are plural, you can specify any members joining with the OR condition.
   In case you want to avoid strictly immediate delivery of reply messages, uncomment the commented line.
   The MTA (Mail Transfer Agent) is assumed sendmail or Postfix.

$/ = "";
$_ = $header = <STDIN>;
s/\n[ \t]+/ /g;
if (/(^|\n)Resent-From: (.*)/) {
  $from = $2;
elsif (/(^|\n)From: (.*)/) {
  $from = $2;
if (/(^|\n)To: (.*)/) {
  $to = $2;
$to =~ s/"[^"]*"//g;
if (/(^|\n)Content-Type: (.*)/) {
  $content_type = $2;
$/ = "\n";
$body = "";
while (<STDIN>) {
  $body .= $_;
if ($from =~ /\btaro\@example\.jp\b/ ||
    $from =~ /\bhanako\@example\.jp\b/ ||
    ($to =~ /^[^@]*\bsociety\@example\.jp\b[^@]*$/ &&
#     !($header =~ /(^|\n)In-Reply-To:/) &&
     !($content_type =~ /multipart\/mixed/) &&
     length($body) <= 30000)) {
  open(MAIL, "|/usr/local/majordomo/wrapper resend -l society society-outgoing");
  print MAIL "$header$body";
else {
  open(MAIL, "|/usr/lib/sendmail -oi -f owner-society\@example.jp owner-society\@example.jp");
  print MAIL "$header$body";

Note   Here I show Majordomo, which is widely used, as an example of a mailing list program although I don't use it. If you find any mistakes in the description, please notify me.

Remark   If the mailing list manager reposts a posted message using the "Redirect" function of the mailer Becky!, the delivered message will appear as if it is released from moderation by a mailing list program such as Majordomo, because its "Date", "From", "To", "CC" and "Subject" fields and text are not changed. However, even if you don't use Becky!, you can govern the semi-moderated policy with this script by usual forwarding. I recommend you to set the original poster's address in the "Reply-To" field and add the following explanation for example:
"Here is a message from Mr./Ms. Xxx. The attached file was carried on http://... The reply to this message will be directed to him/her."

index   home