Command Receiving Mail, Overview

4D Internet Commands

Receiving Mail, Overview

version 2003 (Modified)


The suite of POP3 commands enable your database to retrieve messages from a POP3 mail server. 4D Internet Commands are MIME compliant and can recognize and extract messages containing multiple enclosures.

The POP3-related commands are broken down into two sections, "IC POP3 Review Mail" and "IC Downloaded Mail". The separation of commands is representative of the differing methods for reading mail. When reading mail from a POP3 server, messages (or information about the messages) may be brought down into 4D structures (variables, fields, arrays) or they may be downloaded to disk. This section "IC POP3 Review Mail" covers the ability of 4D Internet Commands to read messages from the POP3 server into 4D.

The need to for dual methods of message retrieval is spawned by memory constraints on actions which have the potential to download many megabytes of information. For instance, a single mail message which had a 5 Mb attachment could easily overflow the storage capability within the database. The only 4D structure capable of storing this size is a picture or a BLOB field, but converting a message or attachment to this format is often ineffectual since it places huge memory requirements on any client attempting to access the picture or the BLOB. To resolve this issue, this section has a command POP3_Download which will bring a message from the POP3 server to the user's local disk. Once on disk, the "IC Downloaded Mail" section of the manual provides a number of commands to manipulate the file.

When using the suite of POP3 commands, it is important to understand the parameters that are used most frequently, especially msgNumber and uniqueID. msgNumber is the number of a message in the mailbox at the time the POP3_Login command was executed. Upon login, messages in a mailbox are assigned numbers from 1 to the number of items in the mailbox. Numbers are assigned based on the order that they were received in the mailbox, with one being the oldest message. The numbers assigned to the messages are only valid during the time from your POP3_Login to POP3_Logout.

At the time POP3_Logout is executed any message marked for deletion will be removed. When the user logs back into the server, the current messages in the mailbox will once again be numbered from 1 to x. For example, if there are 10 messages in the mailbox, and messages numbered 1 through 5 are deleted, messages 6 through 10 will be renumbered 1 through 5 the next time the user logs in to the mailbox.

To illustrate, suppose you login to a POP3 server and obtain the following list of messages:

#UniqueIDDateFromSubject
1bd573a4dbd573a4d1 Jul 1998 …[email protected]Sales lead…
2bd574dc7bd574dc71 Jul 1998 …[email protected]Site-License order
3bd575f06bd575f063 Jul 1998 …[email protected]Lunch anyone?
4bd5761d4bd5761d44 Jul 1998 …[email protected]Your wife called…
5bd577dc7db577dc54 Jul 1995 …[email protected]FedEx tracking

During the session you delete message numbers 3 and 4. When you Logout of this session your requested deletions are committed. Now when you log back into the server your message list would be renumbered as:

#UniqueIDDateFromSubject
1bd573a4dbd573a4d1 Jul 1998 …[email protected]Sales lead…
2bd574dc7bd574dc71 Jul 1998 …[email protected]Site-License order
3bd577dc7db577dc54 Jul 1995 …[email protected]FedEx tracking

msgNumber is not a static value in relation to any specific message and will change from session to session dependent on its relation to other messages in the mailbox at the time the session was opened. The uniqueID however is a unique number assigned to the message when it was received by the server. This number is calculated using the time and date that the message is received and is a value assigned by your POP3 server. Unfortunately, POP3 servers do not use the uniqueID as the primary reference to its messages. Throughout the POP3 commands you will need to specify the msgNumber as the reference to messages on the server. Developers may need to take some care if developing solutions which bring references to messages into a database but leave the body of the message on the server.

Note: For greater flexibility, 4D Internet commands let you pass a POP3, IMAP or FTP connection reference directly to low-level TCP commands and vice versa. For more information, refer to the Low Level Routines, Overview section.