Hello, This is a reply to an e-mail that you wrote on Thu, 17 Jul 2003 at 14:04, lines prefixed by '>' were originally written by you. > Ok, this is what I want to do. I would like to parse a mailbox and > forward > the returned mail in it to other users. For instance, if I send an > e-mail > to "[EMAIL PROTECTED]" and "[EMAIL PROTECTED]" doesn't exist it is > going > to send the return to "[EMAIL PROTECTED]". I want to parse > "[EMAIL PROTECTED]" and > send the e-mail to whoever is in the "Disposition-Notification-To" > header of > the e-mail. Anyone know where I can find a good script to parse mail > boxes > or maybe give me an idea of where to start? I checked hotscripts and > some > others but they are complete web based e-mail systems. I'd like to > run this > as a cron job if possible and I don't want to tear another system all > apart
If you have the imap php extensions installed you could use them (they support POP too) I normally work on systems without the imap enxtensions though so I chose to make my own class to deal with POP3 related tasks. Here are some snippets that you may find useful... class POPClient { .. function Connect(){ // connect to server if(!$this->[EMAIL PROTECTED]($this->server, $this->port)){ $this->error = "Could not connect to {$this->server}:{$this->port}"; return FALSE; } // login to server: fputs($this->sock, "USER {$this->user}\r\n"); $buf = fgets($this->sock, 1024); if($buf[0] != '+'){ $this->error = "Invalid username: {$this->user}"; return FALSE; } fputs($this->sock, "PASS {$this->pass}\r\n"); $buf = fgets($this->sock, 1024); if($buf[0] != '+') { $this->error = "Invalid password"; return FALSE; } $this->connected = TRUE; return TRUE; } <snip> function MessageCount(){ if($this->connected){ fputs($this->sock, "STAT\r\n"); $buf = fgets($this->sock, 1024); $buf = fgets($this->sock, 1024); $statbits = split(' ', $buf, 3); if(isset($statbits[1])){ return $statbits[1]; } else { return 0; } } else { $this->error = "Not connected to server"; return FALSE; } } <snip> function RetrieveMsg($id, $headonly=FALSE){ if($this->connected){ if($headonly){ $command="TOP"; $param=" 0"; } else { $command="RETR"; $param=""; } fputs($this->sock, "$command $id$param\r\n"); $buf = fgets($this->sock, 1024); if($buf[0] != '+') { $this->error = "Mail server would not let me retrieve message $id"; return FALSE; } $message="";$thisline=""; while ($thisline!=".\r\n"){ // .\r\n signifies the end of the message $thisline = fgets($this->sock, 1024); $this->messagesource .= $thisline; } return TRUE; } else { $this->error = "Not connected to server"; return FALSE; } } <snip> } -- phpmachine :: The quick and easy to use service providing you with professionally developed PHP scripts :: http://www.phpmachine.com/ Professional Web Development by David Nicholson http://www.djnicholson.com/ QuizSender.com - How well do your friends actually know you? http://www.quizsender.com/ (developed entirely in PHP) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php