March 1, 2021
Hot Topics:

Enhancing your Webmail program

  • By Bjxrn Borud
  • Send Email »
  • More Articles »

The variable

contains information about the host and the port we wish to connect to and the kind of protocol we want to talk. In this case
would typically have the value:

To this we then add the string contained in

and finally the folder name.

Why do you want to do that?

The prefix
is added to make listing mail folders easier. When the client asks for a list of mail folders, it can provide the IMAP server with a prefix to the filenames. It works just like the shell: if you say
you will match all filenames starting with the string "docu".


enables us to tuck a prefix onto the actual filenames of our folders, thus making it easy to tell the IMAP server that we want it to list anything that starts with the prefix as if it were a mail folder:
$mailboxes = imap_listmailbox($MBOX, $M_MBOX, "$M_PREFIX%");  

The third argument to the PHP3 function

tells the IMAP server to only list filenames starting with the chosen prefix. Before showing the name to the user we massage the name a bit, removing the prefix and the host/port/service information.

In short: folder names on disk have prefixes so we can identify them. When displayed to the user everything but the folder name itself is stripped away.

Keeping track

Now that we have several folders, we have to keep track of which folder we're in. Actually, most of the code to do this was already added in version 1.0. The
variable is used to keep track of what folder is currently being viewed.

To remember what folder we were in while browsing a message, when moving or deleting messages some pages have a hidden input field (well, "input field" is obviously a bad name if you're not supposed to input anything into it or even see it, but nevertheless, 'tis an input field). This is sort of a sneaky way to have the application open the correct folder.

We could also have used cookies to keep track of the current folder. Setting cookies is fairly simple in PHP3 and reading them is even simpler. (Yes, you guessed it; cookies are turned into variables just like forms fields are).

Note: See page 5 for a rundown of what's new in this tutorial.

What's next?

Our little Webmail interface is still under 500 lines of code. Considering what it would take to write an equivalent application with a GUI, that is not bad at all. Of course there is a lot left to be desired. For one, the folders should be hierarchical and they should be displayed as such. Some tasks could be automated, such as the creation of monthly archive folders. E-mail could be moved from the default folder into such archive folders when a message reaches a certain age.

Also, we haven't begun to dive into MIME and multipart MIME messages.

Tune in next month and find out where we go next!ø

Related resources

1. Web mail in PHP Part I of this workshop.
2. How to set cookies in PHP3.
3. www.apache.org The Apache Web server project.
4. www.php.net Homepage for PHP3 info and development.
5. ftp.cac.washington.edu/imap/ University of Washington's IMAP directory
6. www.imap.org/ The basics on IMAP.
7. http://horde.org/imp/ IMP, a much more advanced IMAP interface written in PHP3.

Bjørn Borud works as a systems engineer at Fast Search and Transfer ASA, which develops large-scale search engines and cutting-edge image compression software. In his copious spare time Bjørn reads, writes software, and sometimes writes articles for various publications.

Page 4 of 7

This article was originally published on May 25, 1999

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date