コード例 #1
0
static void
write_recipients (ESoapMessage *msg,
		  const gchar *elem_name,
		  GHashTable *recips)
{
	GHashTableIter iter;
	gpointer key, value;

	g_return_if_fail (msg != NULL);
	g_return_if_fail (elem_name != NULL);
	g_return_if_fail (recips != NULL);

	if (!g_hash_table_size (recips))
		return;

	e_soap_message_start_element (msg, elem_name, NULL, NULL);

	g_hash_table_iter_init (&iter, recips);
	while (g_hash_table_iter_next (&iter, &key, &value)) {
		e_soap_message_start_element (msg, "Mailbox", NULL, NULL);
		e_ews_message_write_string_parameter_with_attribute (msg, "EmailAddress", NULL, key, NULL, NULL);
		e_soap_message_end_element (msg); /* Mailbox */
	}

	e_soap_message_end_element (msg); /* elem_name */
}
コード例 #2
0
ファイル: e-ews-message.c プロジェクト: tivv/evolution-ews
ESoapMessage *
e_ews_message_new_with_header (const gchar *uri,
                               const gchar *method_name,
                               const gchar *attribute_name,
                               const gchar *attribute_value,
                               EwsServerVersion server_info)
{
	ESoapMessage *msg;
	const gchar *server_ver;

	msg = e_soap_message_new (SOUP_METHOD_POST, uri, FALSE, NULL, NULL, NULL);
	if (!msg) {
		g_warning (G_STRLOC ": Could not build SOAP message");
		return NULL;
	}

	soup_message_headers_append (SOUP_MESSAGE (msg)->request_headers, "Content-Type", "text/xml; charset=utf-8");
	soup_message_headers_append (SOUP_MESSAGE (msg)->request_headers, "User-Agent",
				     "Evolution/" VERSION);
	soup_message_headers_append (SOUP_MESSAGE (msg)->request_headers,"Connection",  "Keep-Alive");

	e_soap_message_start_envelope (msg);

	/* server info */
	if (server_info == EWS_EXCHANGE_2007_SP1)
		server_ver = "Exchange2007_SP1";
	else
		server_ver = "Exchange2007";

	e_soap_message_start_header (msg);

	e_soap_message_start_element (msg, "RequestServerVersion", "types",
					"http://schemas.microsoft.com/exchange/services/2006/types");
	e_soap_message_add_attribute (msg, "Version", server_ver, NULL, NULL);
	e_soap_message_end_element (msg);

	e_soap_message_end_header (msg);

	e_soap_message_start_body (msg);
	e_soap_message_add_namespace(msg, "messages",
				       "http://schemas.microsoft.com/exchange/services/2006/messages");
	e_soap_message_start_element(msg, method_name, "messages", NULL);
	e_soap_message_set_default_namespace (msg,
						"http://schemas.microsoft.com/exchange/services/2006/types");
	if (attribute_name)
		e_soap_message_add_attribute (msg, attribute_name, attribute_value, NULL, NULL);
	return msg;
}
コード例 #3
0
ファイル: e-ews-message.c プロジェクト: tivv/evolution-ews
void
e_ews_message_write_string_parameter (ESoapMessage *msg,
                                      const gchar *name,
                                      const gchar *prefix,
                                      const gchar *value)
{
	e_soap_message_start_element (msg, name, prefix, NULL);
	e_soap_message_write_string (msg, value);
	e_soap_message_end_element (msg);
}
コード例 #4
0
static ESExpResult *
e_ews_func_and_or_not (ESExp *f,
                       gint argc,
                       ESExpTerm **argv,
                       gpointer data,
                       match_type type)
{
	ESExpResult *r, *r1;
	ESoapMessage *msg;
	gint i;

	msg = (ESoapMessage *) data;

	/* "and" and "or" expects atleast two arguments */

	if (argc == 0)
		goto result;

	if (type == MATCH_AND) {
		if (argc >= 2)
			e_soap_message_start_element (msg, "And", NULL, NULL);

	} else if (type == MATCH_OR) {
		if (argc >= 2)
			e_soap_message_start_element (msg, "Or", NULL, NULL);

	} else if (type == MATCH_NOT)
		e_soap_message_start_element (msg, "Not", NULL, NULL);

	for (i = 0; i < argc; i++) {
		r1 = e_sexp_term_eval (f, argv[i]);
		e_sexp_result_free (f, r1);
	}

	if (argc >= 2 || type == MATCH_NOT)
		e_soap_message_end_element (msg);

result:
	r = e_sexp_result_new (f, ESEXP_RES_UNDEFINED);

	return r;
}
コード例 #5
0
ファイル: e-ews-message.c プロジェクト: tivv/evolution-ews
void
e_ews_message_write_string_parameter_with_attribute (ESoapMessage *msg,
                                                     const gchar *name,
                                                     const gchar *prefix,
                                                     const gchar *value,
                                                     const gchar *attribute_name,
                                                     const gchar *attribute_value)
{
	e_soap_message_start_element (msg, name, prefix, NULL);
	e_soap_message_add_attribute (msg, attribute_name, attribute_value, NULL, NULL);
	e_soap_message_write_string (msg, value);
	e_soap_message_end_element (msg);
}
コード例 #6
0
void
e_ews_query_to_restriction (ESoapMessage *msg,
                            const gchar *query,
                            EEwsFolderType type)
{
	gboolean is_query;

	is_query = e_ews_check_is_query (query, type);

	if (is_query) {
		e_soap_message_start_element (msg, "Restriction", "messages", NULL);
		e_ews_convert_sexp_to_restriction (msg, query, type);
		e_soap_message_end_element (msg);
	}
	return;
}
コード例 #7
0
ファイル: e-soap-message.c プロジェクト: tivv/evolution-ews
/**
 * e_soap_message_start_header_element:
 * @msg: the #ESoapMessage.
 * @name: name of the header element
 * @must_understand: whether the recipient must understand the header in order
 * to proceed with processing the message
 * @actor_uri: the URI which represents the destination actor for this header.
 * @prefix: the namespace prefix
 * @ns_uri: the namespace URI
 *
 * Starts a new SOAP arbitrary header element.
 *
 * Since: 2.92
 */
void
e_soap_message_start_header_element (ESoapMessage *msg,
                                     const gchar *name,
                                     gboolean must_understand,
                                     const gchar *actor_uri,
                                     const gchar *prefix,
                                     const gchar *ns_uri)
{
	ESoapMessagePrivate *priv;

	g_return_if_fail (E_IS_SOAP_MESSAGE (msg));
	priv = E_SOAP_MESSAGE_GET_PRIVATE (msg);

	e_soap_message_start_element (msg, name, prefix, ns_uri);
	if (actor_uri)
		xmlNewNsProp (priv->last_node, priv->soap_ns, (const xmlChar *)"actorUri", (const xmlChar *)actor_uri);
	if (must_understand)
		xmlNewNsProp (priv->last_node, priv->soap_ns, (const xmlChar *)"mustUnderstand", (const xmlChar *)"1");
}
コード例 #8
0
static ESExpResult *
calendar_func_occur_in_time_range (ESExp *f,
                                   gint argc,
                                   ESExpResult **argv,
                                   gpointer data)
{
	ESExpResult *r;
	ESoapMessage *msg;
	gchar *start, *end;

	msg = (ESoapMessage *) data;

	if (argv[0]->type != ESEXP_RES_TIME) {
		e_sexp_fatal_error (
			f, "occur-in-time-range? expects argument 1 "
			"to be a time_t");
		return NULL;
	}

	if (argv[1]->type != ESEXP_RES_TIME) {
		e_sexp_fatal_error (
			f, "occur-in-time-range? expects argument 2 "
			"to be a time_t");
		return NULL;
	}

	start = e_ews_make_timestamp (argv[0]->value.time);
	end = e_ews_make_timestamp (argv[1]->value.time);

	e_soap_message_start_element (msg, "And", NULL, NULL);
	WRITE_GREATER_THAN_OR_EQUAL_TO_MESSAGE (msg, "calendar:Start", start);
	WRITE_LESS_THAN_OR_EQUAL_TO_MESSAGE (msg, "calendar:End", end);
	e_soap_message_end_element (msg);

	r = e_sexp_result_new (f, ESEXP_RES_UNDEFINED);

	g_free (start);
	g_free (end);

	return r;
}
コード例 #9
0
static void
create_mime_message_cb (ESoapMessage *msg,
                        gpointer user_data)
{
	struct _create_mime_msg_data *create_data = user_data;
	CamelStream *mem, *filtered;
	CamelMimeFilter *filter;
	CamelContentType *content_type;
	GByteArray *bytes;
	gchar *base64;
	gint msgflag;
	guint32 message_camel_flags = 0;

	if (create_data->info)
		message_camel_flags = camel_message_info_flags (create_data->info);
		
	e_soap_message_start_element (msg, "Message", NULL, NULL);
	e_soap_message_start_element (msg, "MimeContent", NULL, NULL);

	/* This is horrid. We really need to extend ESoapMessage to allow us
	 * to stream this directly rather than storing it in RAM. Which right
	 * now we are doing about four times: the GByteArray in the mem stream,
	 * then the base64 version, then the xmlDoc, then the soup request. */
	camel_mime_message_set_best_encoding (
		create_data->message,
		CAMEL_BESTENC_GET_ENCODING,
		CAMEL_BESTENC_8BIT);

	mem = camel_stream_mem_new ();
	filtered = camel_stream_filter_new (mem);

	filter = camel_mime_filter_crlf_new (
		CAMEL_MIME_FILTER_CRLF_ENCODE,
		CAMEL_MIME_FILTER_CRLF_MODE_CRLF_ONLY);
	camel_stream_filter_add (CAMEL_STREAM_FILTER (filtered), filter);
	g_object_unref (filter);

	camel_data_wrapper_write_to_stream_sync (
		CAMEL_DATA_WRAPPER (create_data->message),
		filtered, NULL, NULL);
	camel_stream_flush (filtered, NULL, NULL);
	camel_stream_flush (mem, NULL, NULL);
	bytes = camel_stream_mem_get_byte_array (CAMEL_STREAM_MEM (mem));

	base64 = g_base64_encode (bytes->data, bytes->len);
	g_object_unref (mem);
	g_object_unref (filtered);

	e_soap_message_write_string (msg, base64);
	g_free (base64);

	e_soap_message_end_element (msg); /* MimeContent */

	content_type = camel_mime_part_get_content_type (CAMEL_MIME_PART (create_data->message));
	if (content_type && camel_content_type_is (content_type, "multipart", "report") &&
	    camel_content_type_param (content_type, "report-type") &&
	    g_ascii_strcasecmp (camel_content_type_param (content_type, "report-type"), "disposition-notification") == 0) {
		/* it's a disposition notification reply, set ItemClass too */
		e_soap_message_start_element (msg, "ItemClass", NULL, NULL);
		e_soap_message_write_string (msg, "REPORT.IPM.NOTE.IPNRN");
		e_soap_message_end_element (msg); /* ItemClass */
	}

	e_ews_message_write_string_parameter_with_attribute (
			msg,
			"Importance",
			NULL,
			(message_camel_flags & CAMEL_MESSAGE_FLAGGED) != 0 ? "High" : "Normal",
			NULL,
			NULL);

	/* more MAPI crap.  You can't just set the IsDraft property
	 * here you have to use the MAPI MSGFLAG_UNSENT extended
	 * property Further crap is that Exchange 2007 assumes when it
	 * sees this property that you're setting the value to 0
	 * ... it never checks */
	msgflag = MAPI_MSGFLAG_READ; /* draft or sent is always read */
	if ((message_camel_flags & CAMEL_MESSAGE_DRAFT) != 0)
		msgflag |= MAPI_MSGFLAG_UNSENT;

	e_ews_message_add_extended_property_tag_int (msg, 0x0e07, msgflag);

	if ((message_camel_flags & (CAMEL_MESSAGE_FORWARDED | CAMEL_MESSAGE_ANSWERED)) != 0) {
		gint icon;

		icon = (message_camel_flags & CAMEL_MESSAGE_ANSWERED) != 0 ? 0x105 : 0x106;

		e_ews_message_add_extended_property_tag_int (msg, 0x1080, icon);
	}

	if (create_data->info) {
		const gchar *followup, *completed, *dueby;
		time_t completed_tt = (time_t) 0 , dueby_tt = (time_t) 0;

		/* follow-up flags */
		followup = camel_message_info_user_tag (create_data->info, "follow-up");
		completed = camel_message_info_user_tag (create_data->info, "completed-on");
		dueby = camel_message_info_user_tag (create_data->info, "due-by");

		if (followup && !*followup)
			followup = NULL;

		if (completed && *completed)
			completed_tt = camel_header_decode_date (completed, NULL);

		if (dueby && *dueby)
			dueby_tt = camel_header_decode_date (dueby, NULL);

		/* PidTagFlagStatus */
		e_ews_message_add_extended_property_tag_int (msg, 0x1090,
			followup ? (completed_tt != (time_t) 0 ? 0x01 /* followupComplete */: 0x02 /* followupFlagged */) : 0x0);

		if (followup) {
			/* PidLidFlagRequest */
			e_ews_message_add_extended_property_distinguished_tag_string (msg, "Common", 0x8530, followup);

			/* PidTagToDoItemFlags */
			e_ews_message_add_extended_property_tag_int (msg, 0x0e2b, 1);
		}

		if (followup && completed_tt != (time_t) 0) {
			/* minute precision */
			completed_tt = completed_tt - (completed_tt % 60);

			/* PidTagFlagCompleteTime */
			e_ews_message_add_extended_property_tag_time (msg, 0x1091, completed_tt);

			/* PidLidTaskDateCompleted */
			e_ews_message_add_extended_property_distinguished_tag_time (msg, "Task", 0x810f, completed_tt);

			/* PidLidTaskStatus */
			e_ews_message_add_extended_property_distinguished_tag_int (msg, "Task", 0x8101, 2);

			/* PidLidPercentComplete */
			e_ews_message_add_extended_property_distinguished_tag_double (msg, "Task", 0x8102, 1.0);

			/* PidLidTaskComplete */
			e_ews_message_add_extended_property_distinguished_tag_boolean (msg, "Task", 0x811c, TRUE);
		}

		if (followup && dueby_tt != (time_t) 0 && completed_tt == (time_t) 0) {
			/* PidLidTaskStatus */
			e_ews_message_add_extended_property_distinguished_tag_int (msg, "Task", 0x8101, 0);

			/* PidLidPercentComplete */
			e_ews_message_add_extended_property_distinguished_tag_double (msg, "Task", 0x8102, 0.0);

			/* PidLidTaskDueDate */
			e_ews_message_add_extended_property_distinguished_tag_time (msg, "Task", 0x8105, dueby_tt);

			/* PidLidTaskComplete */
			e_ews_message_add_extended_property_distinguished_tag_boolean (msg, "Task", 0x811c, FALSE);
		}
	}

	if (create_data->recipients) {
		GHashTable *recip_to, *recip_cc, *recip_bcc;

		recip_to = g_hash_table_new (camel_strcase_hash, camel_strcase_equal);
		recip_cc = g_hash_table_new (camel_strcase_hash, camel_strcase_equal);
		recip_bcc = g_hash_table_new (camel_strcase_hash, camel_strcase_equal);
	
		filter_recipients (create_data->message, create_data->recipients, recip_to, recip_cc, recip_bcc);

		write_recipients (msg, "ToRecipients", recip_to);
		write_recipients (msg, "CcRecipients", recip_cc);
		write_recipients (msg, "BccRecipients", recip_bcc);

		g_hash_table_destroy (recip_to);
		g_hash_table_destroy (recip_cc);
		g_hash_table_destroy (recip_bcc);
	}

	e_ews_message_write_string_parameter_with_attribute (
			msg,
			"IsRead",
			NULL,
			(message_camel_flags & CAMEL_MESSAGE_SEEN) != 0 ? "true" : "false",
			NULL,
			NULL);

	e_soap_message_end_element (msg); /* Message */

	g_free (create_data);
}
コード例 #10
0
static ESExpResult *
calendar_func_contains (ESExp *f,
                        gint argc,
                        ESExpResult **argv,
                        gpointer data)
{
	ESExpResult *r;
	ESoapMessage *msg;

	msg = (ESoapMessage *) data;

	if (argc > 1 && argv[0]->type == ESEXP_RES_STRING) {
		const gchar *field;
		field = argv[0]->value.string;

		if (argv[1]->type == ESEXP_RES_STRING && argv[1]->value.string[0] != 0) {
			if (!g_strcmp0 (field, "summary")) {
				const gchar *value;
				value = argv[1]->value.string;

				WRITE_CONTAINS_MESSAGE (msg, "Substring", "IgnoreCase", "item:Subject", value);
			} else if (!g_strcmp0 (field, "description")) {
				const gchar *value;
				value = argv[1]->value.string;

				WRITE_CONTAINS_MESSAGE (msg, "Substring", "IgnoreCase", "item:Body", value);
			} else if (!g_strcmp0 (field, "location")) {
				const gchar *value;
				value = argv[1]->value.string;

				WRITE_CONTAINS_MESSAGE (msg, "Substring", "IgnoreCase", "calendar:Location", value);
			} else if (!g_strcmp0 (field, "attendee")) {
				const gchar *value;
				value = argv[1]->value.string;

				e_soap_message_start_element (msg, "Or", NULL, NULL);
				WRITE_CONTAINS_MESSAGE (msg, "Substring", "IgnoreCase", "calendar:RequiredAttendees", value);
				WRITE_CONTAINS_MESSAGE (msg, "Substring", "IgnoreCase", "calendar:OptionalAttendees", value);
				e_soap_message_end_element (msg);
			} else if (!g_strcmp0 (field, "organizer")) {
				const gchar *value;
				value = argv[1]->value.string;

				WRITE_CONTAINS_MESSAGE (msg, "Substring", "IgnoreCase", "calendar:Organizer", value);
			} else if (!g_strcmp0 (field, "classification")) {
				const gchar *value;
				value = argv[1]->value.string;

				WRITE_CONTAINS_MESSAGE (msg, "Substring", "IgnoreCase", "item:Sensitivity", value);
			} else if (!g_strcmp0 (field, "priority")) {
				const gchar *value;
				value = argv[1]->value.string;

				WRITE_CONTAINS_MESSAGE (msg, "Substring", "IgnoreCase", "item:Importance", value);
			} else if (!g_strcmp0 (field, "any")) {
				const gchar *value;
				gint n = 0;
				value = argv[1]->value.string;

				e_soap_message_start_element (msg, "Or", NULL, NULL);
				while (n < G_N_ELEMENTS (calendar_field)) {
					if (calendar_field[n].any_field) {
						WRITE_CONTAINS_MESSAGE (msg, "Substring", "IgnoreCase", calendar_field[n].field_uri, value);
					}
					n++;
				}
				n = 0;
				while (n < G_N_ELEMENTS (item_field)) {
					if (item_field[n].any_field) {
						WRITE_CONTAINS_MESSAGE (msg, "Substring", "IgnoreCase", item_field[n].field_uri, value);
					}
					n++;
				}
				e_soap_message_end_element (msg);
			}
		}
	}

	r = e_sexp_result_new (f, ESEXP_RES_UNDEFINED);

	return r;
}
コード例 #11
0
static ESExpResult *
e_ews_implement_contact_contains (ESExp *f,
                                  gint argc,
                                  ESExpResult **argv,
                                  gpointer data,
                                  match_type type)
{
	ESExpResult *r;
	ESoapMessage *msg;

	msg = (ESoapMessage *) data;

	if (argc > 1 && argv[0]->type == ESEXP_RES_STRING) {
		const gchar *field;
		field = argv[0]->value.string;

		if (argv[1]->type == ESEXP_RES_STRING && argv[1]->value.string != NULL) {
			gchar *mode = NULL;

			if (type == MATCH_CONTAINS || type == MATCH_ENDS_WITH)
				mode = g_strdup ("Substring");
			else if (type == MATCH_BEGINS_WITH)
				mode = g_strdup ("Prefixed");
			else if (type == MATCH_IS)
				mode = g_strdup ("FullString");
			else
				mode = g_strdup ("Substring");

			if (!strcmp (field, "full_name")) {
				gint n = 0;
				const gchar *value;
				value = argv[1]->value.string;

				e_soap_message_start_element (msg, "Or", NULL, NULL);
				while (n < G_N_ELEMENTS (contact_field)) {
					if ((contact_field[n].flag == CONTACT_NAME) && (!contact_field[n].indexed)) {
						WRITE_CONTAINS_MESSAGE (msg, mode, "IgnoreCase", contact_field[n].field_uri, value);
					}
					n++;
				}
				e_soap_message_end_element (msg);

			} else if (!strcmp (field, "x-evolution-any-field")) {
				gint n = 0;
				const gchar *value;
				value = argv[1]->value.string;

				e_soap_message_start_element (msg, "Or", NULL, NULL);
				while (n < G_N_ELEMENTS (contact_field)) {
					if (!contact_field[n].indexed) {
						WRITE_CONTAINS_MESSAGE (msg, "Substring", "IgnoreCase", contact_field[n].field_uri, value);
					} else if (contact_field[n].flag == CONTACT_EMAIL && contact_field[n].indexed) {
						gint i = 0;
						while (i < G_N_ELEMENTS (email_index)) {
							WRITE_CONTAINS_MESSAGE_INDEXED (msg, "Substring", "IgnoreCase", "contacts:EmailAddress", email_index[i].field_index, value);
							i++;
						}
					}
					n++;
				}
				e_soap_message_end_element (msg);
			} else if (!strcmp (field, "email")) {
				const gchar *value;
				gint n = 0;
				value = argv[1]->value.string;

				e_soap_message_start_element (msg, "Or", NULL, NULL);
				while (n < G_N_ELEMENTS (email_index)) {
					WRITE_CONTAINS_MESSAGE_INDEXED (msg, mode, "IgnoreCase", "contacts:EmailAddress", email_index[n].field_index, value);
					n++;
				}
				e_soap_message_end_element (msg);
			} else if (!strcmp (field, "category_list")) {
				const gchar *value;
				value = argv[1]->value.string;

				WRITE_CONTAINS_MESSAGE (msg, mode, "IgnoreCase", "item:Categories", value);
			}

			g_free (mode);
		}
	}

	r = e_sexp_result_new (f, ESEXP_RES_UNDEFINED);

	return r;
}