|
Posted by Norman Peelman on 11/21/08 11:33
"Shawn Wilson" <shawnw_nospam_@_nospam_dvigroup.net> wrote in message
news:qZFif.50739$vs2.19852@fe04.news.easynews.com...
> I am writing a mail system that will be using POP3 to gather messages. My
> system is to be a challange/response system although it will have several
> features that are not normally found in such systems such as message
> redirecting based on filters and PGP encryption.
>
> The broad strokes of what I want to do:
> 1. POP a remote box and get all mail
> 2. put that mail as original seperate messages into a local mail server
> account with all headers intact.
> 3. redirect some messages to another address but keeping headers intact so
a
> reply will to to the original sender and not this middle step server.
>
> Details:
> First, I wonder if there is an easy way to POP an entire message file? So
> far in my searches it seems like the only way to get a message from a POP3
> server is to connect, analyze the messages, pull each message in pieces
> (headers, body, attachment1, attachment2, etc..., other MIME stuff...) so
> you end up running a hundred lines of code just to get one message and be
> sure you got all of it's parts. Is there not a way to just retrieve the
> entire message file as a raw mail file to be parsed later?
>
I do not beleive that it is possible to retrieve an entire message file
but,
if you are going to have to parse it later anyway then you might as well do
it to begin with. You will be using the same amount of code anyway.
> In the absense of that option, can anyone give me a positive checklist of
> steps(functions) to getting a POP3 message? The documentation is pretty
> hard to figure out what is needed for IMAP and what is needed for POP3. I
> just want to make sure I don't end up missing some part of a message.
After
> I get each message, I want to write it to a file and simply dump that file
> in the local mail folder... is that possible or would I need to email it
to
> the local box? If I email the message to the local box, then I can't
fully
> write the headers as some are already server-set like the return path and
> such.
>
> As I understand it so far, it looks like I have to POP in, get a list of
> messages, then for each message request the headers, body, alt body (html
> maybe?), and attachments all seperately. Are those the only things? Will
> that cover all types of mail?
>
Believe it or not, but I think this is how it's done by everyone (email
clients).
You need to look into 'imap_fetchstructure()' as it returns a list of all
parts found.
There are alot of examples on
http://us2.php.net/manual/en/function.imap-fetchstructure.php.
I would imagine you need to:
1) open a connection to the source POP3 account
2) open a connection to the destination account(s)
3) retrieve the number of messages waiting...
4) fetch the header info
5) fetch all the message parts (as discovered with imap_fetchstructure)
6) perform your filter options
7)
a: if you want you could try to simply open a new file in the desired
folder and
fwrite() the contents of all the variables (headers, body parts). Be
careful
with proper termination.
b: create a new mail and 'forward' it as normal to the other account. Be
careful to
construct them properly.
8) perform any other action here (delete message after process, etc)
9) repeat from 3
> At the end is the code I have so far that POPs a box and shows the message
> body for each message found. It only works for plain text messages I
think,
> and doesn't detect or deal with attachments.
>
> I know this isn't an easy answer... any insight is appreciated.
>
> --
> Shawn Wilson
>
> --PHP snippet
>
> function test() {
> $username = "user@domain.com";
> $password = "******";
> $mailserver = "localhost/pop3:110/notls";
>
> $mbox = imap_open("\{$mailserver}INBOX",$username,$password);
>
> echo "<h2>Headers in INBOX</h2>\n";
>
> $headers = imap_headers($mbox);
>
> if ($headers == false) {
> echo "No messages!<br />\n";
> }
> else {
> $messagecount = imap_num_msg($mbox);
> echo "<h3>Found $messagecount messages.</h3><br>";
>
> echo "<pre>";
> for ($x = 1; $x <= $messagecount; ++$x) {
> echo "====<br>";
> echo imap_fetchbody($mbox,$x,1);
> }
> echo "</pre>";
> }
>
>
> imap_close($mbox);
> }
>
> -- end snippet
>
>
[Back to original message]
|