Firefox PHP

Module: POP3 Phorummail

Posted by Thomas Seifert 
All files from this thread

File Name File Size   Posted by Date  
pop3phorummail.php 10.1 KB open | download jjarvis98 12/10/2008 Read message
pop3phorummail.php 11.4 KB open | download jjarvis98 01/12/2009 Read message
Module: POP3 Phorummail
October 12, 2008 08:27AM
This module implements a mailimport from pop3 mailaccounts into phorum through the scheduled hook.
I decided to rework the script I posted earlier today into a real module.

This script is derived from
1) []
pop3-collector from woleium

2) []
Phorummail by Brian Moon

Updated, reworked and turned into a module for current 5.2 (tested with 5.2.9)
by Thomas Seifert ( ).

Needs the PEAR Mail_mimeDecode package!

Superseded by the External Phorummail Module.

Thomas Seifert

Edited 3 time(s). Last edit at 08/31/2009 04:44PM by Thomas Seifert.
Re: Module: POP3 Phorummail
December 10, 2008 08:32PM
I made a few changes.

1) Since you have to have PEAR, I decided to use the PEAR Net_POP3 module. It cuts out a ton of code plus you don't have to "un parse" the <HEADER> stuff.
2) Attachments work! I don't know all the API stuff, so I'm sure there's a few easier ways to do things.
3) Cleaned up a bug if someone ONLY had an e-mail address and no Name, etc. The original "else" statement had a $matches[1], however there was nothing to match to, making the post from 'anonymous'.
Language: PHP
if (preg_match(';!"(.+?)"\s*<(.+?)>!';, $headers["from"], $matches)) { $new_message["author"] = trim($matches[1]); $new_message["email"] = trim($matches[2]); } elseif (preg_match(';!([^<]+?)\s*<(.+?)>!';, $headers["from"], $matches)) { $new_message["author"] = trim($matches[1]); $new_message["email"] = trim($matches[2]); } elseif (preg_match(';!<(.+?)>!';, $headers["from"], $matches)) { $new_message["author"] = trim($matches[1]); $new_message["email"] = trim($matches[1]); } else { $new_message["author"] = $headers["from"]; $new_message["email"] = $headers["from"]; }
4) I used displayname instead of username for message author.

I have no time/intentions of making my own module, feel free to incorporate it back.

Edited 1 time(s). Last edit at 12/10/2008 08:35PM by jjarvis98.
open | download - pop3phorummail.php (10.1 KB)
Re: Module: POP3 Phorummail
January 12, 2009 11:39AM
I fixed a few more things. It seems that datestamp is currently being ignored because in phorum_db_post_message takes a second argument to decide if you even want to use the datestamp. Discovered when I was importing mailman messages and my datestamp was correct, but everything was set to NOW.

Language: PHP
function phorum_db_post_message(&$message, $convert=FALSE) { ... // When converting messages, the post time should be in the message. $NOW = $convert ? $message[';datestamp';] : time(); ... $insertfields = array( ... ';datestamp'; => $NOW, ... ); }

I fixed the 'in-reply-to' code.
Language: PHP
$msgid = substr($msgid, 0, strpos($msgid, "@") - 1);

Splits the msgid wrong because it clips the last letter before the @. The -1 should be removed, or because I live in Matlab arrays I changed it to this

Language: PHP
$msgid = current(explode("@",$msgid));

In the "references" section I also changed the code.
Language: PHP
foreach($ids as $id) { $message = phorum_db_get_message($id, "msgid");

Meaning that it would search for the @ symbol too.

Language: PHP
foreach($ids as $msgid) { if (strpos($msgid, "@") !== false) { $msgid = current(explode("@",$msgid)); } $message = phorum_db_get_message($msgid, "msgid");

If the message contained parts then I made it a recursive function.
1) On mailman messages if the user sent an HTML message to the list serv. The message would come through as:
Where text was the signature of the listserv, meaning this was the only thing posted.

2) when sending inline JPG would put the attachment in the multipart part, which was a part of the main part :).

Still goes on the broadly gross assumption that the first 'message' it receives is the body. But so far that's held true in my testing.
Instead of:
Language: PHP
} elseif ($sections->parts) { /* Blah Blah */ }

I made it this:
Language: PHP
} elseif ($sections->parts) { $out = parseParts($sections,$new_message); $new_message = $out[0]; $attachments = $out[1]; }

Language: PHP
function parseParts($section,$new_message) { foreach($section->parts as $part) { if ($part->parts) { $out = parseParts($part, $new_message); $new_message=$out[0]; $attachments=$out[1]; } if (empty($new_message["body"])) { /* If a html/text message is sent to the mailing list, it is sent on as a multipart */ if ($part->ctype_primary == "multipart" && $part->ctype_secondary == "alternative") { foreach($part->parts as $subpart) { if ($subpart->ctype_primary == "text" && $subpart->ctype_secondary == "plain") { $new_message["body"] = strip_tags($subpart->body); if ($subpart->headers["content-transfer-encoding"] == "quoted-printable") { $new_message["body"] = quoted_printable_decode($new_message["body"]); } } if ($subpart->ctype_primary == "text" && $subpart->ctype_secondary == "html") { $new_message["body"] = strip_tags(br2nl($subpart->body)); } } } if ($part->ctype_primary == "text" && $part->ctype_secondary == "plain") { $new_message["body"] = strip_tags($part->body); if ($part->headers["content-transfer-encoding"] == "quoted-printable") { $new_message["body"] = quoted_printable_decode($new_message["body"]); } } if ($part->ctype_primary == "text" && $part->ctype_secondary == "html") { $new_message["body"] = strip_tags(br2nl($part->body)); } } if ($part->ctype_parameters["name"] && $part->headers["content-transfer-encoding"] == "base64") { $tmp = array(); $tmp[';filename';] = $part->ctype_parameters["name"]; $tmp[';file_data';] = $part->body; $tmp[';filesize';] = strlen($part->body); $tmp[';link';] = PHORUM_LINK_TEMPFILE; $attachments[] = phorum_api_file_store($tmp); } $out[0] = $new_message; $out[1] = $attachments; } return $out; }   function br2nl($string) { return preg_replace(';/\<br(\s*)?\/?\>/i';, "\n", $string); }

I didn't want the messages posted to the phorum to have the signature that mailman attached to the bottom of everything. I hope my users never put in a 46 character underscore.

Language: PHP
$new_message["body"] = current(explode("_______________________________________________", $new_message["body"]));

I also dropped the 'validate valid attachment extensions' part and just use content filtering in mailman admin to enable/prevent extensions I don't want.

Tested with all the different permutations of this:
(, (HTML Only, Text Only, HTML & Text) (Attachment, No Attachment)
and it seemed to work.
open | download - pop3phorummail.php (11.4 KB)
Re: Module: POP3 Phorummail
January 18, 2009 12:16PM

I've been trying this script, but can't get it to work.

I'm using the latest jjarvis98 modification with v5.2.9a
I have the pear module installed

In the readme instructions, it indicates: "I recommend to run the script by hand until everything is working correctly."

How do you actually do that? Is it via the web-browser?

I can remove the web browser check in script.php, but then just get this output:
Usage: php script.php [--module=] [--scheduled] [options] --module= Run the "external" hook in the specified module, unless --scheduled is specified as well, in which case this parameter will be used to restrict the module(s) for which to run the "scheduled" hook. --scheduled Run the "scheduled" hooks in all available modules. If one or more modules are configured using --module / -m, then the "scheduled" hook will only run for the specified module(s). -m Alias for --module= -s Alias for --scheduled [options] When running the "external" hook for a module, then these options are passed to the hook function. When using --scheduled, these are ignored.

Do I have to edit the script file?
Any help would be appreciated
Re: Module: POP3 Phorummail
January 18, 2009 01:14PM
do you have console / ssh access to your webspace? otherwise you won't be able to run it by hand or even have it running later on.

Thomas Seifert
Re: Module: POP3 Phorummail
January 18, 2009 05:57PM

thanks for the info.

Yes, I've managed to get shell access.

I get the following in the error log when I run the script via shell [edited out my username]:

[18-Jan-2009 17:53:06] PHP Warning: require_once(Net/POP3.php): failed to open stream: No such file or directory in home/[...]/public_html/submission/mods/pop3phorummail/pop3phorummail.php on line 50
[18-Jan-2009 17:53:06] PHP Fatal error: require_once(): Failed opening required 'Net/POP3.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in home/[...]/public_html/submission/mods/pop3phorummail/pop3phorummail.php on line 50
Re: Module: POP3 Phorummail
January 18, 2009 06:10PM
So you don't have the appropriate pear module installed.

Thomas Seifert
Re: Module: POP3 Phorummail
January 18, 2009 06:21PM

Module installed is supposed to be: mimeDecode.php

Yes, it's installed in the path php/mail/ on my server

Sorry, I'm a bit of a server newbie
Re: Module: POP3 Phorummail
January 18, 2009 06:45PM
Just to add, in shell I was instructed by my host to run the command:

php /home/myusername/public_html/submission/script.php --scheduled > /dev/null
Re: Module: POP3 Phorummail
January 18, 2009 07:12PM
Just to update - it's working.
Seems there was an issue with access to the pear module on my server

Sorry, only registered users may post in this forum.

Click here to login