FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum Development » Plugins and Code Hacks » Pre-Filter Your Email List
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Pre-Filter Your Email List [message #33234] Sun, 20 August 2006 20:58
jeffrey is currently offline  jeffrey   United States
Messages: 36
Registered: June 2006
Location: Atlanta, GA
Karma: 0
Member
I have written a few pre-filters for the mailing list that can be chained together, to filter the emails before they are posted to the mailing list. I found the regular expressions a little too complex for the builtin regular expressions in the mailing list. So instead of calling the maillist.php directly from sendmail, I call my filter.php program(s) first that then feed the resulting filtered email to maillist.php.

Here's how it works.

1. Check how to call a different program as a particular user (NOBODY) at http://fudforum.org/forum/index.php?t=msg&goto=33233&#msg_33233
you may not need this at all it just makes it easier for me.

Instead of the example I gave there, I actually modify that a little to call my filter program:
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#define NOBODY 99
main() {
   setuid(NOBODY);
   setgid(NOBODY);
   if(fork() == 0) {
      execl("/home/FUDforum/filter.php","/home/FUDforum/filter.php",(char *)NULL);
      exit(0);
   } else {
      exit(0);
   }
}


2. The filter.php program is the first in a possible chain of filters that are called. This filter replaces a series of email list footers with a single instance of the footer. Here is filter.php:
#!/usr/local/bin/php
<?php
// Filter this pattern out of the email and then hand it off to maillist.php
// _______________________________________________
// discuss mailing list
// discuss(at)itdiscuss(dot)org
// Mailing List: http://itdiscuss.org/mailman/listinfo/discuss
// Web Discussion Board: http://itdiscuss.org

$fp = @fopen("php://stdin","r");
$fpOut = @popen("/home/FUDforum/scripts/maillist.php 1","w");
$count = 0;
while(!feof($fp)) {
  $line = fgets($fp, 4096);
  $match = true;
  if(strncmp($line, "_______________________________________________", 46) == 0) {
    // Store in buffer in case we don't match and we need to print
    $buf = $line;
    // Get next four lines and see if they don't match
    for($i = 0; $i < 4; $i++) {
      if(!feof($fp)) {
        $line = fgets($fp, 4096);
        $buf = $buf . $line;
        switch($i) {
        case 0:
          if(strncmp("discuss mailing list", $line, 20) != 0) {
            $match = false;
            break;
          }
          break;
        case 1:
          if(strncmp("discuss(at)itdiscuss(dot)org", $line, 21) != 0) {
            $match = false;
            break;
          }
          break;
        case 2:
          if(strncmp("Mailing List: http://itdiscuss.org/mailman/listinfo/discuss", $line, 58) != 0) {
            $match = false;
            break;
          }
          break;
        case 3:
          if(strncmp("Web Discussion Board: http://itdiscuss.org", $line, 42) != 0) {
            $match = false;
            break;
          }
          break;
        }
      } else {
        break;
      }
    }
    if($match) {
      $count++;
      // print the pattern the first time and then skip the rest of them
      if($count == 1) {
        fputs($fpOut,$buf,4096);
      } else {
        // skip the pattern
      }
    } else {
      // didn't match, print buffer
      fputs($fpOut,$buf, 4096);
    }
  } else {
    fputs($fpOut,$line, 4096);
  }
}
fclose($fp);
fclose($fpOut);
?>


It's possible to call multiple filters and the last filter going to maillist.php. This example goes directly to maillist.php.

I actually use MailMan and use the same filter approach for the MailMan program as well, except for emails going to MailMan I remove every instance of the pattern since MailMan will add another one to the end of the new message being posted to the list.

[Updated on: Wed, 23 August 2006 14:12]

Report message to a moderator

  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: run_maillist.c : Run Mailling List As A Particular User (NOBODY)
Next Topic: SLAED CMS Integration
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 21:22:57 GMT 2024

Total time taken to generate the page: 0.01972 seconds