I want to take this script to the next level

Hi All;

The script is at http://www.vbmysql.com/fudmail.phps

Summary: This script is for use with FUDforum (http://fud.prohost.org). FUDforum has a great feature for mirroring Mailing lists so that mailing list posts end up in a FUDforum forum, but it's currently limited to using procmail as a source for emails. This script uses the standard IMAP tools to hook to a POP server and grab the latest emails, it then does some cleanup and tries to determine which list is targeted, then pipes it to the fudmail mail handler script.

It determines which list to point to with the following:

$mailing_lists = array(

This script is working, but I know that my newbieness is getting in the way of it being even better. Here's the things I need to do:

1) If someone cross-posts to all three lists, the email shows up three times in each mirror forum. I am not sure why it would get piped three times to each of the three lists but I would like to fix this.

2) Some of these lists have aliases at the list server (win32@lists.mysql.com can also be mysql-win32@lists.mysql.com). So I think I need to go to a two-dimensional array approach where you give a list name and a script-id code that says which list gets piped to (currently the script ID is the array position + 1 i.e. element 0 has an id of 1 which gets passed to the FUD mailer script. The script uses the id to know which forum to post the message to).

I would love some help with these things and any other tips that can be given for making this script better.
LVL 17
Who is Participating?

Improve company productivity with a Business Account.Sign Up

robinet02Connect With a Mentor Commented:
By "managing", you mean avoiding to spread the SAME email many times ?
In this case, you could use an MD5 checksum.
When a new mail is added to the second script, you store its MD5 checksum, and you refuse any new email with the same ...
So, you won't get anymore the same email posted 3 times ...
To calculate an MD5 is easy : md5($script_content)
robinet02Connect With a Mentor Commented:
It seems to me that your problem is from the 'To:' field of the original email.
This field may contain multiple destination addresses.
This means that if someone posts to the 3 lists, the script will use everyone of the 3 destination email addresses and issue 3 emails for each = 9 emails in total.

you could use an array like this :


Then you can add all the addresses from the 'To:' field of your email by using :

If this destination is already among the array member, the value will just be increased by one.

Then, you process the emails like this :

foreach ($dest_address as $destination_email_address) {
      mail($destination_email_address, ...)

SqueebeeAuthor Commented:
This script is not mailing out. It is processing incoming email and piping it to a script that inserts the email into a forum. As such the To: field is already populated, the challenge is interpreting it.

Thanks for the suggestion though.
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

robinet02Connect With a Mentor Commented:
I had some difficulties to handle MIME emails in php but found recently this class :


it helps to parse the email message, even if you do not have the IMAP extensions available.
You have then access to the "to" content-field, which you can parse easily with preg_match or preg_match_all, first for email_addresses enclosed between brackets ("<" and ">") and then for addresses without brackets.

Does this answer your needs ?
SqueebeeAuthor Commented:
Actually I am parsing the headers just fine at this point, the issue is in managing the piping of the emails to a second script.
SqueebeeAuthor Commented:
Just closing this. In the end I switched to regular expressions.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.