+static gboolean
+enough_space_for_message (ModestMsgEditWindow *edit_window,
+ MsgData *data)
+{
+ TnyAccountStore *acc_store;
+ guint64 available_disk, expected_size;
+ gint parts_count;
+ guint64 parts_size;
+
+ /* Check size */
+ acc_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store());
+ available_disk = modest_utils_get_available_space (NULL);
+ modest_msg_edit_window_get_parts_size (edit_window, &parts_count, &parts_size);
+ expected_size = modest_tny_msg_estimate_size (data->plain_body,
+ data->html_body,
+ parts_count,
+ parts_size);
+
+ /* Double check: memory full condition or message too big */
+ if (available_disk < MIN_FREE_SPACE ||
+ expected_size > available_disk) {
+
+ modest_platform_information_banner (NULL, NULL,
+ dgettext("ke-recv",
+ "cerm_device_memory_full"));
+ return FALSE;
+ }
+
+ /*
+ * djcb: if we're in low-memory state, we only allow for
+ * saving messages smaller than
+ * MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE (see modest-defs.h) this
+ * should still allow for sending anything critical...
+ */
+ if ((expected_size > MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE) &&
+ modest_platform_check_memory_low (MODEST_WINDOW(edit_window), TRUE))
+ return FALSE;
+
+ /*
+ * djcb: we also make sure that the attachments are smaller than the max size
+ * this is for the case where we'd try to forward a message with attachments
+ * bigger than our max allowed size, or sending an message from drafts which
+ * somehow got past our checks when attaching.
+ */
+ if (expected_size > MODEST_MAX_ATTACHMENT_SIZE) {
+ modest_platform_run_information_dialog (
+ GTK_WINDOW(edit_window),
+ dgettext("ke-recv","memr_ib_operation_disabled"),
+ TRUE);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+