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

New Message Sequence

Sequence description: create and send a new message

Steps to show the editor on tapping new message.


  • User taps on any view on **new message**.
  • modest_ui_actions_on_new_msg.
  • Checks if there are accounts available. If not, then it shows the account wizard.
  • modest_ui_actions_compose_msg:
	 * Previous checks: memory low (not enough RAM), not enough available space (disk)
	 * Gets the account name (and mailbox) for the caller window. Used for setting the proper From: field.
	 * Obtain the drafts folder. Just to check it exists.
	 * modest_account_mgr_get_from_string: obtain the From: string for an account and mailbox (calling provider plugins if needed).
	 * Calculates the signature for the recipient.
	 * Creates the body contents (concatenates the empty body string and the signature, if used.
	 * modest_tny_msg_new_html_plain *****. Creates a TnyMsg instance.
	 * modest_msg_edit_window_new ****: creates the editor window with the newly created msg.
	 * Show the window.
	 * As it's new message use case, the code to add attachments will do nothing.


This method builds the TnyMsg instance used in ModestMsgEditWindow.

  • modest_formatter_create_message. It creates the structure of the message depending on some conditions (plain or rich text mail, has attachments or not, has embedded images or not). This is due to the different mime message structure in each case. So the result is a TnyMsg with the skeletton of Mime parts that will contain the real contents.
  • Takes the header of the created TnyMsg and fills it with the recipients, subject, and other headers.
  • Then it adds the body part and html body part. As the method receives strings for this, it will create the new parts (or fill the existing in TnyMsg if no new part is needed).
  • Adds the attachments (finding the proper parent, usually the multipart/mixed.
  • Adds the embedded images (finding the proper parent, usually the multipart/related.


This method creates a new edit window. In fact, construction may have happened before, as window manager includes a cache of msg edit windows, to try to have it precreated when user wants to open a new editor. This is due to the complexity of the window, that takes a big effort to be built.


  • Obtain the edit window instance from cache.
  • Obtain the from field choices (using the account manager), and sets current value depending on the account and mailbox.
  • Update branding (used in NMS to show icon and name of mail provider).
  • Set up toolbar and restore settings (i.e. cc and bcc toggles).
  • Set up dimming rules.
  • Setup menu.
  • Set the message (this puts the msg passed as an argument into the wpeditor). It's done getting the information from the message (contents, attachments, etc).

Sending a message


  • modest_ui_actions_on_send:
  • First we add contacts to addressbook if needed and requested.
  • We check if the addresses in recipients are ok.
  • We check if there's enough space on disk to save the message (this is needed as sending a message is really adding it to an outbox, which is a local folder).
  • We check if the account really exists, and find the proper transport account to use for sending.
  • modest_ui_actions_send_msg_with_transport: this method configures the sending:
	 * We create the mail operation for sending the new mail. modest_mail_operation_send_new_mail.

Send new mail mail operation

This mail operation, first, calls the mail operation "create_msg", that creates the TnyMsg? to be stored to outbox. Once it's created, the callback transferres the created message to the outbox using TnySendQueue?.

When the mail is added to outbox, it instructs modest to run the send queue with the mails queued.

The send queue is a decorated one that, when it's instructed to really send a mail from outbox, checks if it should use a connection specific smtp server.

Also, when the message is created and added to outbox, there's another asynchronous task that consists on removing the draft message (if any).

Other similar use cases

Closing editor without sending

We just save the message to drafts. But once it's saved, we remove the previous draft (if any).

Reply and forward

They are very similar. The main difference is in the process of creating the message to be passed to mail editor. The implementation is done in modest formatter and modest_tny_msg methods.

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

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment