Log In
New Account
Home My Page Project Cloud Code Snippets Project Openings modest
Summary Lists SCM Wiki

Modest Mime Handling

Handling of Mime in Modest

Mime messages structure

This is a list of examples of how a message is usually structured. We'll explain this with the following notation:

part_mime_type (subpart1_mime_type subpart2_mime_type (subsubpart21_mime_type subsubpart22_mime_type))

Plain text message without attachments


Rich text message without attachments

multipart/alternative (text/plain text/html)

Plain text message with attachments (two images)

multipart/mixed (text/plain image/jpeg image/png)

Rich text message with attachments (two images)

multipart/mixed (multipart/alternative (text/plain text/html) image/jpeg image/png)

Rich text message without attachments with embedded images

multipart/alternative (text/plain multipart/related (text/html image/jpeg image/png))

Rich text message with attachments (a video) and embedded images

multipart/mixed (multipart/alternate (text/plain multipart/related (text/html image/jpeg image/png)) video/avi)

Tinymail mime processing

In modest we use Tinymail objects to represent the mime messages and the parts. The main objects creating mime messages are:

  • TnyMimePart: it represents just a mime part. If it's a multipart it can have subparts
  • TnyMsg: represents a message. It inherits from TnyMimePart, and holds a reference to TnyHeader.
  • TnyHeader: represents the basic information of a header of a message (recipients, subject, flags,...)

Access to submimeparts

If a TnyMimePart has a multipart content type, then you can access its subparts with tny_mime_part_get_parts.

Some notes:

  • An embedded message is a subpart of a message that is also a TnyMsg.
  • The content type is the mime type of the stuff inside.
  • TnyMimePart allows to fetch the headers of the part, with method tny_mime_part_get_header_pairs.
  • The contents of the mime part are exposed as stream. You can retrieve a raw stream with tny_mime_part_get_stream. And you can obtain a decoded stream with tny_mime_part_decode_to_stream.

Some typical multipart containers are:

  • multipart/alternate: alternate representations of the same message. I.e. plain text and html text. A rich message (message in html) should include an alternative representation in plain text.
  • multipart/related: a document (root) and its related documents (documents root refers to). It's used for embedded images. Root document is the html document, and the related parts are the images. The root document refers to the images by their content id.
  • multipart/mixed: usually used to put non related stuff. It's usually for creating a message with its attachments. One of the parts would be the body representation, and the other parts are the attachments.
  • multipart/digest: contains a digest of messages. First part is usually an index, and the other parts are TnyMsg.
  • multipart/signed: in gpg, one part is the message, and the other is the gpg signature.

Creation of messages

Modest includes some helper methods to create the messages with the expected format. The code is in modest-tny-msg.c, modest-formatter.c and modest-text-utils.c.

The main methods are:

  • modest_tny_msg_new (creating a plain text message)
  • modest_tny_msg_new_html_plain (creating a rich text message)
  • modest_tny_msg_create_forward_msg, modest_tny_msg_create_reply_msg

These methods use modest_formatter to do the proper formatting (including signatures, quoting in reply and forward, etc):

  • modest_formatter_create_msg: creates the structure of mime parts of a message taking into account the information about the parts it will contain
  • modest_formatter_create_body_part: similar to the previous one. It's used to create one of the body parts and attach it to the proper place of the message.
  • modest_formatter_cite: creates a new reply message, with the original message inserted.
  • modest_formatter_quote: creates a new reply message, with the original message quoted.
  • modest_formatter_inline: creates a new forward message, with the original message inserted in body.
  • modest_formatter_attach: creates a new forward message, with the original message as attachment.

Mime usage helpers

  • modest_tny_msg_find_body_part: finds the body of a message. You can say if you prefer html or plain text body.
  • modest_tny_msg_get_body: obtains a buffer with the requested body of the message.
  • modest_tny_msg_estimate_size: does an estimation of the space the message will need. This is important on creating a message as you need to know if it will fit in storage.
  • modest_tny_mime_part_get_header_value: helper to obtain the value of a specific header.
  • modest_tny_mime_part_is_attachment_for_modest: very important method in modest, as we consider attachments things that tinymail doesn't, and viceversa. It refers to the things that we should show as attachments in the attachments views.
  • modest_tny_mime_part_is_msg: same as the previous one. We don't consider in modest all TnyMsg as messages. As sometimes a message can be a "direct attachment" (a message without body, and with a file as the only part). This is represented in modest as an attachment of an empty message.
  • modest_tny_mime_part_get_headers_content_type: obtains the content type in headers (sometimes it's different from the content type provided by tinymail). An example is message/rfc822 subparts. They're TnyMsg and tinymail tells it's message/rfc822. But we cannot know the content type of the part unless we use this.
  • modest_tny_mime_part_get_content_type: it shows the content mime type (tny_mime_part_get_content_type value, and if it's message/rfc822, the headers content type).

(last edited February 5, 2010) - Read Only [info] [diff])
FindPage by browsing or searching
5 best incoming links: ModestArchitecture (5), RecentChanges (5)
5 best outgoing links:
5 most popular nearby: ModestArchitecture (4039), RecentChanges (697)

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment