Ask a Jedi: Ordering CFPOP Data

Robert writes in with a question concerning CFPOP:

I have put together a little webail app for my website and for the most part it works pretty good but.... It returns the mail messages in a seemingly random order. Is there a way to order the results?

I could have sworn that I remember CFPOP returning items in order of delivery. In other words, the first message sent to the account would be the first downloaded. The documentation for cfpop does not specify an order, so I probably wouldn’t depend on any order.

That being said - don’t forget that the result of cfpop is a query. Because of this, you can use query of query to sort the results. You can sort by sender, date, subject, or any other column. Here is a simple example:

<cfpop server="pop.xxx.com" username="..." password="..." action="getHeaderOnly" name="qGetMessages">

<cfquery name=”qGetMessages” dbtype=”query”> select * from qGetMessages order by date desc </cfquery> </code>

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Comments