Differences between revisions 10 and 11
Revision 10 as of 2008-03-12 03:41:02
Size: 2864
Editor: TimoSirainen
Revision 11 as of 2009-03-15 22:47:46
Size: 2864
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

Showing Opened Message

Usually clients show some interesting message headers, message's plaintext body and attachment icons if there are any.

The most important thing is to avoid fetching the entire message body. If the message has 1MB attachment, there's no need to download it until user has expressed interest in opening or saving it. You can do this by parsing BODY or BODYSTRUCTURE reply and fetching only the MIME parts you're going to show.

If you already fetched BODY or BODYSTRUCTURE when showing message list, you can fetch everything with one command:


RFC822.HEADER can be used to fetch the whole header, which by this time should be pretty cheap since you're fetching the message body as well. However if you're interested of only a few specific headers (and you should already know some of them from message list!), you can fetch them instead:


If you don't know the BODY or BODYSTRUCTURE before opening the message, you'll need two commands:

* FETCH (...)
1 OK

Fetching attachments

If you're fetching a large attachment, it's no excuse to have your user interface unresponsive until the download is complete. You have two choices to prevent this:

  1. Create a new connection (or use another existing one), open the mailbox with EXAMINE (because some servers allow mailbox to be SELECTed only once) and download the attachment using it.
  2. Fetch the attachment in pieces: FETCH 1 BODY.PEEK[2]<0.102400>, wait for OK, FETCH 1 BODY.PEEK[2]<102401.204800>, etc. The block size should be large enough so that network latency doesn't add too much wasted time, but small enough that any other more important commands can be executed without too much delay.

In both of these cases it's useful to know the approximate latency and available bandwidth between the client and the server. If you know that simply sending a single FETCH command to download the entire message takes less time than using a separate connection, then there's no point in doing that. The block size can be also be dynamically adjusted so that each FETCH request takes for example a second.

You can calculate the latency easily by keeping track of how long it typically takes for server to answer commands that shouldn't be resource intensive (e.g. CAPABILITY, LOGIN, LIST). If you don't know the bandwidth, pick a small enough block size initially and keep growing it.

With high latency links (e.g. 0,3sec+) creating a second connection is probably a better idea than fetching in small blocks, because a lot of time can be wasted on waiting for the OK replies. With low latency links it's probably better to use partial fetches.

ClientImplementation/OpenMessage (last edited 2009-03-15 22:47:46 by localhost)