[evolution-ews/gnome-2-28] Bug #656375 Out of Office Implementation



commit 401be293d39bc60bca9da50cdcbdc7e0e48b061c
Author: Punit Jain <jpunit novell com>
Date:   Tue Mar 20 15:34:38 2012 +0530

    Bug #656375 Out of Office Implementation

 src/account-setup-eplugin/Makefile.am              |    4 +-
 .../exchange-ews-account-out-of-office.c           |  585 ++++++++++++++++++++
 .../exchange-ews-account-out-of-office.h           |   25 +
 .../exchange-ews-account-setup.c                   |   80 +++-
 .../org-gnome-exchange-ews.eplug.xml               |    4 +-
 src/server/e-ews-connection.c                      |  372 ++++++++++++-
 src/server/e-ews-connection.h                      |   42 ++
 src/server/tests/Makefile.am                       |    2 +
 src/server/tests/test-connection.c                 |    2 +
 src/server/tests/test-get-oof-settings.c           |  104 ++++
 src/server/tests/test-libews.c                     |    4 +
 src/server/tests/test-set-oof-settings.c           |  119 ++++
 12 files changed, 1329 insertions(+), 14 deletions(-)
---
diff --git a/src/account-setup-eplugin/Makefile.am b/src/account-setup-eplugin/Makefile.am
index 3926217..d8f51b6 100644
--- a/src/account-setup-eplugin/Makefile.am
+++ b/src/account-setup-eplugin/Makefile.am
@@ -31,7 +31,9 @@ liborg_gnome_exchange_ews_la_SOURCES = 		\
 	exchange-ews-account-setup.c		\
 	exchange-ews-account-setup.h		\
 	exchange-ews-account-listener.c		\
-	exchange-ews-account-listener.h
+	exchange-ews-account-listener.h		\
+	exchange-ews-account-out-of-office.c	\
+	exchange-ews-account-out-of-office.h
 
 liborg_gnome_exchange_ews_la_LIBADD = 			\
 	$(top_builddir)/src/server/libeews-1.2.la	\
diff --git a/src/account-setup-eplugin/exchange-ews-account-out-of-office.c b/src/account-setup-eplugin/exchange-ews-account-out-of-office.c
new file mode 100644
index 0000000..6134a0c
--- /dev/null
+++ b/src/account-setup-eplugin/exchange-ews-account-out-of-office.c
@@ -0,0 +1,585 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ * Authors : Punit Jain <jpunit suse com>
+ * 
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <unistd.h>
+#include <glib/gi18n-lib.h>
+
+#include <gtk/gtk.h>
+#include <camel/camel.h>
+#include <e-ews-connection.h>
+#include <misc/e-dateedit.h>
+#include <e-util/e-dialog-utils.h>
+#include <libedataserverui/e-passwords.h>
+#include <exchange-ews-account-out-of-office.h>
+
+#define d(x) x
+
+typedef enum {
+	EXTERNAL_AUDIENCE_NONE,
+	EXTERNAL_AUDIENCE_KNOWN,
+	EXTERNAL_AUDIENCE_ALL
+} ExternalAudience;
+
+typedef struct {
+	gboolean state;
+
+	/*duration for out of office*/
+	time_t from_time;
+	time_t to_time;
+	EDateEdit *from_date;
+	EDateEdit *to_date;
+
+	/*External Audience type*/
+	gchar *audience;
+	gint audience_type;
+	GtkWidget *aud_box;
+
+	/*Internal and External messages*/
+	gchar *external_message;
+	gchar *internal_message;
+	GtkWidget *external_view;
+	GtkWidget *internal_view;
+
+	/*Update box*/
+	GtkWidget *stat_box;
+} OOFData;
+
+static OOFData *oof_data = NULL;
+
+static void
+update_audience_type (void)
+{
+	if (!g_ascii_strcasecmp (oof_data->audience, "None"))
+		oof_data->audience_type = EXTERNAL_AUDIENCE_NONE;
+	else if (!g_ascii_strcasecmp (oof_data->audience, "Known"))
+		oof_data->audience_type = EXTERNAL_AUDIENCE_KNOWN;
+	else
+		oof_data->audience_type = EXTERNAL_AUDIENCE_ALL;
+}
+
+static void
+update_audience (void)
+{
+	g_free (oof_data->audience);
+	oof_data->audience = NULL;
+
+	if (oof_data->audience_type == EXTERNAL_AUDIENCE_NONE)
+		oof_data->audience = g_strdup ("None");
+	else if (oof_data->audience_type == EXTERNAL_AUDIENCE_KNOWN)
+		oof_data->audience = g_strdup ("Known");
+	else
+		oof_data->audience = g_strdup ("All");
+}
+
+static void
+update_audience_cb (GtkComboBox *combo,
+		    gpointer data)
+{
+	gint active;
+
+	active = gtk_combo_box_get_active (GTK_COMBO_BOX (combo));
+	if (active == oof_data->audience_type)
+		return;
+	else
+		oof_data->audience_type = active;
+
+	update_audience ();
+}
+
+static void
+update_int_msg_cb (GtkTextBuffer *buffer,
+			gpointer data)
+{
+	if (gtk_text_buffer_get_modified (buffer)) {
+		GtkTextIter start, end;
+		if (oof_data->internal_message)
+			g_free (oof_data->internal_message);
+		gtk_text_buffer_get_bounds (buffer, &start, &end);
+		oof_data->internal_message =  gtk_text_buffer_get_text (buffer, &start,
+							       &end, FALSE);
+		gtk_text_buffer_set_modified (buffer, FALSE);
+	}
+}
+
+static void
+update_ext_msg_cb (GtkTextBuffer *buffer,
+			gpointer data)
+{
+	if (gtk_text_buffer_get_modified (buffer)) {
+		GtkTextIter start, end;
+		if (oof_data->external_message)
+			g_free (oof_data->external_message);
+		gtk_text_buffer_get_bounds (buffer, &start, &end);
+		oof_data->external_message =  gtk_text_buffer_get_text (buffer, &start,
+							       &end, FALSE);
+		gtk_text_buffer_set_modified (buffer, FALSE);
+	}
+}
+
+static void
+toggled_state_cb (GtkToggleButton *button,
+               gpointer data)
+{
+	gboolean current_oof_state;
+
+	current_oof_state = gtk_toggle_button_get_active (button);
+	if (current_oof_state == oof_data->state)
+		return;
+	oof_data->state = current_oof_state;
+	gtk_widget_set_sensitive (oof_data->internal_view, current_oof_state);
+	gtk_widget_set_sensitive (oof_data->external_view, current_oof_state);
+	gtk_widget_set_sensitive ((GtkWidget *) oof_data->from_date, current_oof_state);
+	gtk_widget_set_sensitive ((GtkWidget *) oof_data->to_date, current_oof_state);
+	gtk_widget_set_sensitive (oof_data->aud_box, current_oof_state);
+
+}
+
+static void
+from_time_changed_cb (EDateEdit *date_tm, gpointer data)
+{
+	if (e_date_edit_date_is_valid (date_tm) && e_date_edit_time_is_valid (date_tm)) {
+		oof_data->from_time = e_date_edit_get_time (date_tm);
+	}
+}
+
+static void
+to_time_changed_cb (EDateEdit *date_tm, gpointer data)
+{
+	if (e_date_edit_date_is_valid (date_tm) && e_date_edit_time_is_valid (date_tm)) {
+		oof_data->to_time = e_date_edit_get_time (date_tm);
+	}
+	if (oof_data->from_time >= oof_data->to_time)
+		e_notice (NULL, GTK_MESSAGE_WARNING, _("Select a valid time range"));
+}
+
+static void
+oof_data_new (void)
+{
+	oof_data = g_new0 (OOFData, 1);
+	oof_data->state = FALSE;
+	oof_data->audience_type = EXTERNAL_AUDIENCE_ALL;
+	oof_data->audience = NULL;
+	oof_data->external_message = NULL;
+	oof_data->internal_message = NULL;
+	oof_data->internal_view = NULL;
+	oof_data->external_view = NULL;
+	oof_data->from_time = 0;
+	oof_data->to_time = 0;
+	oof_data->from_date = NULL;
+	oof_data->to_date = NULL;
+	oof_data->stat_box = NULL;
+}
+
+static void
+destroy_oof_data (void)
+{
+	if (oof_data->audience) {
+		g_free (oof_data->audience);
+		oof_data->audience = NULL;
+	}
+
+	if (oof_data->external_message) {
+		g_free (oof_data->external_message);
+		oof_data->external_message = NULL;
+	}
+
+	if (oof_data->internal_message) {
+		g_free (oof_data->internal_message);
+		oof_data->internal_message = NULL;
+	}
+
+	if (oof_data) {
+		g_free (oof_data);
+		oof_data = NULL;
+	}
+}
+
+static char *
+get_password (EMConfigTargetAccount *target)
+{
+	gchar *key, *password = NULL;
+	CamelURL *url = NULL;
+
+	url = camel_url_new (e_account_get_string (target->account, E_ACCOUNT_SOURCE_URL), NULL);
+
+	key = camel_url_to_string (url, CAMEL_URL_HIDE_PARAMS);
+	camel_url_free (url);
+
+	password = e_passwords_get_password ("Exchange Web Services", key);
+
+	g_free (key);
+	return password;
+}
+
+
+static EEwsConnection *
+get_connection (EMConfigTargetAccount *target)
+{
+	EEwsConnection *cnc;
+	gchar *password;
+	CamelURL *url = NULL;
+	GError *error = NULL;
+
+	url = camel_url_new (e_account_get_string(target->account, E_ACCOUNT_SOURCE_URL), NULL);
+
+	/* Create a new connection */
+	password = get_password (target);
+
+	cnc = e_ews_connection_new (camel_url_get_param (url, "hosturl"), url->user, password, NULL, NULL, &error);
+
+	if (!cnc) {
+		g_warning ("Error in connection: %s\n", error->message);
+		g_clear_error (&error);
+		return NULL;
+	}
+
+	e_ews_connection_set_mailbox (cnc, target->account->id->address);
+
+	g_free (password);
+	camel_url_free (url);
+
+	return cnc;
+}
+
+static void
+set_oof_error_to_frame (GtkWidget *oof_frame, GError *error)
+{
+	GtkHBox *error_box;
+	GtkLabel *error_msg;
+	GtkWidget *error_img;
+	gchar *message;
+
+	gtk_widget_destroy (oof_data->stat_box);
+
+	error_box = (GtkHBox*) g_object_new (GTK_TYPE_HBOX, NULL, "homogeneous", FALSE, "spacing", 6, NULL);
+	error_img = gtk_image_new_from_stock (GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_SMALL_TOOLBAR);
+	message = g_strdup_printf (_("Unable to fetch out of office settings: \n%s"), error->message);
+	error_msg = (GtkLabel*) gtk_label_new (message);
+	gtk_label_set_use_markup (error_msg, TRUE);
+	gtk_box_pack_start (GTK_BOX (error_box), GTK_WIDGET (error_img), FALSE, FALSE, 12);
+	gtk_box_pack_start (GTK_BOX (error_box), GTK_WIDGET (error_msg), FALSE, FALSE, 0);
+	gtk_container_add (GTK_CONTAINER (oof_frame), GTK_WIDGET (error_box));
+	gtk_widget_show_all (GTK_WIDGET (error_box));
+
+	g_free (message);
+}
+
+static void
+set_oof_settings_to_frame (GtkWidget *oof_frame)
+{
+
+	GtkVBox *vbox_oof;
+	GtkHBox *hbox_ext, *hbox_state;
+	GtkLabel *lbl_oof_desc, *from_label, *to_label;
+	GtkTable *tbl_oof_status;
+	GtkLabel *lbl_status, *lbl_external, *lbl_internal;
+	GtkRadioButton *radio_iof, *radio_oof;
+	GtkScrolledWindow *scrwnd_oof_int, *scrwnd_oof_ext;
+	GtkTextView *txtview_oof_int, *txtview_oof_ext;
+	GtkTextBuffer *buffer_int, *buffer_ext;
+	GtkWidget *from_date, *to_date, *aud_box;
+
+	gtk_widget_destroy (oof_data->stat_box);
+
+	vbox_oof = (GtkVBox*) g_object_new (GTK_TYPE_VBOX, NULL, "homogeneous", FALSE, "spacing", 12, NULL);
+	gtk_container_set_border_width (GTK_CONTAINER (vbox_oof), 6);
+	gtk_container_add (GTK_CONTAINER (oof_frame), GTK_WIDGET (vbox_oof));
+
+	lbl_oof_desc = (GtkLabel*) g_object_new (GTK_TYPE_LABEL, "label", _("The messages specified below will be automatically sent to \n each internal and external personal who sends a mail to you."), "justify", GTK_JUSTIFY_LEFT, NULL);
+	gtk_misc_set_alignment (GTK_MISC (lbl_oof_desc), 0, 0.5);
+	gtk_box_pack_start (GTK_BOX (vbox_oof), GTK_WIDGET (lbl_oof_desc), FALSE, FALSE, 0);
+
+	tbl_oof_status = (GtkTable*) g_object_new (GTK_TYPE_TABLE, "n-rows", 7, "n-columns", 2, "homogeneous", FALSE, "row-spacing", 6, "column-spacing", 6, NULL);
+	lbl_status = (GtkLabel*) g_object_new (GTK_TYPE_LABEL, "label", _("Status:"), "use-markup", TRUE, NULL);
+	gtk_misc_set_alignment (GTK_MISC (lbl_status), 0, 0.5);
+	gtk_misc_set_padding (GTK_MISC (lbl_status), 0, 0);
+
+	if (oof_data->state) {
+		radio_oof = (GtkRadioButton*) g_object_new (GTK_TYPE_RADIO_BUTTON, "label", _("I am _out of the office"), "use-underline", TRUE, NULL);
+		radio_iof = (GtkRadioButton*) g_object_new (GTK_TYPE_RADIO_BUTTON, "label", _("I am _in the office"), "use-underline", TRUE, "group", radio_oof, NULL);
+	}
+	else {
+		radio_iof = (GtkRadioButton*) g_object_new (GTK_TYPE_RADIO_BUTTON, "label", _("I am _in the office"), "use-underline", TRUE, NULL);
+		radio_oof = (GtkRadioButton*) g_object_new (GTK_TYPE_RADIO_BUTTON, "label", _("I am _out of the office"), "use-underline", TRUE, "group", radio_iof, NULL);
+	}
+	g_signal_connect (radio_oof, "toggled", G_CALLBACK (toggled_state_cb), NULL);
+
+	hbox_state = g_object_new (GTK_TYPE_HBOX, NULL, "homogeneous", FALSE, "spacing", 6, NULL);
+	gtk_box_pack_start (GTK_BOX (hbox_state), GTK_WIDGET (radio_iof), FALSE, FALSE, 12);
+	gtk_box_pack_start (GTK_BOX (hbox_state), GTK_WIDGET (radio_oof), FALSE, FALSE, 0);
+
+	/*Selectable Dates*/
+	from_date = e_date_edit_new ();
+	to_date = e_date_edit_new ();
+
+	e_date_edit_set_time ((EDateEdit *) from_date, oof_data->from_time);
+	e_date_edit_set_time ((EDateEdit *) to_date, oof_data->to_time);
+
+	oof_data->from_date = (EDateEdit *) from_date;
+	oof_data->to_date = (EDateEdit *) to_date;
+
+	g_signal_connect (from_date, "changed", G_CALLBACK (from_time_changed_cb), NULL);
+	g_signal_connect (to_date, "changed", G_CALLBACK (to_time_changed_cb), NULL);
+
+	from_label = (GtkLabel*) g_object_new (GTK_TYPE_LABEL, "label", _("_From:"), "use-underline", TRUE, "use-markup", TRUE, NULL);
+	gtk_label_set_mnemonic_widget (from_label, GTK_WIDGET (from_date));
+	gtk_misc_set_alignment (GTK_MISC (from_label), 0, 0.5);
+	gtk_misc_set_padding (GTK_MISC (from_label), 0, 0);
+
+	to_label = (GtkLabel*) g_object_new (GTK_TYPE_LABEL, "label", _("_To:"), "use-markup", TRUE, "use-underline", TRUE, NULL);
+	gtk_label_set_mnemonic_widget (to_label, GTK_WIDGET (to_date));
+	gtk_misc_set_alignment (GTK_MISC (to_label), 0, 0.5);
+	gtk_misc_set_padding (GTK_MISC (to_label), 0, 0);
+	
+	scrwnd_oof_int = (GtkScrolledWindow*) g_object_new (GTK_TYPE_SCROLLED_WINDOW, "hscrollbar-policy", GTK_POLICY_AUTOMATIC, "vscrollbar-policy", GTK_POLICY_AUTOMATIC, "shadow-type", GTK_SHADOW_IN, NULL);
+	txtview_oof_int = (GtkTextView*) g_object_new (GTK_TYPE_TEXT_VIEW, "justification", GTK_JUSTIFY_LEFT, "wrap-mode", GTK_WRAP_WORD, "editable", TRUE, NULL);
+
+	buffer_int = gtk_text_view_get_buffer (txtview_oof_int);
+	if (oof_data->internal_message) {
+		/* previuosly set message */
+		gtk_text_buffer_set_text (buffer_int, oof_data->internal_message, -1);
+		gtk_text_view_set_buffer (txtview_oof_int, buffer_int);
+	}
+	gtk_text_buffer_set_modified (buffer_int, FALSE);
+	gtk_container_add (GTK_CONTAINER (scrwnd_oof_int), GTK_WIDGET (txtview_oof_int));
+
+	lbl_internal = (GtkLabel*) g_object_new (GTK_TYPE_LABEL, "label", _("I_nternal:"), "use-underline", TRUE, "use-markup", TRUE, NULL);
+	gtk_label_set_mnemonic_widget (lbl_internal, GTK_WIDGET (txtview_oof_int));
+	gtk_widget_set_tooltip_text (GTK_WIDGET (lbl_internal), _("Message to be sent inside organization"));
+	gtk_misc_set_alignment (GTK_MISC (lbl_internal), 0, 0.5);
+	gtk_misc_set_padding (GTK_MISC (lbl_internal), 0, 0);
+
+
+	/*Select External Audience*/
+	hbox_ext = g_object_new (GTK_TYPE_HBOX, NULL, "homogeneous", FALSE, "spacing", 6, NULL);	
+	aud_box = gtk_combo_box_new_text ();
+	gtk_combo_box_insert_text (GTK_COMBO_BOX (aud_box), EXTERNAL_AUDIENCE_NONE, _("None"));
+	gtk_combo_box_insert_text (GTK_COMBO_BOX (aud_box), EXTERNAL_AUDIENCE_KNOWN, _("Known"));
+	gtk_combo_box_insert_text (GTK_COMBO_BOX (aud_box), EXTERNAL_AUDIENCE_ALL, _("All"));
+	gtk_combo_box_set_active (GTK_COMBO_BOX (aud_box), oof_data->audience_type);
+	gtk_widget_set_tooltip_text (GTK_WIDGET (aud_box), _("Send Message to"));
+
+	oof_data->aud_box = aud_box;
+	gtk_box_pack_start (GTK_BOX (hbox_ext), GTK_WIDGET (aud_box), FALSE, FALSE, 0);
+	g_signal_connect (GTK_COMBO_BOX (aud_box), "changed", G_CALLBACK (update_audience_cb), NULL);
+
+	scrwnd_oof_ext = (GtkScrolledWindow*) g_object_new (GTK_TYPE_SCROLLED_WINDOW, "hscrollbar-policy", GTK_POLICY_AUTOMATIC, "vscrollbar-policy", GTK_POLICY_AUTOMATIC, "shadow-type", GTK_SHADOW_IN, NULL);
+	gtk_box_pack_start (GTK_BOX (hbox_ext), GTK_WIDGET (scrwnd_oof_ext), TRUE, TRUE, 0);
+	txtview_oof_ext = (GtkTextView*) g_object_new (GTK_TYPE_TEXT_VIEW, "justification", GTK_JUSTIFY_LEFT, "wrap-mode", GTK_WRAP_WORD, "editable", TRUE, NULL);
+
+	buffer_ext = gtk_text_view_get_buffer (txtview_oof_ext);
+	if (oof_data->external_message) {
+		/* previuosly set message */
+		gtk_text_buffer_set_text (buffer_ext, oof_data->external_message, -1);
+		gtk_text_view_set_buffer (txtview_oof_ext, buffer_ext);
+
+	}
+	gtk_text_buffer_set_modified (buffer_ext, FALSE);
+	gtk_container_add (GTK_CONTAINER (scrwnd_oof_ext), GTK_WIDGET (txtview_oof_ext));
+
+	lbl_external = (GtkLabel*) g_object_new (GTK_TYPE_LABEL, "label", _("E_xternal:"), "use-underline", TRUE, "use-markup", TRUE, NULL);
+	gtk_label_set_mnemonic_widget (lbl_external, GTK_WIDGET (txtview_oof_ext));
+	gtk_widget_set_tooltip_text (GTK_WIDGET (lbl_external), _("Message to be sent outside organization"));
+	gtk_misc_set_alignment (GTK_MISC (lbl_external), 0, 0.5);
+	gtk_misc_set_padding (GTK_MISC (lbl_external), 0, 0);
+
+	g_signal_connect (buffer_int, "changed", G_CALLBACK (update_int_msg_cb), NULL);
+	g_signal_connect (buffer_ext, "changed", G_CALLBACK (update_ext_msg_cb), NULL);
+
+
+	
+	gtk_table_attach (tbl_oof_status, GTK_WIDGET (lbl_status), 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
+	gtk_table_attach (tbl_oof_status, GTK_WIDGET (hbox_state), 1, 2, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
+	gtk_table_attach (tbl_oof_status, GTK_WIDGET (from_label), 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
+	gtk_table_attach (tbl_oof_status, GTK_WIDGET (from_date), 1, 2, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
+	gtk_table_attach (tbl_oof_status, GTK_WIDGET (to_label), 0, 1, 2, 3, GTK_FILL, GTK_FILL, 0, 0);
+	gtk_table_attach (tbl_oof_status, GTK_WIDGET (to_date), 1, 2, 2, 3, GTK_FILL, GTK_FILL, 0, 0);
+	gtk_table_attach (tbl_oof_status, GTK_WIDGET (lbl_internal), 0, 1, 3, 4, GTK_FILL, GTK_FILL, 0, 0);
+	gtk_table_attach (tbl_oof_status, GTK_WIDGET (scrwnd_oof_int), 1, 2, 3, 4, GTK_FILL, GTK_FILL, 0, 0);
+	gtk_table_attach (tbl_oof_status, GTK_WIDGET (lbl_external), 0, 1, 4, 5, GTK_FILL, GTK_FILL, 0, 0);
+	gtk_table_attach (tbl_oof_status, GTK_WIDGET (hbox_ext), 1, 2, 4, 5, GTK_FILL, GTK_FILL, 0, 0);
+
+
+	gtk_box_pack_start (GTK_BOX (vbox_oof), GTK_WIDGET (tbl_oof_status), FALSE, FALSE, 0);
+
+
+	if (!oof_data->state) {
+		gtk_widget_set_sensitive (GTK_WIDGET (txtview_oof_int), FALSE);
+		gtk_widget_set_sensitive (GTK_WIDGET (txtview_oof_ext), FALSE);
+		gtk_widget_set_sensitive ((GtkWidget *) from_date, FALSE);
+		gtk_widget_set_sensitive ((GtkWidget *) to_date, FALSE);
+		gtk_widget_set_sensitive (aud_box, FALSE);
+	}
+
+	oof_data->internal_view = GTK_WIDGET (txtview_oof_int);
+	oof_data->external_view = GTK_WIDGET (txtview_oof_ext);
+
+	gtk_widget_show_all (GTK_WIDGET (vbox_oof));
+}
+
+static void
+get_oof_settings_cb (GObject *object, GAsyncResult *res, gpointer user_data)
+{
+	EEwsConnection *cnc = E_EWS_CONNECTION (object);
+	GtkWidget *oof_frame = GTK_WIDGET (user_data);
+	OOFSettings *oof_settings = NULL;
+	GError *error = NULL;
+
+	e_ews_connection_get_oof_settings_finish (cnc, res, &oof_settings, &error);
+
+	if (error) {
+		g_warning ("Error Unable to get out of office settings: %s\n", error->message);
+		set_oof_error_to_frame (oof_frame, error);
+		g_object_unref (cnc);
+		g_clear_error (&error);
+		return;
+	}
+
+	if (!g_ascii_strcasecmp (oof_settings->state, "Disabled"))
+		oof_data->state = FALSE;
+	else
+		oof_data->state = TRUE;
+
+	oof_data->audience = g_strdup (oof_settings->ext_aud);
+	update_audience_type ();
+	oof_data->from_time = oof_settings->start_tm;
+	oof_data->to_time = oof_settings->end_tm;
+	oof_data->internal_message = g_strdup (oof_settings->int_reply);
+	oof_data->external_message = g_strdup (oof_settings->ext_reply);
+
+	set_oof_settings_to_frame (oof_frame);
+	e_ews_connection_free_oof_settings (oof_settings);
+	g_object_unref (cnc);
+}
+
+static void
+set_oof_data_from_settings (EMConfigTargetAccount *target, GtkWidget *oof_frame)
+{
+	GCancellable *cancellable = NULL;
+	EEwsConnection *cnc = NULL;
+
+	cnc = get_connection (target);
+	if (!cnc)
+		return;
+
+	cancellable = g_cancellable_new ();
+	
+	e_ews_connection_get_oof_settings_start (cnc, EWS_PRIORITY_MEDIUM,
+					   	 get_oof_settings_cb, cancellable,
+					   	 oof_frame);
+}
+
+static OOFSettings*
+get_settings_from_data (void)
+{
+	OOFSettings *oof_settings = NULL;
+
+	oof_settings = g_new0 (OOFSettings, 1);
+
+	if (oof_data->from_time >= oof_data->to_time) {
+		g_warning ("Set valid time range");
+		oof_data->from_time = 0;
+		oof_data->to_time = 0;
+	}
+
+	if (oof_data->state) {
+		if (oof_data->from_time && oof_data->to_time)
+			oof_settings->state = g_strdup ("Scheduled");
+		else
+			oof_settings->state = g_strdup ("Enabled");
+	} else
+		oof_settings->state = g_strdup ("Disabled");
+
+	oof_settings->ext_aud = g_strdup (oof_data->audience);
+	oof_settings->start_tm = oof_data->from_time;
+	oof_settings->end_tm = oof_data->to_time;
+	oof_settings->int_reply = g_strdup (oof_data->internal_message);
+	oof_settings->ext_reply = g_strdup (oof_data->external_message);
+
+	return oof_settings;
+}
+
+gboolean
+ews_set_oof_settings (EMConfigTargetAccount *target)
+{
+	GCancellable *cancellable = NULL;
+	OOFSettings *oof_settings = NULL;
+	EEwsConnection *cnc = NULL;
+	GError *error = NULL;
+	gboolean ret_val;
+
+	cnc = get_connection (target);
+	if (!cnc) {
+		destroy_oof_data ();
+		return FALSE;
+	}
+
+	cancellable = g_cancellable_new ();
+
+	oof_settings = get_settings_from_data ();
+
+	e_ews_connection_set_oof_settings (cnc, EWS_PRIORITY_MEDIUM,
+					   oof_settings, cancellable,
+					   &error);
+
+	if (error) {
+		g_warning ("Error While setting out of office: %s\n", error->message);
+		g_clear_error (&error);
+		ret_val = FALSE;
+	} else
+		ret_val = TRUE;
+
+	destroy_oof_data ();
+	e_ews_connection_free_oof_settings (oof_settings);
+	g_object_unref (cnc);
+
+	return ret_val;
+}
+
+GtkWidget *
+ews_get_outo_office_widget (EMConfigTargetAccount *target_account)
+{
+	GtkFrame *frm_oof;
+	GtkHBox *stat_box;
+	GtkLabel *stat_msg;
+
+	frm_oof = (GtkFrame*) g_object_new (GTK_TYPE_FRAME, "label", _("Out of Office"), NULL);
+
+	oof_data_new ();
+	
+	stat_box = (GtkHBox*) g_object_new (GTK_TYPE_HBOX, NULL, "homogeneous", FALSE, "spacing", 6, NULL);
+	stat_msg = (GtkLabel*) g_object_new (GTK_TYPE_LABEL, "label", _("Fetching out of office settings..."), "use-markup", TRUE, NULL);
+
+	oof_data->stat_box = GTK_WIDGET (stat_box);
+
+	gtk_box_pack_start (GTK_BOX (stat_box), GTK_WIDGET (stat_msg), FALSE, FALSE, 12);
+	gtk_container_add (GTK_CONTAINER (frm_oof), GTK_WIDGET (stat_box));
+
+	set_oof_data_from_settings (target_account, (GtkWidget*) frm_oof);
+
+	return (GtkWidget *) frm_oof;
+}
diff --git a/src/account-setup-eplugin/exchange-ews-account-out-of-office.h b/src/account-setup-eplugin/exchange-ews-account-out-of-office.h
new file mode 100644
index 0000000..e4b30fb
--- /dev/null
+++ b/src/account-setup-eplugin/exchange-ews-account-out-of-office.h
@@ -0,0 +1,25 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ * Authors : Punit Jain <jpunit suse com>
+ *
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ */
+#include <gtk/gtk.h>
+#include "mail/em-config.h"
+
+GtkWidget*		ews_get_outo_office_widget (EMConfigTargetAccount *target_account);
+gboolean		ews_set_oof_settings (EMConfigTargetAccount *target);
diff --git a/src/account-setup-eplugin/exchange-ews-account-setup.c b/src/account-setup-eplugin/exchange-ews-account-setup.c
index ac0ed93..574f317 100644
--- a/src/account-setup-eplugin/exchange-ews-account-setup.c
+++ b/src/account-setup-eplugin/exchange-ews-account-setup.c
@@ -37,7 +37,9 @@
 #include "ews-plugin-compat.h"
 #include <addressbook/gui/widgets/eab-config.h>
 #include <calendar/gui/e-cal-config.h>
+#include <exchange-ews-account-out-of-office.h>
 
+#include <camel/camel.h>
 #include <camel-ews-folder.h>
 #include <e-ews-connection.h>
 #include <camel-ews-utils.h>
@@ -62,6 +64,10 @@ gboolean org_gnome_exchange_ews_check_options(EPlugin *epl, EConfigHookPageCheck
 /* OAB receiving options */
 GtkWidget * org_gnome_ews_oab_settings (EPlugin *epl, EConfigHookItemFactoryData *data);
 
+/*Ews Settings Page*/
+GtkWidget * org_gnome_ews_settings (EPlugin *epl, EConfigHookItemFactoryData *data);
+void	org_gnome_exchange_ews_commit ( EPlugin *epl, EConfigHookItemFactoryData *data);
+
 static ExchangeEWSAccountListener *config_listener = NULL;
 
 static void
@@ -116,7 +122,7 @@ static void autodiscover_callback (EwsUrls *urls, gpointer user_data, GError *er
 	}
 	if (urls) {
 		char *oab_url;
-		
+
 		gtk_entry_set_text (GTK_ENTRY (cbdata->host_entry), urls->as_url);
 
 		oab_url = g_strconcat (urls->oab_url, "oab.xml", NULL);
@@ -706,3 +712,75 @@ org_gnome_ews_oab_settings (EPlugin *epl, EConfigHookItemFactoryData *data)
 	camel_url_free (url);
 	return NULL;
 }
+
+void
+org_gnome_exchange_ews_commit ( EPlugin *epl,
+				EConfigHookItemFactoryData *data)
+{
+	EMConfigTargetAccount *target_account;
+	const gchar *source_url;
+	CamelURL *url = NULL;
+
+	target_account = (EMConfigTargetAccount *) data->config->target;
+
+	/*return if it is not a ews account*/
+	source_url = e_account_get_string (target_account->account,  E_ACCOUNT_SOURCE_URL);
+	url = camel_url_new(source_url, NULL);
+	if (url == NULL
+	    || g_strcmp0 (url->protocol, "ews") != 0) {
+		if (url)
+			camel_url_free(url);
+		return;
+	}
+
+	if (!ews_plugin_get_online_status ()) {
+		camel_url_free (url);
+		return;
+	}
+
+	/* Set oof data in exchange account */
+	ews_set_oof_settings (target_account);
+}
+
+GtkWidget *
+org_gnome_ews_settings (EPlugin *epl, EConfigHookItemFactoryData *data)
+{
+	EMConfigTargetAccount *target_account;
+	CamelURL *url = NULL;
+	const gchar *source_url;
+	GtkVBox *vbox_settings;
+	GtkWidget *oof;
+
+	target_account = (EMConfigTargetAccount *) data->config->target;
+
+	/*return if it is not a ews account*/
+	source_url = e_account_get_string (target_account->account,  E_ACCOUNT_SOURCE_URL);
+	url = camel_url_new(source_url, NULL);
+	if (url == NULL
+	    || g_strcmp0 (url->protocol, "ews") != 0) {
+		if (url)
+			camel_url_free(url);
+		return NULL;
+	}
+
+	if (data->old) {
+		camel_url_free(url);
+		return data->old;
+	}
+
+	if (!ews_plugin_get_online_status ()) {
+		camel_url_free (url);
+		return NULL;
+	}
+
+	vbox_settings = (GtkVBox*) g_object_new (GTK_TYPE_VBOX, "homogeneous", FALSE, "spacing", 6, NULL);
+	gtk_container_set_border_width (GTK_CONTAINER (vbox_settings), 12);
+
+	/*Get Out of office widget*/
+	oof = ews_get_outo_office_widget (target_account);
+	gtk_box_pack_start (GTK_BOX (vbox_settings), oof, FALSE, FALSE, 0);
+
+	gtk_widget_show_all (GTK_WIDGET (vbox_settings));
+	gtk_notebook_insert_page (GTK_NOTEBOOK (data->parent), GTK_WIDGET (vbox_settings), gtk_label_new(_("EWS Settings")), 4);
+	return GTK_WIDGET (vbox_settings);
+}
diff --git a/src/account-setup-eplugin/org-gnome-exchange-ews.eplug.xml b/src/account-setup-eplugin/org-gnome-exchange-ews.eplug.xml
index f0ec9b6..e7235ef 100644
--- a/src/account-setup-eplugin/org-gnome-exchange-ews.eplug.xml
+++ b/src/account-setup-eplugin/org-gnome-exchange-ews.eplug.xml
@@ -35,7 +35,9 @@
 	<hook class="org.gnome.evolution.mail.config:1.0">
 		<group 	target="account" 
 			id="org.gnome.evolution.mail.config.accountEditor" 
-			check="org_gnome_exchange_ews_check_options">
+			check="org_gnome_exchange_ews_check_options"
+			commit="org_gnome_exchange_ews_commit">
+			<item type="page" path="40.oof" _label="EWS Settings" factory="org_gnome_ews_settings"/>
 			<item type="item_table" path="10.receive/10.config/30.ews" factory="org_gnome_exchange_ews_account_setup"/>
 			<item type="section_table" path="20.receive_options/20.gal" _label="GAL settings"/>
 			<item type="item_table" path="20.receive_options/20.gal/10.oab" factory="org_gnome_ews_oab_settings"/>
diff --git a/src/server/e-ews-connection.c b/src/server/e-ews-connection.c
index b4c49bb..e17c701 100644
--- a/src/server/e-ews-connection.c
+++ b/src/server/e-ews-connection.c
@@ -426,7 +426,9 @@ ews_response_cb (SoupSession *session, SoupMessage *msg, gpointer data)
 			e_soap_response_dump_response (response, stdout);
 
 		param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessages");
-		if (!param) param = e_soap_response_get_first_parameter_by_name (response, "FreeBusyResponseArray");
+		if (!param) 
+			param = e_soap_response_get_first_parameter_by_name (response, "FreeBusyResponseArray");
+
 		if (param) {
 			/* Iterate over all "*ResponseMessage" elements. */
 			for (subparam = e_soap_parameter_get_first_child (param);
@@ -449,6 +451,15 @@ ews_response_cb (SoupSession *session, SoupMessage *msg, gpointer data)
 				if (enode->cb)
 					enode->cb (subparam, enode);
 			}
+		} else if ((param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessage"))) {
+			/*Parse GetUserOofSettingsResponse and SetUserOofSettingsResponse*/
+			if (!ews_get_response_status (param, &error)) {
+					g_simple_async_result_set_from_error (enode->simple, error);
+			} else {
+				subparam = e_soap_parameter_get_next_child (param);
+				if (enode->cb)
+					enode->cb (subparam, enode);
+			}
 		} else
 			ews_parse_soap_fault (response, &error);
 
@@ -629,6 +640,95 @@ get_items_response_cb (ESoapParameter *subparam, EwsNode *enode)
 	}
 }
 
+static gchar *
+get_text_from_html (gchar *html_text)
+{
+	gssize haystack_len = strlen (html_text);
+	gchar *plain_text, *ret_text;
+	gchar *start = g_strstr_len (html_text, haystack_len, "<body"),
+		*end = g_strstr_len (html_text, haystack_len, "</body>"),
+		*i, *j;
+
+	plain_text = g_malloc (end - start);
+	i = start;
+	for (j = plain_text; i < end; i++) {
+		if (*i == '<') {
+			while (*i != '>')
+				i++;
+		} else {
+			*j = *i;
+			j++;
+		}
+	}
+
+	*j = '\0';
+	ret_text = g_strdup (plain_text);
+
+	g_free (html_text);
+	g_free (plain_text);
+
+	return ret_text;
+}
+
+static void
+get_oof_settings_response_cb (ESoapParameter *subparam, EwsNode *enode)
+{
+	ESoapParameter *node, *node_1;
+	EwsAsyncData *async_data;
+	OOFSettings *oof_settings;
+	gchar *state = NULL, *ext_aud = NULL;
+	gchar *start_tm = NULL, *end_tm = NULL;
+	gchar *ext_msg = NULL, *int_msg = NULL;
+	GTimeVal time_val;
+
+	node = e_soap_parameter_get_first_child_by_name (subparam, "OofState");
+	state = e_soap_parameter_get_string_value (node);
+
+	node = e_soap_parameter_get_first_child_by_name (subparam, "ExternalAudience");
+	ext_aud = e_soap_parameter_get_string_value (node);
+
+	node = e_soap_parameter_get_first_child_by_name (subparam, "Duration");
+
+	node_1 = e_soap_parameter_get_first_child_by_name (node, "StartTime");
+	start_tm = e_soap_parameter_get_string_value (node_1);
+
+	node_1 = e_soap_parameter_get_first_child_by_name (node, "EndTime");
+	end_tm = e_soap_parameter_get_string_value (node_1);
+
+	node = e_soap_parameter_get_first_child_by_name (subparam, "InternalReply");
+	node_1 = e_soap_parameter_get_first_child_by_name (node, "Message");
+	int_msg = e_soap_parameter_get_string_value (node_1);
+	if (g_strrstr (int_msg, "</body>"))
+		int_msg = get_text_from_html (int_msg);
+
+	node = e_soap_parameter_get_first_child_by_name (subparam, "ExternalReply");
+	node_1 = e_soap_parameter_get_first_child_by_name (node, "Message");
+	ext_msg = e_soap_parameter_get_string_value (node_1);
+	if (g_strrstr (ext_msg, "</body>"))
+		ext_msg = get_text_from_html (ext_msg);
+
+	oof_settings = g_new0 (OOFSettings, 1);
+
+	oof_settings->state = state;
+	oof_settings->ext_aud = ext_aud;
+
+	if (g_time_val_from_iso8601 (start_tm, &time_val))
+		oof_settings->start_tm = time_val.tv_sec;
+
+	if (g_time_val_from_iso8601 (end_tm, &time_val))
+		oof_settings->end_tm = time_val.tv_sec;
+	
+	oof_settings->int_reply = int_msg;
+	oof_settings->ext_reply = ext_msg;
+
+
+	async_data = g_simple_async_result_get_op_res_gpointer (enode->simple);
+	async_data->items = g_slist_append (async_data->items, oof_settings);
+
+	g_free (start_tm);
+	g_free (end_tm);
+}
+
 static void
 resolve_names_response_cb (ESoapParameter *subparam, EwsNode *enode)
 {
@@ -1261,7 +1361,7 @@ e_ews_get_msg_for_url (const gchar *url, xmlOutputBuffer *buf)
 {
 	SoupMessage *msg;
 
-	msg = soup_message_new(buf?"POST":"GET", url);
+	msg = soup_message_new (buf?"POST":"GET", url);
 	soup_message_headers_append (msg->request_headers,
 				     "User-Agent", "libews/0.1");
 
@@ -1374,14 +1474,18 @@ e_ews_autodiscover_ws_url (EEwsAutoDiscoverCallback cb, gpointer cbdata,
 
 	/* These have to be submitted only after they're both set in ad->msgs[]
 	   or there will be races with fast completion */
-	soup_session_queue_message (cnc->priv->soup_session, ad->msgs[0],
-				    autodiscover_response_cb, ad);
-	soup_session_queue_message (cnc->priv->soup_session, ad->msgs[1],
-				    autodiscover_response_cb, ad);
-	soup_session_queue_message (cnc->priv->soup_session, ad->msgs[2],
-				    autodiscover_response_cb, ad);
-	soup_session_queue_message (cnc->priv->soup_session, ad->msgs[3],
-				    autodiscover_response_cb, ad);
+	if (ad->msgs[0])
+		soup_session_queue_message (cnc->priv->soup_session, ad->msgs[0],
+					    autodiscover_response_cb, ad);
+	if (ad->msgs[1])
+		soup_session_queue_message (cnc->priv->soup_session, ad->msgs[1],
+					    autodiscover_response_cb, ad);
+	if (ad->msgs[2])
+		soup_session_queue_message (cnc->priv->soup_session, ad->msgs[2],
+					    autodiscover_response_cb, ad);
+	if (ad->msgs[3])
+		soup_session_queue_message (cnc->priv->soup_session, ad->msgs[3],
+					    autodiscover_response_cb, ad);
 
 	g_object_unref (cnc); /* the GSimpleAsyncResult holds it now */
 
@@ -4691,7 +4795,6 @@ e_ews_connection_get_delegate_finish	(EEwsConnection *cnc,
 	return TRUE;
 }
 
-gboolean
 /**
  * e_ews_connection_get_delegate
  * @cnc:
@@ -4701,6 +4804,7 @@ gboolean
  * @cancellable:
  * @error:
  **/
+gboolean
 e_ews_connection_get_delegate	(EEwsConnection *cnc,
 				 gint pri,
 				 const gchar *mail_id,
@@ -4734,3 +4838,249 @@ e_ews_connection_get_delegate	(EEwsConnection *cnc,
 
 }
 
+/**
+ * e_ews_connection__get_oof_settings_start
+ * @cnc: The EWS Connection
+ * @pri: The priority associated with the request
+ * @cb: Responses are parsed and returned to this callback
+ * @cancellable: a GCancellable to monitor cancelled operations
+ * @user_data: user data passed to callback
+ **/
+void
+e_ews_connection_get_oof_settings_start	(EEwsConnection *cnc,
+					 gint pri,
+					 GAsyncReadyCallback cb,
+					 GCancellable *cancellable,
+					 gpointer user_data)
+{
+	ESoapMessage *msg;
+	GSimpleAsyncResult *simple;
+	EwsAsyncData *async_data;
+
+	msg = e_ews_message_new_with_header (cnc->priv->uri, "GetUserOofSettingsRequest", NULL, NULL, EWS_EXCHANGE_2007_SP1);
+
+	e_soap_message_start_element (msg, "Mailbox", NULL, NULL);
+	e_ews_message_write_string_parameter (msg, "Address", NULL, cnc->priv->email);
+	e_soap_message_end_element (msg);
+
+	/* Complete the footer and print the request */
+	e_ews_message_write_footer (msg);
+
+      	simple = g_simple_async_result_new (G_OBJECT (cnc),
+					    cb, user_data,
+					    e_ews_connection_get_oof_settings_start);
+
+	async_data = g_new0 (EwsAsyncData, 1);
+	g_simple_async_result_set_op_res_gpointer (
+		simple, async_data, (GDestroyNotify) async_data_free);
+
+	ews_connection_queue_request (cnc, msg, get_oof_settings_response_cb, pri,
+				      cancellable, simple, cb == ews_sync_reply_cb);
+}
+
+gboolean
+e_ews_connection_get_oof_settings_finish	(EEwsConnection *cnc,
+						 GAsyncResult *result,
+						 OOFSettings **oof_settings,
+						 GError **error)
+{
+	GSimpleAsyncResult *simple;
+	EwsAsyncData *async_data;
+
+	g_return_val_if_fail (
+		g_simple_async_result_is_valid (
+		result, G_OBJECT (cnc), e_ews_connection_get_oof_settings_start),
+		FALSE);
+
+	simple = G_SIMPLE_ASYNC_RESULT (result);
+	async_data = g_simple_async_result_get_op_res_gpointer (simple);
+
+	if (g_simple_async_result_propagate_error (simple, error))
+		return FALSE;
+
+	*oof_settings = (OOFSettings *) async_data->items->data;
+
+	return TRUE;
+}
+
+gboolean
+e_ews_connection_get_oof_settings	(EEwsConnection *cnc,
+					 gint pri,
+					 OOFSettings **oof_settings,
+					 GCancellable *cancellable,
+					 GError **error)
+{
+	EwsSyncData *sync_data;
+	gboolean result;
+
+	sync_data = g_new0 (EwsSyncData, 1);
+	sync_data->eflag = e_flag_new ();
+
+	e_ews_connection_get_oof_settings_start	(cnc, pri,
+						 ews_sync_reply_cb, cancellable,
+						 (gpointer) sync_data);
+
+	e_flag_wait (sync_data->eflag);
+
+	result = e_ews_connection_get_oof_settings_finish (cnc, sync_data->res,
+							    oof_settings, error);
+
+	e_flag_free (sync_data->eflag);
+	g_object_unref (sync_data->res);
+	g_free (sync_data);
+
+	return result;
+}
+
+/**
+ * e_ews_connection__set_oof_settings_start
+ * @cnc: The EWS Connection
+ * @pri: The priority associated with the request
+ * @oof_settings: Details to set for ooof
+ * @cb: Responses are parsed and returned to this callback
+ * @cancellable: a GCancellable to monitor cancelled operations
+ * @user_data: user data passed to callback
+ **/
+void
+e_ews_connection_set_oof_settings_start	(EEwsConnection *cnc,
+					 gint pri,
+					 OOFSettings *oof_settings,
+					 GAsyncReadyCallback cb,
+					 GCancellable *cancellable,
+					 gpointer user_data)
+{
+	ESoapMessage *msg;
+	GSimpleAsyncResult *simple;
+	EwsAsyncData *async_data;
+	gchar *start_tm = NULL, *end_tm = NULL;
+	GTimeVal *time_val;
+
+	msg = e_ews_message_new_with_header (cnc->priv->uri, "SetUserOofSettingsRequest", NULL, NULL, EWS_EXCHANGE_2007_SP1);
+
+	/*Set Mailbox to user Address we want to set*/
+	e_soap_message_start_element (msg, "Mailbox", NULL, NULL);
+	e_ews_message_write_string_parameter (msg, "Address", NULL, cnc->priv->email);
+	e_soap_message_end_element (msg);
+
+	/*Write out of office settings to message*/
+	e_soap_message_start_element (msg, "UserOofSettings", NULL, NULL);
+	e_ews_message_write_string_parameter (msg, "OofState", NULL, oof_settings->state);
+	e_ews_message_write_string_parameter (msg, "ExternalAudience", NULL, oof_settings->ext_aud);
+
+	time_val = g_new0 (GTimeVal, 1);
+	time_val->tv_sec = oof_settings->start_tm;
+	start_tm = g_time_val_to_iso8601 (time_val);
+
+	time_val->tv_sec = oof_settings->end_tm;
+	end_tm = g_time_val_to_iso8601 (time_val);
+
+	e_soap_message_start_element (msg, "Duration", NULL, NULL);
+	e_ews_message_write_string_parameter (msg, "StartTime", NULL, start_tm);
+	e_ews_message_write_string_parameter (msg, "EndTime", NULL, end_tm);
+	e_soap_message_end_element (msg);
+
+	e_soap_message_start_element (msg, "InternalReply", NULL, NULL);
+	e_ews_message_write_string_parameter (msg, "Message", NULL, oof_settings->int_reply);
+	e_soap_message_end_element (msg);
+
+	e_soap_message_start_element (msg, "ExternalReply", NULL, NULL);
+	e_ews_message_write_string_parameter (msg, "Message", NULL, oof_settings->ext_reply);
+	e_soap_message_end_element (msg);
+
+	e_soap_message_end_element (msg);
+
+	/* Complete the footer and print the request */
+	e_ews_message_write_footer (msg);
+
+      	simple = g_simple_async_result_new (G_OBJECT (cnc),
+					    cb, user_data,
+					    e_ews_connection_set_oof_settings_start);
+
+	async_data = g_new0 (EwsAsyncData, 1);
+	g_simple_async_result_set_op_res_gpointer (
+		simple, async_data, (GDestroyNotify) async_data_free);
+
+	ews_connection_queue_request (cnc, msg, NULL, pri,
+				      cancellable, simple, cb == ews_sync_reply_cb);
+
+	g_free (time_val);
+	g_free (start_tm);
+	g_free (end_tm);
+}
+
+gboolean
+e_ews_connection_set_oof_settings_finish	(EEwsConnection *cnc,
+						 GAsyncResult *result,
+						 GError **error)
+{
+	GSimpleAsyncResult *simple;
+	EwsAsyncData *async_data;
+
+	g_return_val_if_fail (
+		g_simple_async_result_is_valid (
+		result, G_OBJECT (cnc), e_ews_connection_set_oof_settings_start),
+		FALSE);
+
+	simple = G_SIMPLE_ASYNC_RESULT (result);
+	async_data = g_simple_async_result_get_op_res_gpointer (simple);
+
+	if (g_simple_async_result_propagate_error (simple, error))
+		return FALSE;
+
+	return TRUE;
+}
+
+gboolean
+e_ews_connection_set_oof_settings	(EEwsConnection *cnc,
+					 gint pri,
+					 OOFSettings *oof_settings,
+					 GCancellable *cancellable,
+					 GError **error)
+{
+	EwsSyncData *sync_data;
+	gboolean result;
+
+	sync_data = g_new0 (EwsSyncData, 1);
+	sync_data->eflag = e_flag_new ();
+
+	e_ews_connection_set_oof_settings_start	(cnc, pri, oof_settings,
+						 ews_sync_reply_cb, cancellable,
+						 (gpointer) sync_data);
+
+	e_flag_wait (sync_data->eflag);
+
+	result = e_ews_connection_set_oof_settings_finish (cnc, sync_data->res,
+							    error);
+
+	e_flag_free (sync_data->eflag);
+	g_object_unref (sync_data->res);
+	g_free (sync_data);
+
+	return result;
+}
+
+void
+e_ews_connection_free_oof_settings (OOFSettings *oof_settings)
+{
+	if (oof_settings->state) {
+		g_free (oof_settings->state);
+		oof_settings->state = NULL;
+	}
+	if (oof_settings->ext_aud) {
+		g_free (oof_settings->ext_aud);
+		oof_settings->ext_aud = NULL;
+	}
+	if (oof_settings->int_reply) {
+		g_free (oof_settings->int_reply);
+		oof_settings->int_reply = NULL;
+	}
+	if (oof_settings->ext_reply) {
+		g_free (oof_settings->ext_reply);
+		oof_settings->ext_reply = NULL;
+	}
+
+	if (oof_settings) {
+		g_free (oof_settings);
+		oof_settings = NULL;
+	}
+}
diff --git a/src/server/e-ews-connection.h b/src/server/e-ews-connection.h
index 60e1465..1f47ba8 100644
--- a/src/server/e-ews-connection.h
+++ b/src/server/e-ews-connection.h
@@ -170,6 +170,15 @@ typedef struct {
 	gpointer field_uri;
 } EwsSortOrder;
 
+typedef struct {
+	gchar *state;		/*Out of office state*/
+	gchar *ext_aud;		/*external audience*/
+	time_t start_tm;	/*Start time*/
+	time_t end_tm;		/*End time*/
+	gchar *int_reply;	/*Internal Reply*/
+	gchar *ext_reply;	/*External Reply*/
+} OOFSettings;
+
 GType		e_ews_connection_get_type	(void);
 EEwsConnection *e_ews_connection_new		(const gchar *uri,
 						 const gchar *username,
@@ -811,8 +820,41 @@ gboolean e_ews_connection_get_delegate
 						 GCancellable *cancellable,
 						 GError **error);
 
+void		e_ews_connection_get_oof_settings_start	(EEwsConnection *cnc,
+							 gint pri,
+							 GAsyncReadyCallback cb,
+							 GCancellable *cancellable,
+							 gpointer user_data);
+
+gboolean	e_ews_connection_get_oof_settings_finish (EEwsConnection *cnc,
+							  GAsyncResult *result,
+							  OOFSettings **oof_settings,
+							  GError **error);
+
+gboolean	e_ews_connection_get_oof_settings (EEwsConnection *cnc,
+						   gint pri,
+						   OOFSettings **oof_settings,
+						   GCancellable *cancellable,
+						   GError **error);
+
+void		e_ews_connection_set_oof_settings_start	(EEwsConnection *cnc,
+							 gint pri,
+							 OOFSettings *oof_settings,
+							 GAsyncReadyCallback cb,
+							 GCancellable *cancellable,
+							 gpointer user_data);
+
+gboolean	e_ews_connection_set_oof_settings_finish (EEwsConnection *cnc,
+							  GAsyncResult *result,
+						 	  GError **error);
 
+gboolean	e_ews_connection_set_oof_settings (EEwsConnection *cnc,
+					 	   gint pri,
+					 	   OOFSettings *oof_settings,
+					 	   GCancellable *cancellable,
+					 	   GError **error);
 
+void		e_ews_connection_free_oof_settings (OOFSettings *oof_settings);
 
 G_END_DECLS
 
diff --git a/src/server/tests/Makefile.am b/src/server/tests/Makefile.am
index 4c5fb7a..b87702d 100644
--- a/src/server/tests/Makefile.am
+++ b/src/server/tests/Makefile.am
@@ -25,6 +25,8 @@ testews_SOURCES = 				\
 		test-deletefolder.c		\
 		test-getdelegate.c		\
 		test-libews.c 			\
+		test-get-oof-settings.c		\
+		test-set-oof-settings.c		\
 		utils.h
 
 #Fixme: Ugly. Kill me later
diff --git a/src/server/tests/test-connection.c b/src/server/tests/test-connection.c
index 811d9c7..9c3b85b 100644
--- a/src/server/tests/test-connection.c
+++ b/src/server/tests/test-connection.c
@@ -56,6 +56,8 @@ con_test_create_new_connection ()
 	cnc = e_ews_connection_new (uri, username, password, NULL, NULL, NULL);
 	g_assert (cnc != NULL);
 
+	g_print ("\nSuccess : Created a new connection\n");
+
 	/* Quit the test suite */
 	//g_signal_connect (cnc, "shutdown", G_CALLBACK (ews_conn_shutdown), NULL);
 }
diff --git a/src/server/tests/test-get-oof-settings.c b/src/server/tests/test-get-oof-settings.c
new file mode 100644
index 0000000..f422600
--- /dev/null
+++ b/src/server/tests/test-get-oof-settings.c
@@ -0,0 +1,104 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Authors : Punit Jain <jpunit suse com>
+ *
+ * Copyright (C) 1999-2011 Novell, Inc. (www.novell.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+
+/* API : e_ews_connection_get_oof_settings */
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <glib.h>
+#include <glib/gprintf.h>
+#include "utils.h"
+#include <e-ews-connection.h>
+#include <e-ews-message.h>
+
+void get_oof_settings_test_run ();
+static GMainLoop *main_loop;
+
+static void
+get_oof_settings_cb (GObject *object, GAsyncResult *res, gpointer data)
+{
+	EEwsConnection *cnc = E_EWS_CONNECTION (object);
+	OOFSettings *oof_settings;
+	GError *error = NULL;
+
+	e_ews_connection_get_oof_settings_finish (cnc, res, &oof_settings,
+						  &error);
+	if (error != NULL) {
+		g_warning ("Unable to get out of office settings: %s \n", error->message);
+		g_clear_error (&error);
+		goto quit;
+	}
+
+	g_print ("Success : Fetched out of office settings successfully \n");
+
+quit:
+	g_main_loop_quit(main_loop);
+}
+
+static void
+op_test_get_oof_settings ()
+{
+	const gchar *username;
+	const gchar *password;
+	const gchar *uri, *email;
+	EEwsConnection *cnc;
+	GCancellable *cancellable;
+
+	cancellable = g_cancellable_new ();
+
+	util_get_login_info_from_env (&username, &password, &uri);
+	util_get_email_from_env (&email);
+
+	g_assert_cmpstr (username, !=, NULL);
+	g_assert_cmpstr (password, !=, NULL);
+	g_assert_cmpstr (uri, !=, NULL);
+	g_assert_cmpstr (email, !=, NULL);
+
+	cnc = e_ews_connection_new (uri, username, password, NULL, NULL, NULL);
+	g_assert (cnc != NULL);
+
+	e_ews_connection_set_mailbox (cnc, email);
+
+	e_ews_connection_get_oof_settings_start	(cnc, EWS_PRIORITY_MEDIUM,
+						 get_oof_settings_cb,
+						 cancellable, NULL);
+}
+
+static gboolean
+idle_cb (gpointer data)
+{
+	op_test_get_oof_settings ();
+	return FALSE;
+}
+
+void
+get_oof_settings_test_run ()
+{
+	g_type_init ();
+
+	main_loop = g_main_loop_new (NULL, TRUE);
+	g_idle_add ((GSourceFunc) idle_cb, NULL);
+	g_main_loop_run (main_loop);
+
+	/* terminate */
+	g_main_loop_unref (main_loop);
+}
diff --git a/src/server/tests/test-libews.c b/src/server/tests/test-libews.c
index 8d52c36..7f5a535 100644
--- a/src/server/tests/test-libews.c
+++ b/src/server/tests/test-libews.c
@@ -7,6 +7,8 @@
 /* Test result of created folder id */
 extern EwsFolderId *folder_id;
 
+void set_oof_settings_test_run ();
+void get_oof_settings_test_run ();
 void connection_tests_run ();
 void op_tests_run ();
 void cuditem_tests_run ();
@@ -40,6 +42,8 @@ int main (int argc, char *argv[])
 	g_test_add_func ("/libews/autocompletion", autocompletion_tests_run);
 
 	g_test_add_func ("/libews/syncfolder", op_tests_run);
+	g_test_add_func ("/libews/setoofsettings", set_oof_settings_test_run);
+	g_test_add_func ("/libews/getoofsettings", get_oof_settings_test_run);
 
 	/* delete folder uses the data from create_folder test. */
 	g_test_add_func ("/libews/createfolder", createfolder_tests_run);
diff --git a/src/server/tests/test-set-oof-settings.c b/src/server/tests/test-set-oof-settings.c
new file mode 100644
index 0000000..23512ca
--- /dev/null
+++ b/src/server/tests/test-set-oof-settings.c
@@ -0,0 +1,119 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Authors : Punit Jain <jpunit suse com>
+ *
+ * Copyright (C) 1999-2011 Novell, Inc. (www.novell.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+
+/* API : e_ews_connection_set_oof_settings */
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <glib.h>
+#include <glib/gprintf.h>
+#include "utils.h"
+#include <e-ews-connection.h>
+#include <e-ews-message.h>
+
+void set_oof_settings_test_run ();
+static GMainLoop *main_loop;
+OOFSettings *oof_settings = NULL;
+
+static void
+set_arbit_values () {
+	time_t tm;
+	oof_settings = g_new0 (OOFSettings, 1);
+	oof_settings->state = g_strdup ("Enabled");
+	oof_settings->ext_aud = g_strdup ("All");
+	tm = time (NULL);
+	oof_settings->start_tm = tm - (24*60*60);
+	oof_settings->end_tm = tm + (24*60*60);
+	oof_settings->int_reply = g_strdup ("My Internal Reply");
+	oof_settings->ext_reply = g_strdup ("My External Reply");
+}
+
+static void
+set_oof_settings_cb (GObject *object, GAsyncResult *res, gpointer data)
+{
+	EEwsConnection *cnc = E_EWS_CONNECTION (object);
+	GError *error = NULL;
+
+	e_ews_connection_set_oof_settings_finish (cnc, res, &error);
+
+	if (error != NULL) {
+		g_warning ("Unable to set out of office settings: %s \n", error->message);
+		g_clear_error (&error);
+		goto quit;
+	}
+
+	g_print ("Success : Set out office successfully \n");
+
+quit:
+	g_main_loop_quit(main_loop);
+}
+
+static void
+op_test_set_oof_settings ()
+{
+	const gchar *username;
+	const gchar *password;
+	const gchar *uri, *email;
+	EEwsConnection *cnc;
+	GCancellable *cancellable;
+
+	cancellable = g_cancellable_new ();
+
+	util_get_login_info_from_env (&username, &password, &uri);
+	util_get_email_from_env (&email);
+
+	g_assert_cmpstr (username, !=, NULL);
+	g_assert_cmpstr (password, !=, NULL);
+	g_assert_cmpstr (uri, !=, NULL);
+	g_assert_cmpstr (email, !=, NULL);
+
+	cnc = e_ews_connection_new (uri, username, password, NULL, NULL, NULL);
+	g_assert (cnc != NULL);
+
+	e_ews_connection_set_mailbox (cnc, email);
+
+	set_arbit_values ();
+	e_ews_connection_set_oof_settings_start	(cnc, EWS_PRIORITY_MEDIUM,
+						 oof_settings,
+						 set_oof_settings_cb,
+						 cancellable, NULL);
+}
+
+static gboolean
+idle_cb (gpointer data)
+{
+	op_test_set_oof_settings ();
+	return FALSE;
+}
+
+void
+set_oof_settings_test_run ()
+{
+	g_type_init ();
+
+	main_loop = g_main_loop_new (NULL, TRUE);
+	g_idle_add ((GSourceFunc) idle_cb, NULL);
+	g_main_loop_run (main_loop);
+
+	/* terminate */
+	g_main_loop_unref (main_loop);
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]