+/**
+ * Reads the message whose summary item is @header. It takes care of
+ * several things, among others:
+ *
+ * If the message was not previously downloaded then ask the user
+ * before downloading. If there is no connection launch the connection
+ * dialog. Update toolbar dimming rules.
+ *
+ * Returns: TRUE if the mail operation was started, otherwise if the
+ * user do not want to download the message, or if the user do not
+ * want to connect, then the operation is not issued
+ **/
+static gboolean
+message_reader (ModestMsgViewWindow *window,
+ ModestMsgViewWindowPrivate *priv,
+ TnyHeader *header,
+ GtkTreeIter iter)
+{
+ ModestMailOperation *mail_op = NULL;
+ GtkTreePath *path = NULL;
+ ModestMailOperationTypeOperation op_type;
+
+ /* Msg download completed */
+ if (tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED) {
+ op_type = MODEST_MAIL_OPERATION_TYPE_OPEN;
+ } else {
+ TnyFolder *folder;
+ GtkResponseType response;
+
+ op_type = MODEST_MAIL_OPERATION_TYPE_RECEIVE;
+
+ /* Ask the user if he wants to download the message */
+ response = modest_platform_run_confirmation_dialog (GTK_WINDOW (window),
+ _("mcen_nc_get_msg"));
+ if (response == GTK_RESPONSE_CANCEL)
+ return FALSE;
+
+ /* Offer the connection dialog if necessary */
+ /* FIXME: should this stuff go directly to the mail
+ operation instead of spread it all over the
+ code? */
+ folder = tny_header_get_folder (header);
+ if (folder) {
+ if (!modest_platform_connect_and_wait_if_network_folderstore (NULL, TNY_FOLDER_STORE (folder))) {
+ g_object_unref (folder);
+ return FALSE;
+ }
+ g_object_unref (folder);
+ }
+ }
+
+ /* Get the path, will be freed by the callback */
+ path = gtk_tree_model_get_path (priv->header_model, &iter);
+
+ /* New mail operation */
+ mail_op = modest_mail_operation_new_with_error_handling (op_type,
+ G_OBJECT(window),
+ modest_ui_actions_get_msgs_full_error_handler,
+ NULL);
+
+ modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
+ modest_mail_operation_get_msg (mail_op, header, view_msg_cb, path);
+ g_object_unref (mail_op);
+
+ /* Update toolbar dimming rules */
+ modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
+
+ return TRUE;
+}
+