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

Home » FUDforum Development » Plugins and Code Hacks » New Version of popfud.php
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
New Version of popfud.php [message #19834] Thu, 09 September 2004 14:58
Squeebee is currently offline  Squeebee   Canada
Messages: 110
Registered: November 2003
Karma:
Senior Member
Attached is the latest version of popfud.php. I decided that my last version was not versatile enough for my needs, and was more complex than it needed to be.

This new version uses regular expressions to match an email message to its list, which makes it much more versatile and also eliminated some of the massaging of the message headers.

I've attached the php file, and I'll include the code at the end of this message so you don't haave to download it to take a look.

<?php
#!/usr/local/php/bin/php -q
<?php
        
/******************************************************************************
        *    POPfud Version 0.2 - Copyright 2003 Mike Hillyer
        *
        *    This program is free software; you can redistribute it and/or modify
        *    it under the terms of the GNU General Public License as published by
        *    the Free Software Foundation; either version 2 of the License, or
        *    (at your option) any later version.
        *
        *    This program is distributed in the hope that it will be useful,
        *    but WITHOUT ANY WARRANTY; without even the implied warranty of
        *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        *    GNU General Public License for more details.
        *
        *    You should have received a copy of the GNU General Public License
        *    along with this program; if not, write to the Free Software
        *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        *
        *    Code written by Mike Hillyer (mike(at)vbmysql(dot)com) *MAINTAINER*
        *
        *    SAMPLE USAGE: php -q popfud.php
        *
        *    This script requires the POP3 module from the PEAR repository.
        *
        ******************************************************************************/

        
define("SERVER_HOST", "mail.myisp.net");
        
define("SERVER_USER", "myusername");
        
define("SERVER_PW", "mypassword");
        
define("SCRIPT_LOCATION", "/path/to/maillist.php");
        
define("RETAIN_NOMATCH", True);   //SET TO TRUE TO SAVE EMAILS THAT MATCH NO LIST
        
define("PEAR_POP3", "/usr/local/php/lib/php/Net/POP3.php"); //LOCATION OF THE POP3 PEAR MODULE

        
    /* USE A REGEX THAT MATCHES THE LIST TO THE EMAILS. IN MY EXAMPLE I USED LIST-ID,
       YOU MAY NEED TO USE TO: AND CC: TAGS DEPENDING ON YOUR PURPOSES, THESE USE THE
       PHP REGEX FORMAT, SEE http://www.php.net/manual/en/pcre.pattern.syntax.php
       ARRAY INDEX IS THE ID OF THE FORUM YOU WISH TO LOAD THE MESSAGES INTO.
    */

        
$mailing_lists = array(
                                
5 => '/^List-Id.*whitebox-users\.beau\.org/im',
                                
2 => '/^List-Id.*whitebox-announce\.beau\.org/im',
                                
3 => '/^List-Id.*whitebox-devel\.beau\.org/im',
                                
4 => '/^List-Id.*whitebox-ia64\.beau\.org/im'
                               
);

//DO NOT MAKE CHANGES BELOW THIS LINE!
        
require(PEAR_POP3);
        
$pop3 =& new Net_POP3();

        
$pop3->connect(SERVER_HOST);
        
$pop3->login(SERVER_USER, SERVER_PW);

        
$n = $pop3->numMsg();                                    //LOOP 1: FOR EACH MESSAGE
        
for ($i=1;$i<=$n;$i++)
        {
                
$found = FALSE;
                
$msgHeader = $pop3->getRawHeaders($i);
                foreach (
$mailing_lists as $list => $expression) //LOOP 2: FOR EACH LIST
                
{
                        if (
preg_match($expression, $msgHeader)) //CHECK MESSAGE AGAINST EACH LIST
                        
{
                                
pipe_email($pop3->getMsg($i), $list);
                                
$pop3->deleteMsg($i);
                                
$found = TRUE;            //PIPE AND DELETE ON A MATCH
                        
}
                }        
                if (!
$found && !RETAIN_NOMATCH)
                {
                        
$pop3->deleteMsg($i);            //DELETE ON NO MATCH WHEN NOT PRESERVING
                
}
        }
        
$pop3->disconnect();
        exit();

        function
pipe_email($message, $scriptNum)        //DOES THE ACTUAL PIPEING OF THE MESSAGE
        
{
                if(!
$PIPE = popen(SCRIPT_LOCATION . " " . $scriptNum, "w"))
                {
                        return
False;
                }

                if (!
fwrite($PIPE, $message))
                {
                        
pclose($PIPE);
                        return
False;
                }
                
pclose($PIPE);
                return
True;
        }
?>
  • Attachment: popfud.php
    (Size: 3.93KB, Downloaded 1465 times)

[Updated on: Thu, 09 September 2004 14:59]

Report message to a moderator

[Message index]
 
Read Message
Previous Topic: PREVIEW PROTECTED SITE SOURCE CODE
Next Topic: New script: fudbox.php
Goto Forum:
  

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

Current Time: Wed Nov 27 23:49:33 GMT 2024

Total time taken to generate the page: 0.04004 seconds