ESource * em_utils_ref_mail_identity_for_store (ESourceRegistry *registry, CamelStore *store) { ESourceMailAccount *extension; ESource *source; const gchar *extension_name; const gchar *store_uid; gchar *identity_uid; g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL); g_return_val_if_fail (CAMEL_IS_STORE (store), NULL); store_uid = camel_service_get_uid (CAMEL_SERVICE (store)); g_return_val_if_fail (store_uid != NULL, NULL); source = e_source_registry_ref_source (registry, store_uid); g_return_val_if_fail (source != NULL, NULL); extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT; extension = e_source_get_extension (source, extension_name); identity_uid = e_source_mail_account_dup_identity_uid (extension); g_object_unref (source); source = NULL; if (identity_uid != NULL) { source = e_source_registry_ref_source (registry, identity_uid); g_free (identity_uid); } return source; }
ESource * em_utils_guess_mail_account (ESourceRegistry *registry, CamelMimeMessage *message, CamelFolder *folder, const gchar *message_uid) { ESource *source = NULL; const gchar *newsgroups; g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL); g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), NULL); if (folder != NULL) g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL); /* check for newsgroup header */ newsgroups = camel_medium_get_header ( CAMEL_MEDIUM (message), "Newsgroups"); if (folder != NULL && newsgroups != NULL) source = guess_mail_account_from_folder (registry, folder, message_uid); /* check for source folder */ if (source == NULL && folder != NULL) source = guess_mail_account_from_folder (registry, folder, message_uid); /* then message source */ if (source == NULL) source = guess_mail_account_from_message (registry, message); return source; }
/** * e_cal_backend_mail_account_get_default: * @registry: an #ESourceRegistry * @address: placeholder for default address * @name: placeholder for name * * Retrieve the default mail account as stored in Evolution configuration. * * Returns: TRUE if there is a default account, FALSE otherwise. */ gboolean e_cal_backend_mail_account_get_default (ESourceRegistry *registry, gchar **address, gchar **name) { ESource *source; ESourceMailIdentity *extension; const gchar *extension_name; g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE); source = e_source_registry_ref_default_mail_identity (registry); if (source == NULL) return FALSE; extension_name = E_SOURCE_EXTENSION_MAIL_IDENTITY; extension = e_source_get_extension (source, extension_name); if (address != NULL) *address = e_source_mail_identity_dup_address (extension); if (name != NULL) *name = e_source_mail_identity_dup_name (extension); g_object_unref (source); return TRUE; }
/** * e_contact_locate_match_full: * @registry: an #ESourceRegistry * @book: The book to look in. If this is NULL, use the default * addressbook. * @contact: The contact to compare to. * @avoid: A list of contacts to not match. These will not show up in the search. * @cb: The function to call. * @closure: The closure to add to the call. * * Look for the best match and return it using the EABContactMatchQueryCallback. **/ void eab_contact_locate_match_full (ESourceRegistry *registry, EBookClient *book_client, EContact *contact, GList *avoid, EABContactMatchQueryCallback cb, gpointer closure) { MatchSearchInfo *info; ESource *source; g_return_if_fail (E_IS_SOURCE_REGISTRY (registry)); g_return_if_fail (E_IS_CONTACT (contact)); g_return_if_fail (cb != NULL); info = g_new0 (MatchSearchInfo, 1); info->contact = g_object_ref (contact); info->cb = cb; info->closure = closure; info->avoid = g_list_copy (avoid); g_list_foreach (info->avoid, (GFunc) g_object_ref, NULL); if (book_client) { use_common_book_client (g_object_ref (book_client), info); return; } source = e_source_registry_ref_default_address_book (registry); e_book_client_connect (source, 30, NULL, book_client_connect_cb, info); g_object_unref (source); }
gboolean eab_merging_book_modify_contact (ESourceRegistry *registry, EBookClient *book_client, EContact *contact, EABMergingAsyncCallback cb, gpointer closure) { EContactMergingLookup *lookup; g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE); lookup = g_new (EContactMergingLookup, 1); lookup->op = E_CONTACT_MERGING_COMMIT; lookup->registry = g_object_ref (registry); lookup->book_client = g_object_ref (book_client); lookup->contact = g_object_ref (contact); lookup->cb = cb; lookup->closure = closure; lookup->avoid = g_list_append (NULL, contact); lookup->match = NULL; add_lookup (lookup); return TRUE; }
gboolean eab_source_and_contact_list_from_string (ESourceRegistry *registry, const gchar *str, ESource **out_source, GSList **out_contacts) { ESource *source; const gchar *s0, *s1; gchar *uid; gboolean success = FALSE; g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE); g_return_val_if_fail (str != NULL, FALSE); if (out_source != NULL) *out_source = NULL; /* in case we fail */ if (out_contacts != NULL) *out_contacts = NULL; /* in case we fail */ if (!strncmp (str, "Book: ", 6)) { s0 = str + 6; s1 = strchr (str, '\r'); if (!s1) s1 = strchr (str, '\n'); } else { s0 = NULL; s1 = NULL; } if (!s0 || !s1) return FALSE; uid = g_strndup (s0, s1 - s0); source = e_source_registry_ref_source (registry, uid); if (source != NULL) { if (out_source != NULL) *out_source = g_object_ref (source); g_object_unref (source); success = TRUE; } g_free (uid); if (success && out_contacts != NULL) *out_contacts = eab_contact_list_from_string (str); return success; }
/** * select_source_dialog * * Implements dialog for allowing user to select a destination source. */ ESource * select_source_dialog (GtkWindow *parent, ESourceRegistry *registry, ECalClientSourceType obj_type, ESource *except_source) { GtkWidget *dialog; ESource *selected_source = NULL; const gchar *extension_name; const gchar *icon_name; g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL); if (obj_type == E_CAL_CLIENT_SOURCE_TYPE_EVENTS) { extension_name = E_SOURCE_EXTENSION_CALENDAR; icon_name = "x-office-calendar"; } else if (obj_type == E_CAL_CLIENT_SOURCE_TYPE_TASKS) { extension_name = E_SOURCE_EXTENSION_TASK_LIST; icon_name = "stock_todo"; } else if (obj_type == E_CAL_CLIENT_SOURCE_TYPE_MEMOS) { extension_name = E_SOURCE_EXTENSION_MEMO_LIST; icon_name = "stock_journal"; } else return NULL; /* create the dialog */ dialog = e_source_selector_dialog_new (parent, registry, extension_name); if (icon_name) gtk_window_set_icon_name (GTK_WINDOW (dialog), icon_name); if (except_source) g_object_set_data (G_OBJECT (dialog), "except-source", except_source); if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK) goto exit; selected_source = e_source_selector_dialog_peek_primary_selection ( E_SOURCE_SELECTOR_DIALOG (dialog)); if (selected_source != NULL) g_object_ref (selected_source); exit: gtk_widget_destroy (dialog); return selected_source; }
ESource * em_utils_guess_mail_identity_with_recipients_and_sort (ESourceRegistry *registry, CamelMimeMessage *message, CamelFolder *folder, const gchar *message_uid, EMailUtilsSourtSourcesFunc sort_func, gpointer sort_func_data) { ESource *source; ESourceExtension *extension; const gchar *extension_name; const gchar *uid; g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL); g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), NULL); source = em_utils_guess_mail_account_with_recipients_and_sort ( registry, message, folder, message_uid, sort_func, sort_func_data); if (source == NULL) return NULL; extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT; extension = e_source_get_extension (source, extension_name); uid = e_source_mail_account_get_identity_uid ( E_SOURCE_MAIL_ACCOUNT (extension)); if (uid == NULL) return NULL; source = e_source_registry_ref_source (registry, uid); if (source == NULL) return NULL; extension_name = E_SOURCE_EXTENSION_MAIL_IDENTITY; if (!e_source_has_extension (source, extension_name)) { g_object_unref (source); return NULL; } return source; }
ESource * em_utils_guess_mail_identity (ESourceRegistry *registry, CamelMimeMessage *message, CamelFolder *folder, const gchar *message_uid) { ESource *source; ESourceExtension *extension; const gchar *extension_name; const gchar *uid; g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL); g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), NULL); if (folder != NULL) g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL); source = em_utils_guess_mail_account (registry, message, folder, message_uid); if (source == NULL) return NULL; extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT; extension = e_source_get_extension (source, extension_name); uid = e_source_mail_account_get_identity_uid ( E_SOURCE_MAIL_ACCOUNT (extension)); if (uid == NULL) return NULL; source = e_source_registry_ref_source (registry, uid); if (source == NULL) return NULL; extension_name = E_SOURCE_EXTENSION_MAIL_IDENTITY; if (!e_source_has_extension (source, extension_name)) { g_object_unref (source); return NULL; } return source; }
/** * e_cal_backend_user_declined: * @registry: an #ESourceRegistry * @icalcomp: component where to check * * Returns: Whether icalcomp contains attendee with a mail same as any of * configured enabled mail account and whether this user declined. * * Since: 2.26 **/ gboolean e_cal_backend_user_declined (ESourceRegistry *registry, icalcomponent *icalcomp) { GList *list, *iter; const gchar *extension_name; gboolean declined = FALSE; g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE); g_return_val_if_fail (icalcomp != NULL, FALSE); extension_name = E_SOURCE_EXTENSION_MAIL_IDENTITY; list = e_source_registry_list_enabled (registry, extension_name); for (iter = list; iter != NULL; iter = g_list_next (iter)) { ESource *source = E_SOURCE (iter->data); ESourceMailIdentity *extension; const gchar *address; extension = e_source_get_extension (source, extension_name); address = e_source_mail_identity_get_address (extension); if (address == NULL) continue; if (is_attendee_declined (icalcomp, address)) { declined = TRUE; break; } } g_list_free_full (list, (GDestroyNotify) g_object_unref); return declined; }
ESource * em_utils_guess_mail_account_with_recipients_and_sort (ESourceRegistry *registry, CamelMimeMessage *message, CamelFolder *folder, const gchar *message_uid, EMailUtilsSourtSourcesFunc sort_func, gpointer sort_func_data) { ESource *source = NULL; GHashTable *recipients; CamelInternetAddress *addr; GList *list, *iter; const gchar *extension_name; const gchar *type; const gchar *key; /* This policy is subject to debate and tweaking, * but please also document the rational here. */ g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL); g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), NULL); /* Build a set of email addresses in which to test for membership. * Only the keys matter here; the values just need to be non-NULL. */ recipients = g_hash_table_new (g_str_hash, g_str_equal); type = CAMEL_RECIPIENT_TYPE_TO; addr = camel_mime_message_get_recipients (message, type); if (addr != NULL) { gint index = 0; while (camel_internet_address_get (addr, index++, NULL, &key)) g_hash_table_add (recipients, (gpointer) key); } type = CAMEL_RECIPIENT_TYPE_CC; addr = camel_mime_message_get_recipients (message, type); if (addr != NULL) { gint index = 0; while (camel_internet_address_get (addr, index++, NULL, &key)) g_hash_table_add (recipients, (gpointer) key); } /* First Preference: We were given a folder that maps to an * enabled mail account, and that account's address appears * in the list of To: or Cc: recipients. */ if (folder != NULL) source = guess_mail_account_from_folder ( registry, folder, message_uid); if (source == NULL) goto second_preference; if (mail_account_in_recipients (registry, source, recipients)) goto exit; second_preference: /* Second Preference: Choose any enabled mail account whose * address appears in the list to To: or Cc: recipients. */ if (source != NULL) { g_object_unref (source); source = NULL; } extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT; list = e_source_registry_list_sources (registry, extension_name); if (sort_func) sort_func (&list, sort_func_data); for (iter = list; iter != NULL; iter = g_list_next (iter)) { ESource *temp = E_SOURCE (iter->data); if (e_source_registry_check_enabled (registry, temp) && mail_account_in_recipients (registry, temp, recipients)) { source = g_object_ref (temp); break; } } g_list_free_full (list, (GDestroyNotify) g_object_unref); if (source != NULL) goto exit; /* Last Preference: Defer to em_utils_guess_mail_account(). */ source = em_utils_guess_mail_account ( registry, message, folder, message_uid); exit: g_hash_table_destroy (recipients); return source; }
/** * e_cal_backend_mail_account_is_valid: * @registry: an #ESourceRegistry * @user: user name for the account to check * @name: placeholder for the account name * * Checks that a mail account is valid, and returns its name. * * Returns: TRUE if the account is valid, FALSE if not. */ gboolean e_cal_backend_mail_account_is_valid (ESourceRegistry *registry, gchar *user, gchar **name) { GList *list, *iter; const gchar *extension_name; gboolean valid = FALSE; g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE); g_return_val_if_fail (user != NULL, FALSE); extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT; list = e_source_registry_list_enabled (registry, extension_name); for (iter = list; iter != NULL; iter = g_list_next (iter)) { ESource *source = E_SOURCE (iter->data); ESourceMailAccount *mail_account; ESourceMailIdentity *mail_identity; const gchar *uid; gboolean match = FALSE; gchar *address; extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT; mail_account = e_source_get_extension (source, extension_name); uid = e_source_mail_account_get_identity_uid (mail_account); if (uid == NULL) continue; source = e_source_registry_ref_source (registry, uid); if (source == NULL) continue; extension_name = E_SOURCE_EXTENSION_MAIL_IDENTITY; if (!e_source_has_extension (source, extension_name)) { g_object_unref (source); continue; } mail_identity = e_source_get_extension (source, extension_name); address = e_source_mail_identity_dup_address (mail_identity); if (address != NULL) { match = (g_ascii_strcasecmp (address, user) == 0); g_free (address); } if (match && name != NULL) *name = e_source_dup_display_name (source); g_object_unref (source); if (match) { valid = TRUE; break; } } g_list_free_full (list, (GDestroyNotify) g_object_unref); return valid; }