Retrieving POP Mail


Post Office Protocol (POP) is a very common store-and-forward email standard used by Internet service providers and corporate administrators alike.

<cfpop> contacts a qualified POP email account and retrieves the message file as a ColdFusion query object for use in your application. In effect, <cfpop>'s behavior is similar to that of <CFQUERY>, except that it retrieves information from a POP server rather than a SQL database.

ColdFusion does not ship with a built-in POP server. You must have a valid POP account on an external POP server. For each retrieval, the <cfpop> tag, shown here, requires the server and user account details specified:

 <cfpop action="getheaderonly"        name="GetHeaders"        server="mail.forta.com"        username="lalalalala"        password="dumdeedum"> 

NOTE

Unlike with <cfmail>, the server attribute <cfpop> is required; there is no server default.


<cfpop> can perform a variety of actions on the POP server; these actions are specifically designed to leverage the POP mail standard:

  • getheaderonly Retrieves only message headers

  • getall Retrieves an entire message body

  • getall Retrieves file attachments when ATTACHMENTPATH is specified

  • delete Deletes messages on the server

The two retrieval actions, getheaderonly and getall, are provided to maximize performance. Header information is generally small in size and quick to retrieve. The size of the full message, including the body and any attached files, is impossible to predict because the information is not available in the getheaderonly query, so the message body and files are generally retrieved one at a time.

NOTE

Building a Web-based POP interface is a relatively straightforward matter. The application involves retrieving the message headers from the server, and providing a drill-down to individual messages with the option to retrieve files and the capability to delete unwanted messages from the server. ColdFusion can also use a POP account as a drop box for collecting email messages and processing their contents autonomously. For example, you could schedule a process to poll the POP account periodically, collect the mail, and update a database.


POP Dates

The date field in the <CFPOP> query object is in a specific POP date format and needs to be processed before it can be manipulated like a standard date. The ParseDateTime() function accepts an argument for converting POP date/time objects into Greenwich mean time:

 #ParseDateTime(queryname.date, "POP")# 

File Attachments

File attachments are returned with the GETALL action only if the ATTACHMENTPATH attribute is set to a valid directory path on the ColdFusion server, as follows:

 <cfpop action="getall"        name="GetMail"        messagenumber="1"        attachmentpath="c:mailattach"        generateuniquefilenames="Yes"        server="mail.forta.com"        username="lalalalala"        password="dumdeedum"> 

In this instance, two additional columns are returned:

  • attachments A tab-separated list of the source attachment names

  • attachmentfiles A tab-separated list of the actual temporary filenames written to the server

In the event that there are no attachments, both of these columns are returned as empty strings. By setting the generateduniquefilenames attribute of <cfpop> to "Yes", you can avoid duplicate filenames when saving attachments to the ColdFusion server.

You can then use <cffile> to move temporary files to a more permanent storage area on the server.

Attachments need to end up with their original names, but POP is an open and portable protocol available on many different operating systems. Unfortunately, not all operating systems that support POP (servers and clients) support the same filenames. For example, if you send a file named super green price list.xls from Windows 2000 to someone on a DOS box, you'll have problems. DOS supports only filenames in the 8.3 format. Or perhaps you need to send two files whose names are exactly the same, except for the letter casing, from a Unix box (which differentiates filenames by case) to an NT box (which does not).

To solve this problem, POP keeps two pieces of information for each file: the original source filename and the name of the actual attached file, which can be different. The physical attachments are named by their alternative names when they are retrieved from the POP server; those names are safe. <cfpop> returns those filenames in two tab-separated lists, attachments and attachmentfiles, respectively.

File manipulation on the ColdFusion server was covered in Chapter 39, "System Integration." Lists were discussed in Chapter 13, "Lists."


Deleting Mail

Deleting messages from a POP server is different from deleting records from a database. Each message on the POP server is uniquely identified by a MESSAGENUMBER. For example, starting with the oldest message, you have 1, 2, 3, and so on up to the total number of messages in the mailbox. However, this unique assignment is only temporary.

Message numbers are reassigned at the end of every <CFPOP> delete action. If three messages are retrieved from a POP mail server, the message numbers returned are 1, 2, and 3. If message 2 is deleted, message 1 remains 1 and message 3 is assigned as message number 2. Therefore, unlike a typical database primary key, the messagenumber key is reassigned depending on what is present in the message queue.



Macromedia ColdFusion MX 7 Certified Developer Study Guide
Macromedia ColdFusion MX 7 Certified Developer Study Guide
ISBN: 0321330110
EAN: 2147483647
Year: 2004
Pages: 389
Authors: Ben Forta

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net