TPop3Cli
Last Updated: 01/27/2007

Frequently Asked Questions for TPop3Cli:

     
  1. What is it? 
  2. Commands 
  3. Download attachments 
  4. Download email without attached files 
  5. Downloading Subjects with POP3 Client 
  6. Image in email body 
  7. Mark message as read on a pop3 server 
  8. New Mail Messages 
  9. Plain text part of an email 
  10. Translate one charset to another 

[Back to Main]













  
What is it?
Francois Piette  francois.piette@overbyte.be    
21.09.1998

TPopClient offers all the functionality of a POP3 client.

 
[Return to Top]

  
Commands
Dz dz@caribe.net    
03/29/2001

To access Pop3 server in "one shot", you must send the following commands in order:

USER <username> CRLF PASS <password> CRLF
That will log you in (if the user/pass is correct and the server is  available, so check for errors).  Once you are logged in, you can use  the following commands to check/retrieve mail:
LIST CRLF
This will list the messages, their list number and their sizes (in bytes)
STAT < n > CRLF
This will give you the size (in bytes) of message "n"
RETR < n > CRLF
This will retrieve message " n "
DELE < n > CRLF
This will mark for deletion message " n "
TOP < n > CRLF
Where " n " is the amount of lines you want.  The headers are sent always and are not counted in the lines.
QUIT CRLF
This will close the connection AND actually delete any message marked for deletion.



There are plenty other commands.  Check RFC for more info:
http://www.ietf.org/rfc/rfc1939.txt


 
[Return to Top]

  
Download attachments
Steve Williams stevewilliams@kromestudios.com    
16/12/2001

> How can I download an attachment in a mail

There are downloaded as part of the message by the TPop3Cli component. Then you use the TMimeDecode component to break the message into the separate pieces, which includes attachments.

 
[Return to Top]

  
Download email without attached files
Jeff Hamblin jphamblin@cox.net    
13/06/2003

I want to be able to download email message bodies without downloading any attached files.  In my code I've put in a check in the POP3 OnMessageLine event to detect when an attached file is about to be downloaded.  How can I abort the download of the rest of this particular message without resetting the entire session?  I want to stop the download and then go on to downloading the next message.

You'll need to set MSGLINES to only get a portion of the email body using the TOP command, say 100 lines, then look for the attachment border and discard the rest. If you don't reach a border then re-get the message with more lines.

 
[Return to Top]

  
Downloading Subjects with POP3 Client
DZ-Jay <dz@caribe.net    
14/01/2006

Here's what you do, in POP3 commands:
1. Issue a "UIDL" command with no arguments.  This will return a list of  the message number and their Unique IDentifier (the msg ID from the POP3  server).

 Alternatively, if your server does not support the UIDL command (I  believe its not required by the RFC, you will then have to issue a LIST  command, then a TOP command (see below) to get the headers, parse the  headers, and extract the Message-ID header from it.

 Notice that there is a difference between the UID of the POP3 server and  the Message-ID header, which is inserted by the SMTP server.  The UID is  easier to find (by using the UIDL command), so use it if its available.


2. You store this list locally so that you can reference the messages on  the server later.


3. Issue a "TOP" command.  The TOP command has 2 arguments, the message  number (from the LIST or UIDL command) and the amount of message body  lines to return.  If you give zero as the body lines, it will return  only the headers.


4. When you are ready to delete a message, send the "DELE" command with  the message number.

 Keep in mind that the message numbers might change when the mailbox is  updated.  If you are going to keep the session open while the user  selects which messages to delete, you will have no problems.  But if you  plan on disconnecting, be aware that the message list might have been  updated by a separate session, so as an added integrity measure you  should verify that the message number still belongs to that particular  message by issuing a "UIDL" command with the message number as an  argument, and comparing it with the UID you stored locally.  If they  match, you can safely delete the message.  If they don't, you should  issue a new UIDL command to get the list again and update the message  numbers of your local UID list.  This is important, and a major error on  some amateur mail software built by independent developers (I know that  The Bat! had this problem back in version 1.x).

 As an example, your POP3 session will look like this:

 NOTE:
 '<' = received from server
 '>' sent to server

 
 < +OK POP3 Server Ready
 > UIDL
 < +OK unique-id listing follows
 < 1 B0208052198.MSG
 < 2 B0208062359.MSG
 < 3 B0208062986.MSG
 < 4 B0208063013.MSG
 < 5 B0208067844.MSG
 < .
 > TOP 1 0 < +OK {Headers of #1 go here... SNIP!} < .
 > TOP 2 0 < +OK {Headers of #2 go here... SNIP!} < .
 > TOP 3 0 < +OK {Headers of #3 go here... SNIP!} < .
 > TOP 4 0 < +OK {Headers of #4 go here... SNIP!} < .
 > TOP 5 0 < +OK {Headers of #5 go here... SNIP!} < .
 > UIDL 1 < +OK 1 B0208052198.MSG
 > DELE 1 < +OK message 1 deleted
 > QUIT < +OK POP3 server signing off (4 messages left)


 
[Return to Top]

  
Image in email body
Arno Garrels arno.garrels@gmx.de    
18/05/2005

I'want create an e-mail with an image into the body of message

Add a valid img tag somewhere in your HTML message part, where 'n' is the index of EmailImages list, if I recall it right.

<p><img src="cid:n"> MyImage</p>

Also take a look at ICS-Root\Delphi\Internet\MailHtml.dpr

 
[Return to Top]

  
Mark message as read on a pop3 server
Jeff Hamblin jphamblin@cox.net    
13/06/2003

I'm using the POP3 component to preview email headers on the mail server. The issue is some email clients show these messages as already read when they are downloaded for the first time into the mail client.  Is there a flag that is set on the mail server showing that the message has been previously downloaded?  If so, how do I undo the flag so the messages show as unread when they are downloaded?

It is up to the mail client to maintain its own list of message IDs in order to determine if a message has been downloaded from the server previously.

So, your client grabs all the headers, compares IDs, and then "knows" what is new and what isn't.

 
[Return to Top]

  
New Mail Messages
DZ-Jay dz@caribe.net    
04/06/2001

> I would like to know if is possible to retrieve only NEW MAIL MESSAGE using
> POP3 component.


The way most email programs work  (Eudora, OE, etc.) is that they issue the UIDL (get UID list) command which  will give the UID (Unique Identifier) of each message in the server.  This  UID is guaranteed to be unique in a server.  Then you keep a list of all  the UID's of the messages you have retrieved in a file.  The next time you  check for new email, you issue the UIDL command again and compare UID's to  the ones you already have locally, if it is not in your list, then it is a  new message and you retrieve it.  When you issue the DELE command to remove  a message, you can delete the UID from your list, since it will no longer  exist on the server.  If any UID's that you have locally do NOT exist on  the server, then this means that they already have been deleted from the  server and thus, you can delete it from your index.

Recall, that even if you delete the message locally you still keep the UID  in your index, until that message has been deleted from the server.

 
[Return to Top]

  
Plain text part of an email
DZ-Jay dz@caribe.net    
24/03/2005

Is just look to the header Content-Type: witch start with eather 'multipart' or with
'text/plain' this correct and always the case?


1. If Content-Type is missing in main message header, it is "text/plain".  This is the default of all 822-RFC compliant messages (because the SMTP protocol is for plain-text), so if the message is just plain text, and no mime parts, there might not be any mime headers, since they are not needed.

2. If Content-Type is "text/plain", then (of course) it is "text/plain".

3. If Content-Type is multipart/mixed, you need to look at all mime parts and see if one of them has a mime header with Content-Type "text/plain" (it might not exist, for example, if it is an html message with attachments, but no text part).  Text parts are usually (but not required to be) the first mime part of a multipart message.

4. If main header Content-Type is "text/html", then there is only one single mime part (html), so there is no pain text part.

5. "Multipart/mixed" are the only ones with different mime parts (i.e. 1 html part and 1 plain text part).  There is a chance that the message contains multiple parts of the same time, in this case it won't be "/mixed" (I forgot right now the type).  But these are rare.

If multipart HTML then part 1 seems to be the plain text part of the message. Is always plain text sent with all mail readers if sending HTML, and is this always the first part, or do I have to look to the part header (as with message header)?

As I mentioned in #3 above, you need to look at all parts.  _Usually_ the plain text part is first, and I haven't seen an example otherwise, but this is by convention, and not required, so you can't trust that all mailers will follow it (there are plenty of popular mailers that don't follow convention nor standards).  Also, there might be more than one "text/plain" part, attachments can also be set with a Content-Type of "text/plain", i.e. if it is a .TXT file, and as I mentioned, there is no requirement on the order the parts must appear.  But if it is an attachment, it will say "Content-Disposition: attachment", so you cannot just look at the Content-Type header.

I would suggest that if the message is "multipart/mixed", extract the first "text/plain" part that is not an attachment, and that will be your plain text version.

 
[Return to Top]

  
Translate one charset to another
David Lee   jdl@verifaxsys.com    
25/02/2001

> for instance, when I send a msg with Hebrew in the subject, the
> subject line looks something like this :
> Subject: =?iso-8859-8-i?B?8PHp5e8gdGVzdA==?=
> How do I translate it to ASCII 8 bit, for instance ?

ISO 8859-X character sets use the characters 0xa0 through 0xff to represent national characters, while the characters in the x20-0x7f range are those used in the US-ASCII (ISO 646) character set.  Thus, ASCII text is a proper subset of all ISO 8859-X character sets.

http://www.cs.ruu.nl/wais/html/na-dir/internationalization/iso-8859-1-charset.html

 
[Return to Top]

   

The ICS FAQ is created and maintained by the ICS VIP Documentation Effort Group.
For more information on how to join our efforts, send email to:
[ICS FAQ]