Re: Finding subject in POP3 connection

From: Date: Sun, 27 Aug 2000 15:28:59 +0000
Subject: Re: Finding subject in POP3 connection
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-13842@lists.php.net to get a copy of this message
> Hi, > Once I've connected to a POP3 server in PHP, how do I obtain the Subject of > any messages waiting? At the moment I've connected, and have one message > waiting - but how do I get the Subject? > Thanks, > Will > -- > W.Luke You should take a look at RFC1939 which specifies version 3 of the Post Office Protocol (POP3): http://www.cis.ohio-state.edu/htbin/rfc/rfc1939.html The commands you need to look at are "USER", "PASS", "LIST", "TOP" and "QUIT". Using those commands you can get the message headers (and first 10 lines of the message) by doing something like this: USER username PASS password LIST TOP 1 10 TOP 2 10 ... TOP 100 10 QUIT Here's a pseudo-code example: open connection to pop3-server.mydomain.com port 110; send "USER username"; send "PASS password"; send "LIST"; read list of messages; for each message_id returned by LIST { send "TOP $message_id 10"; read message header; print message title to user; } send "QUIT"; close connection; Here's a screen-dump of a telnet session doing the above, and it can be easily duplicated in php with the fsockopen(), fputs(), fgets() and fclose() functions (you should also look at the set_socket_blocking() function). ---[ SCREENDUMP START - names changed to protect the guilty ;-) ]--- jesper@juhl:~$ telnet mymailserver.mydomain.com 110 Trying 192.168.1.123... Connected to mymailserver.mydomain.com. Escape character is '^]'. +OK mail08 (POP-Max Version 3.038, Sun Aug 27 17:18:02 2000) POP Mail Server Ready. USER <my_username> +OK PASS <my_password> +OK Maildrop locked and ready LIST +OK 8 message(s) (18905 octets) 1 1650 2 4268 3 1120 4 1697 5 4217 6 2837 7 1939 8 1177 . TOP 1 10 +OK Top of Message follows Received: from sockratte.schell.de (195.20.238.74[195.20.238.74])by mail08(MailMax 3.065) with ESMTP id 41902385 for <juhl@eisenstein.dk>; Thu, 25 May 2000 14:58:08 +0200 WDT Received: (qmail 6958 invoked from network); 25 May 2000 12:57:09 -0000 Received: from unknown (HELO somewhere.com) (62.54.154.209) by schell.de with SMTP; 25 May 2000 12:57:09 -0000 Date: Thu, 25 May 2000 14:56:37 +0200 (CEST) From: <someone@somewhere.com> X-Sender: someone@somewhere.com To: juhl@eisenstein.dk Subject: This is a test email In-Reply-To: <20000525092636.26376.qmail@somewhere.com> Message-ID: <Pine.LNX.4.21.0005251455210.5264-100000@somewhere.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Thu, 25 May 2000 someone@somewhere.com wrote: > > Please check whether your system has DES > crypt. Perhaps some export > > versions of Slackware provide only MD5 > passwords. If the password hashes > > in /etc/shadow (or /etc/passwd) are 13 > chars long, this is a good . QUIT +OK Closing connection. Goodbye. Connection closed by foreign host. ---[ SCREENDUMP END ]--- If you need more details, then just ask. For more RFC's look here: http://www.cis.ohio-state.edu/hypertext/information/rfc.html Best regards, Jesper Juhl juhl@eisenstein.dk

« previous php.general (#13842) next »