Reply to PHP and POP3

Your name:

Reply:


Posted by Shawn Wilson on 11/28/05 18:09

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?

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?

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация