XML
  Home arrow XML arrow Page 4 - Take AJAX to your Email Inbox: Developing ...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

Take AJAX to your Email Inbox: Developing the Client-side Application Layer
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2006-04-05

    Table of Contents:
  • Take AJAX to your Email Inbox: Developing the Client-side Application Layer
  • Connecting to the mail server: defining the "sendHttpRequest()" function
  • Collecting connection data: defining the "getFormValues()" function
  • Displaying email messages: defining the "fetchMessages()" function
  • Initializing the POP3 client: defining the "initializeUserPanel()" function
  • Integrating the POP 3 client: listing the complete source code of the application

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Take AJAX to your Email Inbox: Developing the Client-side Application Layer - Displaying email messages: defining the "fetchMessages()" function


    (Page 4 of 6 )

    Before you can see how this function does its thing, first allow me to clarify one point, so the function's source code will be easier to understand. Notice that the "sendHttpRequest()" function that I wrote previously has the ability to invoke a callback function for processing the server response, after the HTTP request has been completed. In this case, I'll use "fetchMessages()" as the proper callback function to be called up when the email messages have been fetched from the mail server, in order to display them right on the web page.

    Now that you know the purpose of this function and how it fits into the application, take a look at its definition:

    function fetchMessages(messages){
        // build message array
        var messages=messages.split('||||');
        var mdiv=document.getElementById('mailcontainer');
        if(!mdiv){return};
        // display mail server response
        mdiv.innerHTML=messages[0];
        // get 'previous' button
        var prev=document.getElementsByTagName('form')[1].elements
    ['prev'];
        if(!prev){return};
        // get 'next' button
        var next=document.getElementsByTagName('form')[1].elements
    ['next'];
        if(!next){return};
        // get 'clear' button
        var clear=document.getElementsByTagName('form')[1].elements
    ['clear'];
        if(!clear){return};
        // move message pointer back
        prev.onclick=function(){
            index--;
            if(index<0){index=0};
            mdiv.innerHTML=messages[index];
        }
        // move message pointer forward
        next.onclick=function(){
            index++;
            if(index==messages.length){index=messages.length-1};
            mdiv.innerHTML=messages[index];
        }
        // clear mail container
        clear.onclick=function(){mdiv.innerHTML=''};
    }

    There are some interesting things worth noting about the function above. The first one is that it accepts the email messages as the only input argument, in this case represented by the "messages" parameter, for processing at a later time. Perhaps processing email messages may be a confusing task, since the PHP code that runs on the server hasn't been written yet. However, don't feel concerned about it, because I'll be explaining this in detail in the last part of the series.

    For the moment, it's enough to know that all the email messages will be fetched in a string format by the "responseText" property of the corresponding requester object, and then stored as an array structure, where each message is an array element. This task is easily performed by splitting the messages through the "||||" delimiter (four pipe characters), which will allow the messages to be manipulated individually.

    This process is shown by the line below:

    var messages=messages.split('||||');

    Here, careful attention must be paid, since there may be subtle differences in the formats that messages are dispatched by distinct POP3 mail servers. To make sure the retrieval of messages will work on most POP 3 servers, I'll use the four-pipe delimiter, but you can use a different one, according to the particularities of each server.

    The rest of the function's code is quite easy to follow. Since all the messages will be displayed within the "mailcontainer" DIV, which was defined in the first tutorial, the function will show the initial server response, stored as the first element of the "messages" array (messages[0]), and then will assign the respective behaviors to each navigational button.

    In order to go back and forth across messages, the "prev" and "next" buttons will increment or decrement an "index" message pointer each time they're clicked on, which will result in displaying one message at once. As you can see, this navigation mechanism is very simple and effective.

    Similarly, the "Clear" button resets the contents of the "mailcontainer" DIV, by using the following function:

    clear.onclick=function(){mdiv.innerHTML=''};

    Right, as you've seen, the "fetchMessages()" function performs some useful tasks, such as displaying email messages and implementing a simple navigation system, which results in a functional message panel. So, are we done? Well, not so fast. I still need to define the last function of the POP3 application, aimed at initializing the POP3 client, after the web page has been loaded. Thus, let's tackle the final part of the tutorial.

    More XML Articles
    More By Alejandro Gervasio


       · In this second article, all the JavaScript functions that comprise that client-side...
     

    XML ARTICLES

    - Using Regions with XSL Formatting Objects
    - Using XSL Formatting Objects
    - More Schematron Features
    - Schematron Patterns and Validation
    - Using Schematron
    - Datatypes and More in RELAX NG
    - Providing Options in RELAX NG
    - An Introduction to RELAX NG
    - Path, Predicates, and XQuery
    - Using Predicates with XQuery
    - Navigating Input Documents Using Paths
    - XML Basics
    - Introduction to XPath
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek