コード例 #1
0
ファイル: mail-autofilter.c プロジェクト: jdapena/evolution
EFilterRule *
em_vfolder_rule_from_address (EMVFolderContext *context,
                              CamelInternetAddress *addr,
                              gint flags,
                              CamelFolder *folder)
{
	EFilterRule *rule;
	EMailBackend *backend;
	gchar *uri;

	g_return_val_if_fail (EM_IS_VFOLDER_CONTEXT (context), NULL);
	g_return_val_if_fail (CAMEL_IS_INTERNET_ADDRESS (addr), NULL);
	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL);

	uri = e_mail_folder_uri_from_folder (folder);

	backend = em_vfolder_context_get_backend (context);

	rule = em_vfolder_rule_new (backend);
	em_vfolder_rule_add_source (EM_VFOLDER_RULE (rule), uri);
	rule_from_address (rule, E_RULE_CONTEXT (context), addr, flags);

	g_free (uri);

	return rule;
}
コード例 #2
0
/* Expands groups to individual addresses, or removes empty groups completely.
 * Usual email addresses are left untouched.
*/
void
em_utils_expand_groups (CamelInternetAddress *addresses)
{
	gint ii, len;
	const gchar *addr;
	CamelAddress *addrs;

	g_return_if_fail (CAMEL_IS_INTERNET_ADDRESS (addresses));

	addrs = CAMEL_ADDRESS (addresses);
	len = camel_address_length (addrs);
	for (ii = len - 1; ii >= 0; ii--) {
		addr = NULL;

		if (!camel_internet_address_get (addresses, ii, NULL, &addr)) {
			camel_address_remove (addrs, ii);
		} else if (addr) {
			gchar *encoded = camel_internet_address_encode_address (NULL, NULL, addr);

			if (encoded) {
				CamelInternetAddress *iaddr = camel_internet_address_new ();
				gint decoded;

				/* decode expands respective groups */
				decoded = camel_address_decode (CAMEL_ADDRESS (iaddr), encoded);
				if (decoded <= 0 || decoded > 1) {
					camel_address_remove (addrs, ii);

					if (decoded > 1)
						camel_address_cat (addrs, CAMEL_ADDRESS (iaddr));
				}

				g_object_unref (iaddr);
				g_free (encoded);
			}
		}
	}
}
コード例 #3
0
static void
filter_recipients (CamelMimeMessage *message,
		   CamelAddress *recipients,
		   GHashTable *recip_to,
		   GHashTable *recip_cc,
		   GHashTable *recip_bcc)
{
	CamelInternetAddress *addresses, *mime_cc, *mime_bcc;
	gint ii, len;

	g_return_if_fail (message != NULL);
	g_return_if_fail (recipients != NULL);
	g_return_if_fail (CAMEL_IS_INTERNET_ADDRESS (recipients));
	g_return_if_fail (recip_to != NULL);
	g_return_if_fail (recip_cc != NULL);
	g_return_if_fail (recip_bcc != NULL);

	mime_cc = camel_mime_message_get_recipients (message, CAMEL_RECIPIENT_TYPE_CC);
	mime_bcc = camel_mime_message_get_recipients (message, CAMEL_RECIPIENT_TYPE_BCC);

	addresses = CAMEL_INTERNET_ADDRESS (recipients);
	len = camel_address_length (recipients);
	for (ii = 0; ii < len; ii++) {
		const gchar *name = NULL, *email = NULL;

		if (!camel_internet_address_get (addresses, ii, &name, &email) ||
		    !email)
			continue;

		if (mime_bcc && camel_internet_address_find_address (mime_bcc, email, NULL) != -1) {
			g_hash_table_insert (recip_bcc, (gpointer) email, GINT_TO_POINTER (1));
		} else if (mime_cc && camel_internet_address_find_address (mime_cc, email, NULL) != -1) {
			g_hash_table_insert (recip_cc, (gpointer) email, GINT_TO_POINTER (1));
		} else {
			g_hash_table_insert (recip_to, (gpointer) email, GINT_TO_POINTER (1));
		}
	}
}
コード例 #4
0
static gboolean
ews_send_to_sync (CamelTransport *transport,
                  CamelMimeMessage *message,
                  CamelAddress *from,
                  CamelAddress *recipients,
		  gboolean *out_sent_message_saved,
                  GCancellable *cancellable,
                  GError **error)
{
	CamelNetworkSettings *network_settings;
	CamelEwsSettings *ews_settings;
	CamelInternetAddress *used_from;
	CamelSettings *settings;
	CamelService *service;
	EEwsConnection *cnc;
	EwsFolderId *folder_id = NULL;
	gchar *ews_email;
	gchar *host_url;
	gchar *user;
	gboolean success = FALSE;

	service = CAMEL_SERVICE (transport);

	settings = camel_service_ref_settings (service);

	ews_settings = CAMEL_EWS_SETTINGS (settings);
	ews_email = camel_ews_settings_dup_email (ews_settings);
	host_url = camel_ews_settings_dup_hosturl (ews_settings);

	network_settings = CAMEL_NETWORK_SETTINGS (settings);
	user = camel_network_settings_dup_user (network_settings);

	g_object_unref (settings);

	if (CAMEL_IS_INTERNET_ADDRESS (from))
		used_from = CAMEL_INTERNET_ADDRESS (from);
	else
		used_from = camel_mime_message_get_from (message);

	if (!used_from || camel_address_length (CAMEL_ADDRESS (used_from)) == 0) {
		g_set_error_literal (
			error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
			_("Cannot send message with no From address"));
		goto exit;

	} else if (camel_address_length (CAMEL_ADDRESS (used_from)) > 1) {
		g_set_error_literal (
			error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
			_("Exchange server cannot send message with "
			"multiple From addresses"));
		goto exit;

	} else {
		const gchar *used_email = NULL;

		if (!camel_internet_address_get (used_from, 0, NULL, &used_email)) {
			g_set_error_literal (
				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
				_("Failed to read From address"));
			goto exit;
		}
	}

	cnc = ews_transport_ref_connection (CAMEL_EWS_TRANSPORT (service));
	if (!cnc) {
		g_set_error (
			error, CAMEL_SERVICE_ERROR,
			CAMEL_SERVICE_ERROR_NOT_CONNECTED,
			_("Service not connected"));
		goto exit;
	}

	if (ews_transport_can_server_side_sent_folder (service, &folder_id, cancellable)) {
		if (out_sent_message_saved)
			*out_sent_message_saved = TRUE;
	}

	success = camel_ews_utils_create_mime_message (
		cnc, folder_id ? "SendAndSaveCopy" : "SendOnly", folder_id, message, NULL,
		from, recipients, NULL, NULL, cancellable, error);

	g_object_unref (cnc);
	e_ews_folder_id_free (folder_id);

exit:
	g_free (ews_email);
	g_free (host_url);
	g_free (user);

	return success;
}