PHP
  Home arrow PHP arrow Page 3 - Building A PHP-Based Mail Client (part 2)
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
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? 
Google.com  
PHP

Building A PHP-Based Mail Client (part 2)
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 12
    2002-01-11


    Table of Contents:
  • Building A PHP-Based Mail Client (part 2)
  • A Picture Is Worth A Thousand Words
  • The Way Things Work
  • Structure And Syntax
  • Room With A View
  • Getting Down
  • Miles To Go

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    Building A PHP-Based Mail Client (part 2) - The Way Things Work
    ( Page 3 of 7 )

    After a little research, it quickly becomes apparent that a standard process flow can be developed for attachment handling, both while sending and reading mail. Here's my first draft of the process:

    When reading email,

    1. Check the message's Content-Type: header and count the number of message parts.

    If the Content-Type: header indicates that the message is in plaintext, you can skip ahead to the last step. If it's anything but "text/plain", it's a fair bet that you'll have to parse it further.

    An alternative here would be to parse the message body and count how many parts it's divided into - if it's two or more, you can again expect to have to parse it further.

    2. Parse the message body.

    If the message is a multipart message - for example, the type "multipart/mixed" - it is necessary to parse the various sections of the message to determine the attachment attributes.

    As explained previously, every message section includes a header providing information on the data enclosed within that section. This data is used by the mail client to figure out how to handle that particular section.

    3. Display the message section(s).

    Once the client has sufficient information on the number and type of attachments, the final step is to display each section. Plaintext sections can be displayed as is; encoded sections may need to be decoded and then displayed. If the client supports HTML-encoded mail - as most Web-based clients do - it may need to jump through a few additional hoops to decode and render embedded HTML markup.

    It's important to note that different mail clients handle multipart messages differently. Some clients display each section as is (raw text) without processing it further; others use the encoding information present in the section header to decode and display each section separately. Some clients display each message section as an attachment, while others use the data type of each section to decide whether the decoded section should be displayed inline (within the message body) or as an attachment.

    What about sending email? Well, that's also fairly simple - all you need to do is build a message incrementally, with each part representing an attachment and a boundary marker separating the various parts.

    1. Build the message headers.

    When sending email, the first step is to build the message headers. Some of these headers are built in response to user input - for example, the subject line and recipient addresses - while others must be added by the client itself. Typically, if one or more message attachments exist, the client will need to alter the Content-Type: of the message and generate a boundary marker to demarcate the various message sections.

    2. Add the message body and attachments.

    Once the headers have been built, the next step is to add the message text. If attachments exist, they must be encoded into plaintext and appended to the message body, with the message's unique boundary marker separating the various sections from each other.

    3. Send the message.

    With the headers and body both ready, the final task is to actually connect to a mail server and send the mail out. Some programming languages (like PHP) offer high-level constructs to perform this function; others require you to use low-level constructs to open up a socket connection to the server and send the message using socket communication techniques.

     
     
    >>> More PHP Articles          >>> More By icarus, (c) Melonfire
     

       

    PHP ARTICLES

    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...





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