|By Christian Thompson||
|May 1, 2003 12:00 AM EDT||
Don't reinvent the wheel." We've all heard, and perhaps uttered, this maxim many times during our programming careers. ColdFusion MX has introduced new features to help CF developers avoid reinventing the wheel, including tag-based user-defined functions (UDFs) and ColdFusion components (CFCs).
As more CF developers begin to use these features, more code will be available for other developers to download and use. However, code reuse in ColdFusion is not limited to ColdFusion code. Integrating with Java is easier than ever with MX. Since the developer base for Java is large and it has been around much longer than ColdFusion UDFs and CFCs, there is a lot of code already out there that CF developers can use. I discovered this firsthand on a recent project when I didn't think about using existing Java libraries before starting down another path.
This project required me to programmatically access e-mail messages in a subfolder of an e-mail inbox. I couldn't use the CFPOP tag to do this because the protocol implemented by CFPOP - the "Post Office Protocol" - is designed to allow users to download messages from the "inbox" folder only. Another protocol is required to access subfolders - the Internet Message Access Protocol (IMAP).
After discovering that I needed to use IMAP to accomplish my task, I looked for a way to use it with ColdFusion. Unfortunately, since there is no built-in ColdFusion tag that implements IMAP, and I had been looking for an excuse to play around with Java, my first reaction was "Cool! I'll write my own!"
I learned a few IMAP commands and started playing around with the low-level Java networking libraries. Two days and many lines of code later, I had written a marginal IMAP client. Although it mostly worked, it still needed additional functionality and I wasn't at all confident in its stability. I knew there had to be a better way.
Fortunately, I discovered that there is a much better way - use the JavaMail API. According to Sun's JavaMail Web site (http://java.sun.com/products/javamail), this API "provides a set of abstract classes that model a mail system" including support for IMAP - the same functionality (plus a lot more) that I had been struggling with for two days. Best of all, since it's included in the J2EE platform, on which ColdFusion MX is built, I didn't have to download anything or make any configuration changes to use it. This was the option I should have considered from the start.
Now that I had found a library, I wanted to make it simple to use from ColdFusion. Since I was already comfortable using the CFPOP tag, I decided to encapsulate some of JavaMail's functionality into a custom tag that, as much as possible, provides the same interface as CFPOP. The tag's full code is shown in the code listing. Listing 1 shows the functions that interact with the API.
Listing 2 shows the tag's main logic. For the sake of brevity, the code shown in the listing includes only one of the actions provided by CFPOP's interface - the "GETHEADERONLY" action. This excludes the "GETALL" action, which provides the ability to view a message's contents and attachments, and the "DELETE" action.
The JavaMail API consists of a bunch of classes that model a mail system. The highest-level class is the "Session" class. The session class allows you to specify properties like "port" and "timeout." To specify properties, first create and set a "Properties" object. The following sets the protocol to IMAP and the port to 143:
Now create the session object and pass in the properties object:
The session class also provides a method for getting the "store." The store class abstracts the underlying protocol (in this case IMAP) and provides methods for logging into the mailbox.
obj_Store = createObject("Java",
Now you are ready to start accessing folders. The only folder that you can access using POP is the "inbox" folder. With IMAP, you can access subfolders below the inbox. The following code accesses and opens the folder "test," which is a subfolder of "inbox":
Note that this code opens the folder with read permissions only. This is a good idea if you only want to browse the contents of the folder. If you want to delete, move, or update messages, open the folder with read and write permissions:
The next step is to get a list of messages in the folder. With the JavaMail API, this is done by retrieving an array of "Message" objects.
This code returns all messages in the folder. If you only need a subset of the messages, you must pass an array of message numbers to the "getMessages" function. Because I modeled my IMAP tag after the CFPOP tag, I wanted to allow the user to pass a list of message numbers to the tag. This discrepancy was easily remedied by using the built-in "ListToArray" ColdFusion function.
Once you have the messages, you are ready to read the message headers using methods of the "Message" object. The following shows how to access the "subject" and "to addresses" of the first message in the folder (which is located at position 1 of the messages array):
// Get the received date
// Get the to addresses
Note that the "getRecipients" method of the "Message" object returns an array of addresses since an e-mail message can be addressed to more than one person. This is also true when getting the "from", "reply-to", "CC", and "BCC" addresses. Also note the dollar sign ($) syntax used to invoke the "RecipientType" class. RecipientType is an "inner class" of the "Message" class. Although you can access inner classes in Java code by using dot notation (e.g., "Message.RecipientType"), this doesn't work in ColdFusion code.
Now that you have read the messages, the next step is to delete the unwanted ones. To do this, you set the "deleted" flag of the message and then call the folder object's "expunge" method:
Where to Go from Here
The code presented here only scratches the surface of the functionality provided by IMAP. Most obviously, it lacks the ability to read message contents and attachments. Another useful feature would allow users to retrieve a listing of subfolders. If you are interested in adding these or other features, check out the JavaMail tutorial at http://developer.java.sun.com/developer/ onlineTraining/JavaMail/contents.html and the API specification at http://java.sun.com/products/ javamail/1.3/docs/javadocs/index.html.
With the release of MX, ColdFusion developers have more options for code reuse, including native access to a wide array of predeveloped Java software. Sometimes, especially for developers who don't have extensive Java experience, using existing Java libraries is not always the most obvious option. However, in ColdFusion MX, it can be a very worthwhile option to consider. It certainly is one that I strongly recommend the next time you start a project and think "Cool, I'll just write it myself..."
|Christian Thompson 05/27/03 10:53:00 AM EDT|
As it is, the tag does not allow you to connect with NNTP servers. With a little configuration (getting and setting up an NNTP provider), though, JavaMail does. Once you got this set up, you would have create a tag similar to CF_IMAP that performs the necessary actions. I have included a link that talks a little about accessing NNTP servers with JavaMail.
|Craig Rosenblum 05/26/03 11:17:00 PM EDT|
Does this allow us to do nntp reading and posting?
|Christian Thompson 05/12/03 02:25:00 PM EDT|
According to the documentation, BlueDragon's CFIMAP implements the following actions: list folders, list messages, mark message as read, delete message, move message, delete folder, and move folder. Since the tag presented in this article currently only lists messages, you would need to add the rest of the functions. The good news is that they are all implemented in JavaMail. You would just need to write the CF code to call the functions.
|Abraham 05/08/03 12:24:00 PM EDT|
I'm planning to write a email app and want IMAP support.
I've been playing with BlueDragon lately, which offers a tag called CFIMAP. Would it take much extra code to get the same functionality?
Chuck Piluso will present a study of cloud adoption trends and the power and flexibility of IBM Power and Pureflex cloud solutions. Speaker Bio: Prior to Data Storage Corporation (DSC), Mr. Piluso founded North American Telecommunication Corporation, a facilities-based Competitive Local Exchange Carrier licensed by the Public Service Commission in 10 states, serving as the company's chairman and president from 1997 to 2000. Between 1990 and 1997, Mr. Piluso served as chairman & founder of International Telecommunications Corporation, a facilities-based international carrier licensed by t...
Apr. 27, 2015 11:00 PM EDT
There are lots of challenges in IoT around secure, scalable and business friendly infrastructure for enterprises. For large corporations, IoT implementations are one of the top priorities of the decade. All industries are seeing a competitive need to sustain by investing in IoT initiatives. The value addition comes from improved customer service, innovative product and additional revenue streams. The data from these IP-connected devices can be leveraged for a variety of business applications as well as responsive action controls. The various architectural building blocks of an IoT ...
Apr. 27, 2015 09:00 PM EDT
“In the past year we've seen a lot of stabilization of WebRTC. You can now use it in production with a far greater degree of certainty. A lot of the real developments in the past year have been in things like the data channel, which will enable a whole new type of application," explained Peter Dunkley, Technical Director at Acision, in this SYS-CON.tv interview at @ThingsExpo, held Nov 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA.
Apr. 27, 2015 06:00 PM EDT Reads: 4,492
WebRTC is an up-and-coming standard that enables real-time voice and video to be directly embedded into browsers making the browser a primary user interface for communications and collaboration. WebRTC runs in a number of browsers today and is currently supported in over a billion installed browsers globally, across a range of platform OS and devices. Today, organizations that choose to deploy WebRTC applications and use a host machine that supports audio through USB or Bluetooth can use Plantronics products to connect and transit or receive the audio associated with the WebRTC session.
Apr. 27, 2015 04:00 PM EDT Reads: 1,913
The best mobile applications are augmented by dedicated servers, the Internet and Cloud services. Mobile developers should focus on one thing: writing the next socially disruptive viral app. Thanks to the cloud, they can focus on the overall solution, not the underlying plumbing. From iOS to Android and Windows, developers can leverage cloud services to create a common cross-platform backend to persist user settings, app data, broadcast notifications, run jobs, etc. This session provides a high level technical overview of many cloud services available to mobile app developers, includi...
Apr. 27, 2015 04:00 PM EDT Reads: 1,429
SYS-CON Media announced today that @WebRTCSummit Blog, the largest WebRTC resource in the world, has been launched. @WebRTCSummit Blog offers top articles, news stories, and blog posts from the world's well-known experts and guarantees better exposure for its authors than any other publication. @WebRTCSummit Blog can be bookmarked ▸ Here @WebRTCSummit conference site can be bookmarked ▸ Here
Apr. 27, 2015 04:00 PM EDT Reads: 2,515
SYS-CON Events announced today that Ciqada will exhibit at SYS-CON's @ThingsExpo, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Ciqada™ makes it easy to connect your products to the Internet. By integrating key components - hardware, servers, dashboards, and mobile apps - into an easy-to-use, configurable system, your products can quickly and securely join the internet of things. With remote monitoring, control, and alert messaging capability, you will meet your customers' needs of tomorrow - today! Ciqada. Let your products take flight. For more inform...
Apr. 27, 2015 04:00 PM EDT Reads: 1,934
Health care systems across the globe are under enormous strain, as facilities reach capacity and costs continue to rise. M2M and the Internet of Things have the potential to transform the industry through connected health solutions that can make care more efficient while reducing costs. In fact, Vodafone's annual M2M Barometer Report forecasts M2M applications rising to 57 percent in health care and life sciences by 2016. Lively is one of Vodafone's health care partners, whose solutions enable older adults to live independent lives while staying connected to loved ones. M2M will continue to gr...
Apr. 27, 2015 03:00 PM EDT Reads: 1,535
Dave will share his insights on how Internet of Things for Enterprises are transforming and making more productive and efficient operations and maintenance (O&M) procedures in the cleantech industry and beyond. Speaker Bio: Dave Landa is chief operating officer of Cybozu Corp (kintone US). Based in the San Francisco Bay Area, Dave has been on the forefront of the Cloud revolution driving strategic business development on the executive teams of multiple leading Software as a Services (SaaS) application providers dating back to 2004. Cybozu's kintone.com is a leading global BYOA (Build Your O...
Apr. 27, 2015 02:00 PM EDT Reads: 1,579
As enterprises move to all-IP networks and cloud-based applications, communications service providers (CSPs) – facing increased competition from over-the-top providers delivering content via the Internet and independently of CSPs – must be able to offer seamless cloud-based communication and collaboration solutions that can scale for small, midsize, and large enterprises, as well as public sector organizations, in order to keep and grow market share. The latest version of Oracle Communications Unified Communications Suite gives CSPs the capability to do just that. In addition, its integration ...
Apr. 27, 2015 01:30 PM EDT Reads: 4,429
The 17th International Cloud Expo has announced that its Call for Papers is open. 17th International Cloud Expo, to be held November 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, brings together Cloud Computing, APM, APIs, Microservices, Security, Big Data, Internet of Things, DevOps and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding business opportunity. Submit your speaking proposal today!
Apr. 27, 2015 12:00 PM EDT Reads: 2,329
While not quite mainstream yet, WebRTC is starting to gain ground with Carriers, Enterprises and Independent Software Vendors (ISV’s) alike. WebRTC makes it easy for developers to add audio and video communications into their applications by using Web browsers as their platform. But like any market, every customer engagement has unique requirements, as well as constraints. And of course, one size does not fit all. In her session at WebRTC Summit, Dr. Natasha Tamaskar, Vice President, Head of Cloud and Mobile Strategy at GENBAND, will explore what is needed to take a real time communications ...
Apr. 27, 2015 12:00 PM EDT Reads: 1,801
The IoT Bootcamp is coming to Cloud Expo | @ThingsExpo on June 9-10 at the Javits Center in New York. Instructor. Registration is now available at http://iotbootcamp.sys-con.com/ Instructor Janakiram MSV previously taught the famously successful Multi-Cloud Bootcamp at Cloud Expo | @ThingsExpo in November in Santa Clara. Now he is expanding the focus to Janakiram is the founder and CTO of Get Cloud Ready Consulting, a niche Cloud Migration and Cloud Operations firm that recently got acquired by Aditi Technologies. He is a Microsoft Regional Director for Hyderabad, India, and one of the f...
Apr. 27, 2015 12:00 PM EDT Reads: 1,678
SYS-CON Events announced today that Litmus Automation will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Litmus Automation’s vision is to provide a solution for companies that are in a rush to embrace the disruptive Internet of Things technology and leverage it for real business challenges. Litmus Automation simplifies the complexity of connected devices applications with Loop, a secure and scalable cloud platform.
Apr. 27, 2015 11:00 AM EDT Reads: 1,758
In 2015, 4.9 billion connected "things" will be in use. By 2020, Gartner forecasts this amount to be 25 billion, a 410 percent increase in just five years. How will businesses handle this rapid growth of data? Hadoop will continue to improve its technology to meet business demands, by enabling businesses to access/analyze data in real time, when and where they need it. Cloudera's Chief Technologist, Eli Collins, will discuss how Big Data is keeping up with today's data demands and how in the future, data and analytics will be pervasive, embedded into every workflow, application and infra...
Apr. 27, 2015 11:00 AM EDT Reads: 1,478
From telemedicine to smart cars, digital homes and industrial monitoring, the explosive growth of IoT has created exciting new business opportunities for real time calls and messaging. In his session at @ThingsExpo, Ivelin Ivanov, CEO and Co-Founder of Telestax, shared some of the new revenue sources that IoT created for Restcomm – the open source telephony platform from Telestax. Ivelin Ivanov is a technology entrepreneur who founded Mobicents, an Open Source VoIP Platform, to help create, deploy, and manage applications integrating voice, video and data. He is the co-founder of TeleStax, a...
Apr. 27, 2015 11:00 AM EDT Reads: 5,181
As Marc Andreessen says software is eating the world. Everything is rapidly moving toward being software-defined – from our phones and cars through our washing machines to the datacenter. However, there are larger challenges when implementing software defined on a larger scale - when building software defined infrastructure. In his session at 16th Cloud Expo, Boyan Ivanov, CEO of StorPool, will provide some practical insights on what, how and why when implementing "software-defined" in the datacenter.
Apr. 27, 2015 11:00 AM EDT Reads: 1,633
How is unified communications transforming the way businesses operate? In his session at WebRTC Summit, Arvind Rangarajan, Director of Product Marketing at BroadSoft, will discuss how to extend unified communications experience outside the enterprise through WebRTC. He will also review use cases across different industry verticals. Arvind Rangarajan is Director, Product Marketing at BroadSoft. He has over 19 years of experience in the telecommunications industry in various roles such as Software Development, Product Management and Product Marketing, applied across Wireless, Unified Communic...
Apr. 27, 2015 11:00 AM EDT Reads: 1,729
SYS-CON Events announced today that MangoApps will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY., and the 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. MangoApps provides private all-in-one social intranets allowing workers to securely collaborate from anywhere in the world and from any device. Social, mobile, and easy to use. MangoApps has been named a "Market Leader" by Ovum Research and a "Cool Vendor" by Gartner...
Apr. 27, 2015 11:00 AM EDT Reads: 3,591
SYS-CON Media announced today that @ThingsExpo Blog launched with 7,788 original stories. @ThingsExpo Blog offers top articles, news stories, and blog posts from the world's well-known experts and guarantees better exposure for its authors than any other publication. @ThingsExpo Blog can be bookmarked. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago.
Apr. 27, 2015 11:00 AM EDT Reads: 2,573