1 /* Copyright (c) 2007, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <glib/gstdio.h>
33 #include <string.h> /* for strlen */
34 #include <modest-runtime.h>
35 #include <libgnomevfs/gnome-vfs.h>
36 #include <tny-fs-stream.h>
37 #include <tny-camel-account.h>
38 #include <tny-status.h>
39 #include <tny-camel-transport-account.h>
40 #include <tny-camel-imap-store-account.h>
41 #include <tny-camel-pop-store-account.h>
43 #include <modest-defs.h>
44 #include "modest-utils.h"
45 #include "modest-platform.h"
46 #include <modest-account-protocol.h>
47 #include "modest-account-mgr-helpers.h"
48 #include "modest-text-utils.h"
49 #include <modest-local-folder-info.h>
50 #include "widgets/modest-header-view.h"
51 #include "widgets/modest-main-window.h"
52 #include "modest-widget-memory.h"
53 #include "widgets/modest-sort-criterium-view.h"
54 #ifdef MODEST_TOOLKIT_HILDON2
55 #include "modest-header-window.h"
59 modest_utils_get_supported_secure_authentication_error_quark (void)
61 return g_quark_from_static_string("modest-utils-get-supported-secure-authentication-error-quark");
65 modest_utils_folder_writable (const gchar *filename)
67 g_return_val_if_fail (filename, FALSE);
72 if (g_strncasecmp (filename, "obex", 4) != 0) {
73 GnomeVFSFileInfo *folder_info = NULL;
74 GnomeVFSResult result = GNOME_VFS_OK;
75 GnomeVFSURI *uri = NULL;
76 GnomeVFSURI *folder_uri = NULL;
78 uri = gnome_vfs_uri_new (filename);
79 folder_uri = gnome_vfs_uri_get_parent (uri);
81 if (folder_uri != NULL) {
82 folder_info = gnome_vfs_file_info_new ();
83 result = gnome_vfs_get_file_info_uri (folder_uri, folder_info,
84 GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS);
85 gnome_vfs_uri_unref (folder_uri);
87 gnome_vfs_uri_unref (uri);
89 if (folder_uri == NULL)
92 if ((result != GNOME_VFS_OK) ||
93 (!((folder_info->permissions & GNOME_VFS_PERM_ACCESS_WRITABLE) ||
94 (folder_info->permissions & GNOME_VFS_PERM_USER_WRITE)))) {
96 gnome_vfs_file_info_unref (folder_info);
99 gnome_vfs_file_info_unref (folder_info);
105 modest_utils_file_exists (const gchar *filename)
107 GnomeVFSURI *uri = NULL;
108 gboolean result = FALSE;
110 g_return_val_if_fail (filename, FALSE);
112 uri = gnome_vfs_uri_new (filename);
114 result = gnome_vfs_uri_exists (uri);
115 gnome_vfs_uri_unref (uri);
121 modest_utils_create_temp_stream (const gchar *orig_name, const gchar *hash_base, gchar **path)
124 gchar *filepath = NULL;
128 /* hmmm... maybe we need a modest_text_utils_validate_file_name? */
129 g_return_val_if_fail (orig_name && strlen(orig_name) != 0, NULL);
131 if (strlen(orig_name) > 200) {
132 g_warning ("%s: filename too long ('%s')",
133 __FUNCTION__, orig_name);
137 if (g_strstr_len (orig_name, strlen(orig_name), "/") != NULL) {
138 g_warning ("%s: filename contains '/' character(s) (%s)",
139 __FUNCTION__, orig_name);
143 /* make a random subdir under /tmp or /var/tmp */
144 if (hash_base != NULL) {
145 hash_number = g_str_hash (hash_base);
147 hash_number = (guint) random ();
149 tmpdir = g_strdup_printf ("%s/%u", g_get_tmp_dir (), hash_number);
150 if ((g_access (tmpdir, R_OK) == -1) && (g_mkdir (tmpdir, 0755) == -1)) {
151 g_warning ("%s: failed to create dir '%s': %s",
152 __FUNCTION__, tmpdir, g_strerror(errno));
157 filepath = g_strconcat (tmpdir, "/", orig_name, NULL);
158 /* don't overwrite if it already exists, even if it is writable */
159 if (modest_utils_file_exists (filepath)) {
168 /* try to write the file there */
169 fd = g_open (filepath, O_CREAT|O_WRONLY|O_TRUNC, 0644);
171 g_warning ("%s: failed to create '%s': %s",
172 __FUNCTION__, filepath, g_strerror(errno));
184 return TNY_FS_STREAM (tny_fs_stream_new (fd));
192 } ModestGetSupportedAuthInfo;
195 on_idle_secure_auth_finished (gpointer user_data)
197 /* Operation has finished, close the dialog. Control continues after
198 * gtk_dialog_run in modest_utils_get_supported_secure_authentication_methods() */
199 gdk_threads_enter(); /* CHECKED */
200 gtk_dialog_response (GTK_DIALOG (user_data), GTK_RESPONSE_ACCEPT);
201 gdk_threads_leave(); /* CHECKED */
207 on_camel_account_get_supported_secure_authentication (TnyCamelAccount *self,
213 ModestPairList *pairs;
215 ModestProtocolRegistry *protocol_registry;
216 ModestGetSupportedAuthInfo *info = (ModestGetSupportedAuthInfo*)user_data;
219 g_return_if_fail (user_data);
220 g_return_if_fail (TNY_IS_CAMEL_ACCOUNT(self));
221 g_return_if_fail (TNY_IS_LIST(auth_types));
223 info = (ModestGetSupportedAuthInfo *) user_data;
225 /* Free everything if the actual action was canceled */
227 g_debug ("%s: operation canceled\n", __FUNCTION__);
232 g_debug ("%s: error getting the supported auth methods\n", __FUNCTION__);
237 g_debug ("%s: auth_types is NULL.\n", __FUNCTION__);
241 if (tny_list_get_length(auth_types) == 0) {
242 g_debug ("%s: auth_types is an empty TnyList.\n", __FUNCTION__);
246 protocol_registry = modest_runtime_get_protocol_registry ();
247 pairs = modest_protocol_registry_get_pair_list_by_tag (protocol_registry, MODEST_PROTOCOL_REGISTRY_AUTH_PROTOCOLS);
249 /* Get the enum value for the strings: */
251 iter = tny_list_create_iterator(auth_types);
252 while (!tny_iterator_is_done(iter)) {
254 const gchar *auth_name;
255 ModestProtocolType protocol_type;
257 pair = TNY_PAIR(tny_iterator_get_current(iter));
260 auth_name = tny_pair_get_name(pair);
261 g_object_unref (pair);
265 g_debug ("%s: auth_name=%s\n", __FUNCTION__, auth_name);
267 protocol_type = modest_protocol_get_type_id (modest_protocol_registry_get_protocol_by_name (protocol_registry,
268 MODEST_PROTOCOL_REGISTRY_AUTH_PROTOCOLS,
271 if (modest_protocol_registry_protocol_type_is_secure (protocol_registry, protocol_type))
272 result = g_list_prepend(result, GINT_TO_POINTER(protocol_type));
274 tny_iterator_next(iter);
276 g_object_unref (iter);
278 modest_pair_list_free (pairs);
279 *(info->result) = result;
282 /* Close the dialog in a main thread */
283 g_idle_add(on_idle_secure_auth_finished, info->dialog);
286 g_slice_free (ModestGetSupportedAuthInfo, info);
291 gboolean not_finished;
295 keep_pulsing (gpointer user_data)
297 KeepPulsing *info = (KeepPulsing *) user_data;
299 if (!info->not_finished) {
300 g_slice_free (KeepPulsing, info);
304 gtk_progress_bar_pulse (GTK_PROGRESS_BAR (info->progress));
309 modest_utils_get_supported_secure_authentication_methods (ModestProtocolType protocol_type,
310 const gchar* hostname,
312 const gchar* username,
313 GtkWindow *parent_window,
316 TnyAccount * tny_account = NULL;
317 ModestProtocolRegistry *protocol_registry;
320 ModestTnyAccountStore *account_store;
321 TnySessionCamel *session = NULL;
322 ModestProtocol *protocol = NULL;
323 GList *result = NULL;
326 g_return_val_if_fail (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID, NULL);
328 protocol_registry = modest_runtime_get_protocol_registry ();
330 /* We need a connection to get the capabilities; */
331 if (!modest_platform_connect_and_wait (GTK_WINDOW (parent_window), NULL))
334 /* Create a TnyCamelAccount so we can use
335 * tny_camel_account_get_supported_secure_authentication(): */
336 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
338 if (MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
339 tny_account = modest_account_protocol_create_account (MODEST_ACCOUNT_PROTOCOL (protocol));
343 g_printerr ("%s could not create tny account.", __FUNCTION__);
347 /* Set proto, so that the prepare_func() vfunc will work when
348 * we call set_session(): */
349 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
350 tny_account_set_id (tny_account, "temp_account");
351 tny_account_set_proto (tny_account, modest_protocol_get_name (protocol));
352 tny_account_set_hostname (tny_account, hostname);
353 tny_account_set_user (tny_account, username);
356 tny_account_set_port (tny_account, port);
358 /* Set the session for the account, so we can use it: */
359 account_store = modest_runtime_get_account_store ();
360 session = modest_tny_account_store_get_session (TNY_ACCOUNT_STORE (account_store));
361 g_return_val_if_fail (session, NULL);
362 tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account), session);
364 dialog = gtk_dialog_new_with_buttons(" ",
366 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
367 _("mcen_bd_dialog_cancel"),
371 /* Ask camel to ask the server, asynchronously: */
372 ModestGetSupportedAuthInfo *info = g_slice_new (ModestGetSupportedAuthInfo);
373 info->result = &result;
374 info->dialog = dialog;
376 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(info->dialog)->vbox),
377 gtk_label_new(_("emev_ni_checking_supported_auth_methods")));
378 progress = gtk_progress_bar_new();
379 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(info->dialog)->vbox), progress);
380 gtk_widget_show_all(info->dialog);
382 KeepPulsing *pi = g_slice_new (KeepPulsing);
383 pi->progress = progress;
384 pi->not_finished = TRUE;
386 /* Starts the pulsing of the progressbar */
387 g_timeout_add (500, keep_pulsing, pi);
389 tny_camel_account_get_supported_secure_authentication (TNY_CAMEL_ACCOUNT (tny_account),
390 on_camel_account_get_supported_secure_authentication,
394 retval = gtk_dialog_run (GTK_DIALOG (info->dialog));
396 pi->not_finished = FALSE;
397 /* pi is freed in the timeout itself to avoid a GCond here */
399 gtk_widget_destroy(dialog);
402 tny_account_cancel (tny_account);
403 g_object_unref (tny_account);
409 modest_utils_show_dialog_and_forget (GtkWindow *parent_window,
412 g_return_if_fail (GTK_IS_WINDOW(parent_window));
413 g_return_if_fail (GTK_IS_DIALOG(dialog));
415 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent_window);
417 /* Destroy the dialog when it is closed: */
418 g_signal_connect_swapped (dialog,
420 G_CALLBACK (gtk_widget_destroy),
423 gtk_widget_show (GTK_WIDGET (dialog));
427 modest_utils_toggle_action_set_active_block_notify (GtkToggleAction *action, gboolean value)
429 GSList *proxies = NULL;
431 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
433 for (proxies = gtk_action_get_proxies (GTK_ACTION (action));
434 proxies != NULL; proxies = g_slist_next (proxies)) {
435 GtkWidget *widget = (GtkWidget *) proxies->data;
436 gtk_action_block_activate_from (GTK_ACTION (action), widget);
439 gtk_toggle_action_set_active (action, value);
441 for (proxies = gtk_action_get_proxies (GTK_ACTION (action));
442 proxies != NULL; proxies = g_slist_next (proxies)) {
443 GtkWidget *widget = (GtkWidget *) proxies->data;
444 gtk_action_unblock_activate_from (GTK_ACTION (action), widget);
451 modest_list_index (TnyList *list, GObject *object)
456 g_return_val_if_fail (TNY_IS_LIST(list), -1);
457 g_return_val_if_fail (G_IS_OBJECT(object), -1);
459 iter = tny_list_create_iterator (list);
460 while (!tny_iterator_is_done (iter)) {
461 GObject *current = tny_iterator_get_current (iter);
463 g_object_unref (current);
464 if (current == object)
467 tny_iterator_next (iter);
471 if (tny_iterator_is_done (iter))
473 g_object_unref (iter);
478 modest_utils_get_available_space (const gchar *maildir_path)
483 GnomeVFSFileSize size;
485 folder = modest_local_folder_info_get_maildir_path (maildir_path);
486 uri_string = gnome_vfs_get_uri_from_local_path (folder);
487 uri = gnome_vfs_uri_new (uri_string);
492 if (gnome_vfs_get_volume_free_space (uri, &size) != GNOME_VFS_OK)
494 gnome_vfs_uri_unref (uri);
499 return (guint64) size;
502 on_destroy_dialog (GtkDialog *dialog)
504 gtk_widget_destroy (GTK_WIDGET(dialog));
505 if (gtk_events_pending ())
506 gtk_main_iteration ();
510 checked_modest_sort_criterium_view_add_sort_key (ModestSortCriteriumView *view, const gchar* key, guint max)
514 g_return_val_if_fail (view && MODEST_IS_SORT_CRITERIUM_VIEW(view), 0);
515 g_return_val_if_fail (key, 0);
517 sort_key = modest_sort_criterium_view_add_sort_key (view, key);
518 if (sort_key < 0 || sort_key >= max) {
519 g_warning ("%s: out of range (%d) for %s", __FUNCTION__, sort_key, key);
522 return (guint)sort_key;
526 launch_sort_headers_dialog (GtkWindow *parent_window,
529 ModestHeaderView *header_view = NULL;
531 GtkSortType sort_type;
533 gint default_key = 0;
535 gboolean outgoing = FALSE;
536 gint current_sort_colid = -1;
537 GtkSortType current_sort_type;
538 gint attachments_sort_id;
539 gint priority_sort_id;
540 GtkTreeSortable *sortable;
542 /* Get header window */
543 if (MODEST_IS_MAIN_WINDOW (parent_window)) {
544 header_view = MODEST_HEADER_VIEW(modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(parent_window),
545 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW));
546 #ifdef MODEST_TOOLKIT_HILDON2
547 } else if (MODEST_IS_HEADER_WINDOW (parent_window)) {
548 header_view = MODEST_HEADER_VIEW (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (parent_window)));
555 /* Add sorting keys */
556 cols = modest_header_view_get_columns (header_view);
559 #define SORT_ID_NUM 6
560 int sort_model_ids[SORT_ID_NUM];
561 int sort_ids[SORT_ID_NUM];
563 outgoing = (GPOINTER_TO_INT (g_object_get_data(G_OBJECT(cols->data), MODEST_HEADER_VIEW_COLUMN))==
564 MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT);
566 sort_key = checked_modest_sort_criterium_view_add_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog), _("mcen_li_sort_sender_recipient"),
569 sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_TO_COLUMN;
570 sort_ids[sort_key] = MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT;
572 sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN;
573 sort_ids[sort_key] = MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_IN;
576 sort_key = checked_modest_sort_criterium_view_add_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog), _("mcen_li_sort_date"),
579 sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_DATE_SENT_TIME_T_COLUMN;
580 sort_ids[sort_key] = MODEST_HEADER_VIEW_COLUMN_COMPACT_SENT_DATE;
582 sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_DATE_RECEIVED_TIME_T_COLUMN;
583 sort_ids[sort_key] = MODEST_HEADER_VIEW_COLUMN_COMPACT_RECEIVED_DATE;
585 default_key = sort_key;
587 sort_key = checked_modest_sort_criterium_view_add_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog), _("mcen_li_sort_subject"),
589 sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_SUBJECT_COLUMN;
591 sort_ids[sort_key] = MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT;
593 sort_ids[sort_key] = MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_IN;
595 sort_key = checked_modest_sort_criterium_view_add_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog), _("mcen_li_sort_attachment"),
597 sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN;
598 sort_ids[sort_key] = TNY_HEADER_FLAG_ATTACHMENTS;
599 attachments_sort_id = sort_key;
601 sort_key = checked_modest_sort_criterium_view_add_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog), _("mcen_li_sort_size"),
603 sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_MESSAGE_SIZE_COLUMN;
604 sort_ids[sort_key] = 0;
606 sort_key = checked_modest_sort_criterium_view_add_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog), _("mcen_li_sort_priority"),
608 sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN;
609 sort_ids[sort_key] = TNY_HEADER_FLAG_PRIORITY_MASK;
610 priority_sort_id = sort_key;
612 sortable = GTK_TREE_SORTABLE (gtk_tree_model_filter_get_model
613 (GTK_TREE_MODEL_FILTER (gtk_tree_view_get_model (GTK_TREE_VIEW (header_view)))));
615 if (!gtk_tree_sortable_get_sort_column_id (sortable,
616 ¤t_sort_colid, ¤t_sort_type)) {
617 modest_sort_criterium_view_set_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog), default_key);
618 modest_sort_criterium_view_set_sort_order (MODEST_SORT_CRITERIUM_VIEW (dialog), GTK_SORT_DESCENDING);
620 modest_sort_criterium_view_set_sort_order (MODEST_SORT_CRITERIUM_VIEW (dialog), current_sort_type);
621 if (current_sort_colid == TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN) {
622 gpointer flags_sort_type_pointer;
623 flags_sort_type_pointer = g_object_get_data (G_OBJECT (cols->data), MODEST_HEADER_VIEW_FLAG_SORT);
624 if (GPOINTER_TO_INT (flags_sort_type_pointer) == TNY_HEADER_FLAG_PRIORITY_MASK)
625 modest_sort_criterium_view_set_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog), priority_sort_id);
627 modest_sort_criterium_view_set_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog), attachments_sort_id);
629 gint current_sort_keyid = 0;
630 while (current_sort_keyid < SORT_ID_NUM) {
631 if (sort_model_ids[current_sort_keyid] == current_sort_colid)
634 current_sort_keyid++;
636 modest_sort_criterium_view_set_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog), current_sort_keyid);
640 result = gtk_dialog_run (GTK_DIALOG (dialog));
641 if (result == GTK_RESPONSE_OK) {
642 sort_key = modest_sort_criterium_view_get_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog));
643 if (sort_key < 0 || sort_key > SORT_ID_NUM -1) {
644 g_warning ("%s: out of range (%d)", __FUNCTION__, sort_key);
648 sort_type = modest_sort_criterium_view_get_sort_order (MODEST_SORT_CRITERIUM_VIEW (dialog));
649 if (sort_model_ids[sort_key] == TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN) {
650 g_object_set_data (G_OBJECT(cols->data), MODEST_HEADER_VIEW_FLAG_SORT,
651 GINT_TO_POINTER (sort_ids[sort_key]));
652 /* This is a hack to make it resort rows always when flag fields are
653 * selected. If we do not do this, changing sort field from priority to
654 * attachments does not work */
655 modest_header_view_sort_by_column_id (header_view, 0, sort_type);
657 gtk_tree_view_column_set_sort_column_id (GTK_TREE_VIEW_COLUMN (cols->data),
658 sort_model_ids[sort_key]);
661 modest_header_view_sort_by_column_id (header_view, sort_model_ids[sort_key], sort_type);
662 gtk_tree_sortable_sort_column_changed (sortable);
665 modest_widget_memory_save (modest_runtime_get_conf (),
666 G_OBJECT (header_view), MODEST_CONF_HEADER_VIEW_KEY);
673 modest_utils_run_sort_dialog (GtkWindow *parent_window,
674 ModestSortDialogType type)
676 GtkWidget *dialog = NULL;
679 dialog = modest_platform_create_sort_dialog (parent_window);
682 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
683 GTK_WINDOW (dialog), parent_window);
687 case MODEST_SORT_HEADERS:
688 launch_sort_headers_dialog (parent_window,
694 on_destroy_dialog (GTK_DIALOG(dialog));
699 modest_images_cache_get_id (const gchar *account, const gchar *uri)
701 GnomeVFSURI *vfs_uri;
704 vfs_uri = gnome_vfs_uri_new (uri);
708 result = g_strdup_printf ("%s__%x", account, gnome_vfs_uri_hash (vfs_uri));
709 gnome_vfs_uri_unref (vfs_uri);
715 modest_utils_get_account_name_from_recipient (const gchar *from_header)
717 gchar *account_name = NULL;
718 ModestAccountMgr *mgr = NULL;
719 GSList *accounts = NULL, *node = NULL;
721 g_return_val_if_fail (from_header, NULL);
723 mgr = modest_runtime_get_account_mgr ();
724 accounts = modest_account_mgr_account_names (mgr, TRUE);
726 for (node = accounts; node != NULL; node = g_slist_next (node)) {
728 modest_account_mgr_get_from_string (mgr, node->data);
732 modest_text_utils_get_email_address (from);
733 gchar *from_header_email =
734 modest_text_utils_get_email_address (from_header);
736 if (from_email && from_header_email) {
737 if (!modest_text_utils_utf8_strcmp (from_header_email, from_email, TRUE)) {
738 account_name = g_strdup (node->data);
745 g_free (from_header_email);
749 g_slist_foreach (accounts, (GFunc) g_free, NULL);
750 g_slist_free (accounts);
756 modest_utils_on_entry_invalid_character (ModestValidatingEntry *self,
757 const gchar* character,
760 gchar *message = NULL;
761 const gchar *show_char = NULL;
764 show_char = character;
769 message = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), show_char);
770 modest_platform_information_banner (GTK_WIDGET (self), NULL, message);