From: Sergio Villar SenĂ­n Date: Fri, 18 Dec 2009 12:45:42 +0000 (+0100) Subject: Do not allow to send messages to empty recipients X-Git-Tag: 3.2.7~4 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=2020def1c798df4a9a265583c32ea929b7fbedf9 Do not allow to send messages to empty recipients Fixes NB#151328 --- diff --git a/src/hildon2/modest-address-book.c b/src/hildon2/modest-address-book.c index b26b80d..9ec4b66 100644 --- a/src/hildon2/modest-address-book.c +++ b/src/hildon2/modest-address-book.c @@ -733,6 +733,7 @@ modest_address_book_check_names (ModestRecptEditor *recpt_editor, gint offset_delta = 0; gint last_length; GtkTextIter start_iter, end_iter; + gboolean empty_recipients = 0; g_return_val_if_fail (MODEST_IS_RECPT_EDITOR (recpt_editor), FALSE); @@ -771,6 +772,7 @@ modest_address_book_check_names (ModestRecptEditor *recpt_editor, /* Ignore empty addresses */ if (!g_strcmp0 (address, "")) { g_free (address); + empty_recipients++; goto next_address; } @@ -884,6 +886,10 @@ modest_address_book_check_names (ModestRecptEditor *recpt_editor, gtk_text_buffer_place_cursor (buffer, &end_iter); } + /* Check that at least there is one non-empty recipient */ + if ((g_slist_length (start_indexes) - empty_recipients) == 0) + result = FALSE; + g_slist_foreach (start_indexes, (GFunc) g_free, NULL); g_slist_foreach (end_indexes, (GFunc) g_free, NULL); g_slist_free (start_indexes); diff --git a/src/hildon2/modest-msg-edit-window.c b/src/hildon2/modest-msg-edit-window.c index 22c8466..b980993 100644 --- a/src/hildon2/modest-msg-edit-window.c +++ b/src/hildon2/modest-msg-edit-window.c @@ -3391,14 +3391,18 @@ modest_msg_edit_window_check_names (ModestMsgEditWindow *window, gboolean add_to { ModestMsgEditWindowPrivate *priv = NULL; GSList *address_list = NULL; + gboolean no_to, no_cc, no_bcc; g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window), FALSE); priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); /* check if there's no recipient added */ - if ((gtk_text_buffer_get_char_count (modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->to_field))) == 0) && - (gtk_text_buffer_get_char_count (modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->cc_field))) == 0) && - (gtk_text_buffer_get_char_count (modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->bcc_field))) == 0)) { + no_to = modest_text_utils_no_recipient (modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->to_field))); + no_cc = modest_text_utils_no_recipient (modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->cc_field))); + no_bcc = modest_text_utils_no_recipient (modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->bcc_field))); + + + if (no_to && no_cc && no_bcc) { /* no recipient contents, then select contacts */ modest_msg_edit_window_open_addressbook (window, NULL); return FALSE; @@ -3406,19 +3410,19 @@ modest_msg_edit_window_check_names (ModestMsgEditWindow *window, gboolean add_to /* Check names */ g_object_ref (window); - if (!modest_address_book_check_names (MODEST_RECPT_EDITOR (priv->to_field), + if (!no_to && !modest_address_book_check_names (MODEST_RECPT_EDITOR (priv->to_field), (add_to_addressbook) ? &address_list : NULL)) { modest_recpt_editor_grab_focus (MODEST_RECPT_EDITOR (priv->to_field)); g_object_unref (window); return FALSE; } - if (!modest_address_book_check_names (MODEST_RECPT_EDITOR (priv->cc_field), + if (!no_cc && !modest_address_book_check_names (MODEST_RECPT_EDITOR (priv->cc_field), (add_to_addressbook) ? &address_list : NULL)) { modest_recpt_editor_grab_focus (MODEST_RECPT_EDITOR (priv->cc_field)); g_object_unref (window); return FALSE; } - if (!modest_address_book_check_names (MODEST_RECPT_EDITOR (priv->bcc_field), + if (!no_bcc && !modest_address_book_check_names (MODEST_RECPT_EDITOR (priv->bcc_field), (add_to_addressbook) ? &address_list : NULL)) { modest_recpt_editor_grab_focus (MODEST_RECPT_EDITOR (priv->bcc_field)); g_object_unref (window); diff --git a/src/modest-text-utils.c b/src/modest-text-utils.c index fb4da84..91b9ef9 100644 --- a/src/modest-text-utils.c +++ b/src/modest-text-utils.c @@ -2243,3 +2243,39 @@ modest_text_utils_quote_names (const gchar *recipients) return g_string_free (str, FALSE); } + +/* Returns TRUE if there is no recipients in the text buffer. Note + that strings like " ; , " contain only separators and thus no + recipients */ +gboolean +modest_text_utils_no_recipient (GtkTextBuffer *buffer) +{ + gboolean retval = TRUE; + gchar *text, *tmp; + GtkTextIter start, end; + + if (gtk_text_buffer_get_char_count (buffer) == 0) + return TRUE; + + gtk_text_buffer_get_start_iter (buffer, &start); + gtk_text_buffer_get_end_iter (buffer, &end); + + text = g_strstrip (gtk_text_buffer_get_text (buffer, &start, &end, FALSE)); + if (!g_strcmp0 (text, "")) + return TRUE; + + tmp = text; + while (tmp && *tmp != '\0') { + if ((*tmp != ',') && (*tmp != ';') && + (*tmp != '\r') && (*tmp != '\n') && + (*tmp != ' ')) { + retval = FALSE; + break; + } else { + tmp++; + } + } + g_free (text); + + return retval; +} diff --git a/src/modest-text-utils.h b/src/modest-text-utils.h index 00c42ca..50f4ee4 100644 --- a/src/modest-text-utils.h +++ b/src/modest-text-utils.h @@ -567,4 +567,6 @@ gchar * modest_text_utils_get_secure_header (const gchar *value, const gchar *he **/ gchar * modest_text_utils_quote_names (const gchar *recipients); +gboolean modest_text_utils_no_recipient (GtkTextBuffer *buffer); + #endif /* __MODEST_TEXT_UTILS_H__ */ diff --git a/src/modest-ui-dimming-rules.c b/src/modest-ui-dimming-rules.c index 71fa5dd..6261ca9 100644 --- a/src/modest-ui-dimming-rules.c +++ b/src/modest-ui-dimming-rules.c @@ -1876,7 +1876,7 @@ modest_ui_dimming_rules_on_editor_remove_attachment (ModestWindow *win, gpointer return dimmed; } -gboolean +gboolean modest_ui_dimming_rules_on_send (ModestWindow *win, gpointer user_data) { ModestDimmingRule *rule = NULL; @@ -1906,6 +1906,14 @@ modest_ui_dimming_rules_on_send (ModestWindow *win, gpointer user_data) dimmed = ((gtk_text_buffer_get_char_count (to_buffer) + gtk_text_buffer_get_char_count (cc_buffer) + gtk_text_buffer_get_char_count (bcc_buffer)) == 0); + + if (!dimmed) { + if (modest_text_utils_no_recipient (to_buffer) && + modest_text_utils_no_recipient (cc_buffer) && + modest_text_utils_no_recipient (bcc_buffer)) + dimmed = TRUE; + } + if (dimmed) modest_dimming_rule_set_notification (rule, _("mcen_ib_add_recipients_first")); }