Re: [evolution-patches] Patch for the receipt bounty (#127534) (fwd)




Horrah.

Ok, i've committed this ... I made some changes, particularly to the way the message is processed, and a few string changes to make it a little neater.  I've attached the final version below with my changes as well.

Pity it couldn't have been done as a plugin, but i guess that's the way things go sometimes.

Thanks for all your work and patience!

Michael

On Wed, 2005-04-06 at 18:26 +0200, ERDI Gergo wrote:

-- 
    .--= ULLA! =---------------------.   `We are not here to give users what
    \     http://cactus.rulez.org     \   they want'  -- RMS, at GUADEC 2001
     `---= cactus cactus rulez org =---'
Question Authority before it questions you ...

---------- Forwarded message ----------
Date: Tue, 5 Apr 2005 21:30:38 +0200 (CEST)
From: ERDI Gergo <cactus cactus rulez org>
To: evolution-hackers lists ximian com
Subject: Re: [evolution-patches] Patch for the receipt bounty (#127534)

On Mon, 4 Apr 2005, Not Zed wrote:

> Could you please address these issues, then send the final patch to the
> list?  I don't see any reason why it shouldn't go in after that
> (although, i will actually have to test that it works first ;-).

OK, here it is.

-- 
    .--= ULLA! =---------------------.   `We are not here to give users what
    \     http://cactus.rulez.org     \   they want'  -- RMS, at GUADEC 2001
     `---= cactus cactus rulez org =---'
I know KUNG FU, KARATE and 47 other dangerous words.
Index: composer/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/composer/ChangeLog,v
retrieving revision 1.686
diff -u -p -r1.686 ChangeLog
--- composer/ChangeLog	17 Mar 2005 02:12:24 -0000	1.686
+++ composer/ChangeLog	8 Apr 2005 04:31:43 -0000
@@ -1,3 +1,7 @@
+2005-04-05  ERDI Gergo  <cactus cactus rulez org>
+
+	* e-msg-composer.c: implement read-receipt functionality.
+
 2005-03-16  Not Zed  <NotZed Ximian com>
 
 	** See bug #73347
Index: composer/e-msg-composer.c
===================================================================
RCS file: /cvs/gnome/evolution/composer/e-msg-composer.c,v
retrieving revision 1.501
diff -u -p -r1.501 e-msg-composer.c
--- composer/e-msg-composer.c	15 Mar 2005 21:04:24 -0000	1.501
+++ composer/e-msg-composer.c	8 Apr 2005 04:31:44 -0000
@@ -463,6 +463,15 @@ build_message (EMsgComposer *composer, g
 					 composer->extra_hdr_names->pdata[i],
 					 composer->extra_hdr_values->pdata[i]);
 	}
+
+	/* Message Disposition Notification */
+	if (composer->request_receipt) {
+		char *mdn_address = hdrs->account->id->reply_to;
+		if (!mdn_address || !*mdn_address)
+			mdn_address = hdrs->account->id->address;
+		
+		camel_medium_add_header (CAMEL_MEDIUM (new), "Disposition-Notification-To", mdn_address);
+	}
 	
 	if (composer->mime_body) {
 		plain_encoding = CAMEL_TRANSFER_ENCODING_7BIT;
@@ -525,7 +534,7 @@ build_message (EMsgComposer *composer, g
 			CORBA_exception_init (&ev);
 			GNOME_GtkHTML_Editor_Engine_runCommand (composer->editor_engine, "save-data-on", &ev);
 		}
-		data = get_text (composer->persist_stream_interface, "text/html");		
+		data = get_text (composer->persist_stream_interface, "text/html");
 		if (save_html_object_data) {
 			GNOME_GtkHTML_Editor_Engine_runCommand (composer->editor_engine, "save-data-off", &ev);
 			CORBA_exception_free (&ev);
@@ -1928,6 +1937,19 @@ menu_view_bcc_cb (BonoboUIComponent     
 }
 
 static void
+menu_insert_receipt_cb (BonoboUIComponent           *component,
+			const char                  *path,
+			Bonobo_UIComponent_EventType type,
+			const char                  *state,
+			gpointer                     user_data)
+{
+	if (type != Bonobo_UIComponent_STATE_CHANGED)
+		return;
+	
+	e_msg_composer_set_request_receipt (E_MSG_COMPOSER (user_data), atoi (state));
+}
+
+static void
 menu_changed_charset_cb (BonoboUIComponent           *component,
 			 const char                  *path,
 			 Bonobo_UIComponent_EventType type,
@@ -2228,6 +2250,14 @@ setup_ui (EMsgComposer *composer)
 	bonobo_ui_component_add_listener (
 		composer->uic, "ViewBCC",
 		menu_view_bcc_cb, composer);
+
+	/* Insert/Request Receipt */
+	bonobo_ui_component_set_prop (
+		composer->uic, "/commands/RequestReceipt",
+		"state", composer->request_receipt ? "1" : "0", NULL);
+	bonobo_ui_component_add_listener (
+		composer->uic, "RequestReceipt",
+		menu_insert_receipt_cb, composer);
 	
 	/* Security -> PGP Sign */
 	bonobo_ui_component_set_prop (
@@ -5358,6 +5388,7 @@ e_msg_composer_set_view_cc (EMsgComposer
 }
 
 
+
 /**
  * e_msg_composer_get_view_bcc:
  * @composer: A message composer widget
@@ -5406,6 +5437,47 @@ e_msg_composer_set_view_bcc (EMsgCompose
 	e_msg_composer_hdrs_set_visible (E_MSG_COMPOSER_HDRS (composer->hdrs),
 					 e_msg_composer_get_visible_flags (composer));
 }
+
+
+
+/**
+ * e_msg_composer_get_request_receipt
+ * @composer: A message composer widget
+ * 
+ * Get the status of the "Request receipt" flag.
+ * 
+ * Return value: The status of the "Request receipt" flag.
+ **/
+gboolean
+e_msg_composer_get_request_receipt (EMsgComposer *composer)
+{
+	g_return_val_if_fail (E_IS_MSG_COMPOSER (composer), FALSE);
+	
+	return composer->request_receipt;
+}
+
+
+/**
+ * e_msg_composer_set_request_receipt:
+ * @composer: A message composer widget
+ * @state: whether to request or not a receipt
+ *
+ * If set, a message delivery notification request will be sent to the recipient
+ */
+void
+e_msg_composer_set_request_receipt (EMsgComposer *composer, gboolean request_receipt)
+{
+	g_return_if_fail (E_IS_MSG_COMPOSER (composer));
+	
+	if ((composer->request_receipt && request_receipt) ||
+	    (!composer->request_receipt && !request_receipt))
+		return;
+	
+	composer->request_receipt = request_receipt;
+	bonobo_ui_component_set_prop (composer->uic, "/commands/RequestReceipt",
+				      "state", composer->request_receipt ? "1" : "0", NULL);
+}
+
 
 
 EDestination **
Index: composer/e-msg-composer.h
===================================================================
RCS file: /cvs/gnome/evolution/composer/e-msg-composer.h,v
retrieving revision 1.91
diff -u -p -r1.91 e-msg-composer.h
--- composer/e-msg-composer.h	27 Jul 2004 16:52:17 -0000	1.91
+++ composer/e-msg-composer.h	8 Apr 2005 04:31:44 -0000
@@ -101,6 +101,7 @@ struct _EMsgComposer {
 	guint32 view_bcc               : 1;
 	guint32 view_cc                : 1;
 	guint32 view_subject           : 1;
+	guint32 request_receipt        : 1;
 	guint32 has_changed            : 1;
 	guint32 autosaved              : 1;
 	
@@ -191,6 +192,10 @@ void                     e_msg_composer_
 gboolean                 e_msg_composer_get_view_bcc                     (EMsgComposer      *composer);
 void                     e_msg_composer_set_view_bcc                     (EMsgComposer      *composer,
 									  gboolean           view_bcc);
+
+gboolean                 e_msg_composer_get_request_receipt              (EMsgComposer *composer);
+void                     e_msg_composer_set_request_receipt              (EMsgComposer *composer,
+									  gboolean      request_receipt);
 
 EDestination           **e_msg_composer_get_recipients                   (EMsgComposer *composer);
 EDestination           **e_msg_composer_get_to                           (EMsgComposer *composer);
Index: e-util/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/e-util/ChangeLog,v
retrieving revision 1.530
diff -u -p -r1.530 ChangeLog
--- e-util/ChangeLog	16 Mar 2005 06:50:11 -0000	1.530
+++ e-util/ChangeLog	8 Apr 2005 04:31:45 -0000
@@ -365,6 +365,10 @@
 	* e-icon-factory.c (icon_foreach_remove): We must return TRUE here
 	so that things actually get removed from the list
 
+2004-08-07  ERDI Gergo  <cactus cactus rulez org>
+
+	* e-account.h: Added new receipt_policy field to services
+
 2004-08-05  Rodrigo Moya <rodrigo novell com>
 
 	* e-icon-factory.c (e_icon_factory_init): connect to "changed"
Index: e-util/e-account.c
===================================================================
RCS file: /cvs/gnome/evolution/e-util/e-account.c,v
retrieving revision 1.14
diff -u -p -r1.14 e-account.c
--- e-util/e-account.c	4 Mar 2005 03:07:18 -0000	1.14
+++ e-util/e-account.c	8 Apr 2005 04:31:45 -0000
@@ -265,6 +265,56 @@ xml_set_prop (xmlNodePtr node, const cha
 	return res;
 }
 
+static EAccountReceiptPolicy
+str_to_receipt_policy (const char *str)
+{
+	if (!strcmp (str, "ask"))
+		return E_ACCOUNT_RECEIPT_ASK;
+	if (!strcmp (str, "always"))
+		return E_ACCOUNT_RECEIPT_ALWAYS;
+
+	return E_ACCOUNT_RECEIPT_NEVER;
+}
+
+static char*
+receipt_policy_to_str (EAccountReceiptPolicy val)
+{
+	char *ret = 0;
+	
+	switch (val) {
+	case E_ACCOUNT_RECEIPT_NEVER:
+		ret = "never";
+		break;
+	case E_ACCOUNT_RECEIPT_ASK:
+		ret = "ask";
+		break;
+	case E_ACCOUNT_RECEIPT_ALWAYS:
+		ret = "always";
+		break;
+	}
+
+	return ret;
+}
+
+static gboolean
+xml_set_receipt_policy (xmlNodePtr node, const char *name, EAccountReceiptPolicy *val)
+{
+	EAccountReceiptPolicy new_val;
+	char *buf;
+
+	if ((buf = xmlGetProp (node, name))) {
+		new_val = str_to_receipt_policy (buf);
+		xmlFree (buf);
+
+		if (new_val != *val) {
+			*val = new_val;
+			return TRUE;
+		}
+	}
+
+	return FALSE;
+}
+
 static gboolean
 xml_set_content (xmlNodePtr node, char **val)
 {
@@ -387,7 +437,7 @@ e_account_set_from_xml (EAccount *accoun
 	
 	changed |= xml_set_prop (node, "name", &account->name);
 	changed |= xml_set_bool (node, "enabled", &account->enabled);
-
+	
 	for (node = node->children; node; node = node->next) {
 		if (!strcmp (node->name, "identity")) {
 			changed |= xml_set_identity (node, account->id);
@@ -405,6 +455,8 @@ e_account_set_from_xml (EAccount *accoun
 		} else if (!strcmp (node->name, "auto-bcc")) {
 			changed |= xml_set_bool (node, "always", &account->always_bcc);
 			changed |= xml_set_content (node, &account->bcc_addrs);
+		} else if (!strcmp (node->name, "receipt-policy")) {
+			changed |= xml_set_receipt_policy (node, "policy", &account->receipt_policy);
 		} else if (!strcmp (node->name, "pgp")) {
 			changed |= xml_set_bool (node, "encrypt-to-self", &account->pgp_encrypt_to_self);
 			changed |= xml_set_bool (node, "always-trust", &account->pgp_always_trust);
@@ -494,6 +546,8 @@ e_account_import (EAccount *dest, EAccou
 	g_free (dest->bcc_addrs);
 	dest->bcc_addrs = g_strdup (src->bcc_addrs);
 	
+	dest->receipt_policy = src->receipt_policy;
+	
 	g_free (dest->pgp_key);
 	dest->pgp_key = g_strdup (src->pgp_key);
 	dest->pgp_encrypt_to_self = src->pgp_encrypt_to_self;
@@ -578,6 +632,9 @@ e_account_to_xml (EAccount *account)
 	if (account->bcc_addrs)
 		xmlNewTextChild (node, NULL, "recipients", account->bcc_addrs);
 
+	node = xmlNewChild (root, NULL, "receipt-policy", NULL);
+	xmlSetProp (node, "policy", receipt_policy_to_str (account->receipt_policy));
+	
 	node = xmlNewChild (root, NULL, "pgp", NULL);
 	xmlSetProp (node, "encrypt-to-self", account->pgp_encrypt_to_self ? "true" : "false");
 	xmlSetProp (node, "always-trust", account->pgp_always_trust ? "true" : "false");
@@ -708,6 +765,8 @@ static struct _account_info {
 	{ /* E_ACCOUNT_BCC_ALWAYS */ 0, TYPE_BOOL, G_STRUCT_OFFSET(EAccount, always_bcc) },
 	{ /* E_ACCOUNT_BCC_ADDRS */ 0, TYPE_STRING, G_STRUCT_OFFSET(EAccount, bcc_addrs) },
 
+	{ /* E_ACCOUNT_RECEIPT_POLICY */ 0, TYPE_INT, G_STRUCT_OFFSET(EAccount, receipt_policy) },
+	
 	{ /* E_ACCOUNT_PGP_KEY */ 0, TYPE_STRING, G_STRUCT_OFFSET(EAccount, pgp_key) },
 	{ /* E_ACCOUNT_PGP_ENCRYPT_TO_SELF */ 0, TYPE_BOOL, G_STRUCT_OFFSET(EAccount, pgp_encrypt_to_self) },
 	{ /* E_ACCOUNT_PGP_ALWAYS_SIGN */ 0, TYPE_BOOL, G_STRUCT_OFFSET(EAccount, pgp_always_sign) },
Index: e-util/e-account.h
===================================================================
RCS file: /cvs/gnome/evolution/e-util/e-account.h,v
retrieving revision 1.8
diff -u -p -r1.8 e-account.h
--- e-util/e-account.h	20 Sep 2004 05:59:54 -0000	1.8
+++ e-util/e-account.h	8 Apr 2005 04:31:45 -0000
@@ -55,6 +55,8 @@ typedef enum _e_account_item_t {
 	E_ACCOUNT_BCC_ALWAYS,
 	E_ACCOUNT_BCC_ADDRS,
 
+	E_ACCOUNT_RECEIPT_POLICY,
+	
 	E_ACCOUNT_PGP_KEY,
 	E_ACCOUNT_PGP_ENCRYPT_TO_SELF,
 	E_ACCOUNT_PGP_ALWAYS_SIGN,
@@ -82,6 +84,12 @@ typedef struct _EAccountIdentity {
 	char *sig_uid;
 } EAccountIdentity;
 
+typedef enum _EAccountReceiptPolicy {
+	E_ACCOUNT_RECEIPT_NEVER,
+	E_ACCOUNT_RECEIPT_ASK,
+	E_ACCOUNT_RECEIPT_ALWAYS
+} EAccountReceiptPolicy;
+
 typedef struct _EAccountService {
 	char *url;
 	gboolean keep_on_server;
@@ -108,6 +116,8 @@ typedef struct _EAccount {
 	char *cc_addrs;
 	gboolean always_bcc;
 	char *bcc_addrs;
+
+	EAccountReceiptPolicy receipt_policy;
 
 	char *pgp_key;
 	gboolean pgp_encrypt_to_self;
Index: mail/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/mail/ChangeLog,v
retrieving revision 1.3616
diff -u -p -r1.3616 ChangeLog
--- mail/ChangeLog	6 Apr 2005 05:39:08 -0000	1.3616
+++ mail/ChangeLog	8 Apr 2005 04:31:49 -0000
@@ -1,3 +1,28 @@
+2005-04-08  Not Zed  <NotZed Ximian com>
+
+	* em-composer-utils.c (em_utils_ask_receipt): removed.
+	(em_utils_handle_receipt): asynchronously load message if none is
+	supplied.
+
+	* em-folder-view.c (emfv_set_seen): pass message in.
+
+	* em-composer-utils.c (em_utils_ask_receipt): strip leading lwsp
+	on the disposition address.
+	(em_utils_ask_receipt): added a comment about which rfc.
+	(em_utils_handle_receipt): merged ask_receipt into here.  Changed
+	api to take a message instead, so we don't have to load the
+	message every time.  Also only set receipt-handled if we have a
+	receipt requested in the first place.
+
+2005-04-05  ERDI Gergo  <cactus cactus rulez org>
+
+	* mail-errors.xml: Added new dialog for receipt requests
+
+	* em-composer-utils.c (em_utils_guess_account): Made guess_account
+	public, to be callable from em-folder-view
+	(em_utils_send_receipt): New function to send an RFC
+	2298-compliant message delivery notification
+
 2005-04-05  Not Zed  <NotZed Ximian com>
 
 	** See bug #74320
Index: mail/em-account-editor.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/em-account-editor.c,v
retrieving revision 1.24
diff -u -p -r1.24 em-account-editor.c
--- mail/em-account-editor.c	2 Mar 2005 05:23:45 -0000	1.24
+++ mail/em-account-editor.c	8 Apr 2005 04:31:50 -0000
@@ -724,6 +724,64 @@ emae_setup_signatures(EMAccountEditor *e
 }
 
 static void
+emae_receipt_policy_changed(GtkComboBox *dropdown, EMAccountEditor *emae)
+{
+	int id = gtk_combo_box_get_active(dropdown);
+	GtkTreeModel *model;
+	GtkTreeIter iter;
+	EAccountReceiptPolicy policy;
+
+	if (id != -1) {
+		model = gtk_combo_box_get_model(dropdown);
+		if (gtk_tree_model_iter_nth_child(model, &iter, NULL, id)) {
+			gtk_tree_model_get(model, &iter, 1, &policy, -1);
+			e_account_set_int (emae->account, E_ACCOUNT_RECEIPT_POLICY, policy);
+		}
+	}
+
+}
+
+static GtkWidget *
+emae_setup_receipt_policy (EMAccountEditor *emae, GladeXML *xml)
+{
+	GtkComboBox *dropdown = (GtkComboBox *)glade_xml_get_widget(xml, "receipt_policy_dropdown");
+	GtkListStore *store;
+	int i = 0, active = 0;
+	GtkTreeIter iter;
+	EAccountReceiptPolicy current = emae->account->receipt_policy;
+	static struct {
+		EAccountReceiptPolicy policy;
+		char *label;			
+	} receipt_policies[] = {
+		{ E_ACCOUNT_RECEIPT_NEVER,  N_("Never") },
+		{ E_ACCOUNT_RECEIPT_ALWAYS, N_("Always") },
+		{ E_ACCOUNT_RECEIPT_ASK,    N_("Ask for each message") }
+	};
+
+	gtk_widget_show((GtkWidget *)dropdown);
+
+	store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
+
+	for (i = 0; i < 3; ++i) {
+		gtk_list_store_append (store, &iter);
+		gtk_list_store_set (store, &iter,
+				    0, _(receipt_policies[i].label),
+				    1, receipt_policies[i].policy,
+				    -1);
+		if (current == receipt_policies[i].policy)
+			active = i;		
+	}
+	
+	gtk_combo_box_set_model(dropdown, (GtkTreeModel *)store);
+	gtk_combo_box_set_active(dropdown, active);
+
+	g_signal_connect(dropdown, "changed", G_CALLBACK(emae_receipt_policy_changed), emae);
+	gtk_widget_set_sensitive((GtkWidget *)dropdown, e_account_writable(emae->account, E_ACCOUNT_RECEIPT_POLICY));
+
+	return (GtkWidget *)dropdown;
+}
+
+static void
 emae_account_entry_changed(GtkEntry *entry, EMAccountEditor *emae)
 {
 	int item = GPOINTER_TO_INT(g_object_get_data((GObject *)entry, "account-item"));
@@ -2081,6 +2139,9 @@ emae_defaults_page(EConfig *ec, EConfigI
 	gtk_widget_set_sensitive((GtkWidget *)gui->restore_folders_button,
 				 e_account_writable(emae->account, E_ACCOUNT_SENT_FOLDER_URI)
 				 || e_account_writable(emae->account, E_ACCOUNT_DRAFTS_FOLDER_URI));
+
+	/* Receipt policy */
+	emae_setup_receipt_policy (emae, xml);
 	
 	w = glade_xml_get_widget(xml, item->label);
 	gtk_notebook_append_page((GtkNotebook *)parent, w, gtk_label_new(_("Defaults")));
Index: mail/em-composer-utils.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/em-composer-utils.c,v
retrieving revision 1.34
diff -u -p -r1.34 em-composer-utils.c
--- mail/em-composer-utils.c	4 Mar 2005 03:15:37 -0000	1.34
+++ mail/em-composer-utils.c	8 Apr 2005 04:31:50 -0000
@@ -50,9 +50,10 @@
 #include "e-util/e-account-list.h"
 
 #include <camel/camel-string-utils.h>
+#include <camel/camel-stream-mem.h>
 #include <camel/camel-nntp-address.h>
 
-static EAccount *guess_account (CamelMimeMessage *message, CamelFolder *folder);
+static EAccount * guess_account (CamelMimeMessage *message, CamelFolder *folder);
 
 struct emcs_t {
 	unsigned int ref_count;
@@ -190,6 +191,7 @@ composer_send_queued_cb (CamelFolder *fo
 		if (emcs && emcs->folder) {
 			/* set any replied flags etc */
 			camel_folder_set_message_flags (emcs->folder, emcs->uid, emcs->flags, emcs->set);
+			camel_folder_set_message_user_flag (emcs->folder, emcs->uid, "receipt-handled", TRUE);
 			camel_object_unref (emcs->folder);
 			emcs->folder = NULL;
 			g_free (emcs->uid);
@@ -1064,6 +1066,191 @@ em_utils_redirect_message_by_uid (CamelF
 	g_return_if_fail (uid != NULL);
 	
 	mail_get_message (folder, uid, redirect_msg, NULL, mail_thread_new);
+}
+
+static void
+emu_handle_receipt_message(CamelFolder *folder, const char *uid, CamelMimeMessage *msg, void *data)
+{
+	if (msg)
+		em_utils_handle_receipt(folder, uid, msg);
+}
+
+/* Message disposition notifications, rfc 2298 */
+void
+em_utils_handle_receipt (CamelFolder *folder, const char *uid, CamelMimeMessage *msg)
+{
+	EAccount *account;
+	const char *addr;
+	CamelMessageInfo *info;
+
+	info = camel_folder_get_message_info(folder, uid);
+	if (info == NULL)
+		return;
+
+	if (camel_message_info_user_flag(info, "receipt-handled")) {
+		camel_message_info_free(info);
+		return;
+	}
+
+	if (msg == NULL) {
+		mail_get_message(folder, uid, emu_handle_receipt_message, NULL, mail_thread_new);
+		camel_message_info_free(info);
+		return;
+	}
+
+	if ( (addr = camel_medium_get_header((CamelMedium *)msg, "Disposition-Notification-To")) == NULL) {
+		camel_message_info_free(info);
+		return;
+	}
+
+	camel_message_info_set_user_flag(info, "receipt-handled", TRUE);
+	camel_message_info_free(info);
+	
+	account = guess_account(msg, folder);
+
+	/* TODO: should probably decode/format the address, it could be in rfc2047 format */
+	if (addr == NULL) {
+		addr = "";
+	} else {
+		while (camel_mime_is_lwsp(*addr))
+			addr++;
+	}
+	
+	if (account->receipt_policy == E_ACCOUNT_RECEIPT_ALWAYS
+	    || (account->receipt_policy == E_ACCOUNT_RECEIPT_ASK
+		&& e_error_run (NULL, "mail:ask-receipt", addr, camel_mime_message_get_subject(msg)) == GTK_RESPONSE_YES))
+		em_utils_send_receipt(folder, msg);
+}
+
+static void
+em_utils_receipt_done (CamelFolder *folder, CamelMimeMessage *msg, CamelMessageInfo *info,
+		       int queued, const char *appended_uid, void *data)
+{
+	camel_message_info_free (info);
+	mail_send ();
+}
+
+
+void
+em_utils_send_receipt (CamelFolder *folder, CamelMimeMessage *message)
+{
+	/* See RFC #2298 for a description of message receipts */
+
+	EAccount *account = guess_account (message, folder);
+
+	CamelMimeMessage *receipt = camel_mime_message_new ();
+	CamelMultipart *body = camel_multipart_new ();
+	CamelMimePart *part;
+	CamelDataWrapper *receipt_text, *receipt_data;
+	CamelContentType *type;
+	CamelInternetAddress *addr;
+	CamelStream *stream;	
+	CamelFolder *out_folder;
+	CamelMessageInfo *info;
+	const char *message_id = camel_medium_get_header (CAMEL_MEDIUM (message), "Message-ID");
+	const char *message_date = camel_medium_get_header (CAMEL_MEDIUM (message), "Date");
+	const char *message_subject = camel_mime_message_get_subject (message);
+	const char *receipt_address = camel_medium_get_header (CAMEL_MEDIUM (message), "Disposition-Notification-To");
+	char *fake_msgid;
+	char *hostname;
+	char *self_address, *receipt_subject;
+	char *ua, *recipient;
+
+	if (!receipt_address)
+		return;
+	
+	/* Collect information for the receipt */
+
+	/* We use camel_header_msgid_generate () to get a canonical
+	 * hostname, then skip the part leading to '@' */
+	fake_msgid = camel_header_msgid_generate ();
+	for (hostname = fake_msgid; hostname && *hostname != '@'; ++hostname);
+	++hostname;
+
+	self_address = account->id->address;
+
+	if (!message_id)
+		message_id = "";
+	if (!message_date)
+		message_date ="";
+	
+	/* Create toplevel container */
+	camel_data_wrapper_set_mime_type (CAMEL_DATA_WRAPPER (body),
+					  "multipart/report;"
+					  "report-type=\"disposition-notification\"");
+	camel_multipart_set_boundary (body, NULL);	
+	
+	/* Create textual receipt */
+	receipt_text = camel_data_wrapper_new ();
+	type = camel_content_type_new ("text", "plain");
+	camel_content_type_set_param (type, "format", "flowed");
+	camel_data_wrapper_set_mime_type_field (receipt_text, type);
+	camel_content_type_unref (type);
+	stream = camel_stream_mem_new ();
+	camel_stream_printf (stream,
+			     "Your message to %s about \"%s\" on %s has been read.",
+			     self_address, message_subject, message_date);
+	camel_data_wrapper_construct_from_stream (receipt_text, stream);
+	camel_object_unref (stream);
+	
+	part = camel_mime_part_new ();
+	camel_medium_set_content_object (CAMEL_MEDIUM (part), receipt_text);
+	camel_object_unref (receipt_text);
+	camel_multipart_add_part (body, part);
+	camel_object_unref (part);	
+	
+	/* Create the machine-readable receipt */
+	receipt_data = camel_data_wrapper_new ();
+	type = camel_content_type_new ("message", "disposition-notification");
+	camel_data_wrapper_set_mime_type_field (receipt_data, type);
+	camel_content_type_unref (type);
+	stream = camel_stream_mem_new ();
+	part = camel_mime_part_new ();
+
+	ua = g_strdup_printf ("%s; %s", hostname, "Evolution " VERSION SUB_VERSION " " VERSION_COMMENT);
+	recipient = g_strdup_printf ("rfc822; %s", self_address);	
+
+	camel_medium_add_header (CAMEL_MEDIUM (part), "Reporting-UA", ua);
+	camel_medium_add_header (CAMEL_MEDIUM (part), "Final-Recipient", recipient);
+	camel_medium_add_header (CAMEL_MEDIUM (part), "Original-Message-ID", message_id);
+	camel_medium_add_header (CAMEL_MEDIUM (part), "Disposition", "manual-action/MDN-sent-manually; displayed");
+
+	g_free (ua);
+	g_free (recipient);
+	g_free (fake_msgid);
+	
+	camel_data_wrapper_construct_from_stream (receipt_data, stream);
+	camel_object_unref (stream);
+	camel_medium_set_content_object (CAMEL_MEDIUM (part), receipt_data);
+	camel_object_unref (receipt_data);
+	camel_multipart_add_part (body, part);
+	camel_object_unref (part);	
+	
+	/* Finish creating the message */
+	camel_medium_set_content_object (CAMEL_MEDIUM (receipt), CAMEL_DATA_WRAPPER (body));
+	camel_object_unref (body);
+	
+	receipt_subject = g_strdup_printf ("Delivery Notification for: \"%s\"", message_subject);
+	camel_mime_message_set_subject (receipt, receipt_subject);
+	g_free (receipt_subject);
+	
+	addr = camel_internet_address_new ();
+	camel_address_decode (CAMEL_ADDRESS (addr), self_address);
+	camel_mime_message_set_recipients (receipt, CAMEL_RECIPIENT_TYPE_TO, addr);
+	camel_object_unref (addr);
+	
+	addr = camel_internet_address_new ();
+	camel_address_decode (CAMEL_ADDRESS (addr), receipt_address);
+	camel_mime_message_set_from (receipt, addr);
+	camel_object_unref (addr);
+
+	camel_medium_set_header (CAMEL_MEDIUM (receipt), "Return-Path", "<>");
+
+	/* Send the receipt */
+	out_folder = mail_component_get_folder(NULL, MAIL_COMPONENT_FOLDER_OUTBOX);
+	info = camel_message_info_new (NULL);
+	camel_message_info_set_flags (info, CAMEL_MESSAGE_SEEN, CAMEL_MESSAGE_SEEN);
+	mail_append_mail (out_folder, receipt, info, em_utils_receipt_done, 0);
 }
 
 /* Replying to messages... */
Index: mail/em-composer-utils.h
===================================================================
RCS file: /cvs/gnome/evolution/mail/em-composer-utils.h,v
retrieving revision 1.7
diff -u -p -r1.7 em-composer-utils.h
--- mail/em-composer-utils.h	28 Jul 2004 14:38:50 -0000	1.7
+++ mail/em-composer-utils.h	8 Apr 2005 04:31:50 -0000
@@ -34,6 +34,7 @@ struct _CamelFolder;
 struct _CamelMimeMessage;
 struct _EMsgComposer;
 struct _EMFormat;
+struct _EAccount;
 
 void em_composer_utils_setup_callbacks (struct _EMsgComposer *composer, struct _CamelFolder *folder, const char *uid,
 					guint32 flags, guint32 set, struct _CamelFolder *drafts, const char *drafts_uid);
@@ -62,6 +63,9 @@ void em_utils_forward_messages (struct _
 
 void em_utils_redirect_message (struct _CamelMimeMessage *message);
 void em_utils_redirect_message_by_uid (struct _CamelFolder *folder, const char *uid);
+
+void em_utils_handle_receipt (struct _CamelFolder *folder, const char *uid, struct _CamelMimeMessage *msg);
+void em_utils_send_receipt   (struct _CamelFolder *folder, struct _CamelMimeMessage *message);
 
 enum {
 	REPLY_MODE_SENDER,
Index: mail/em-folder-view.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/em-folder-view.c,v
retrieving revision 1.113
diff -u -p -r1.113 em-folder-view.c
--- mail/em-folder-view.c	4 Apr 2005 20:53:21 -0000	1.113
+++ mail/em-folder-view.c	8 Apr 2005 04:31:51 -0000
@@ -64,6 +64,7 @@
 #include <bonobo/bonobo-ui-util.h>
 
 #include "widgets/misc/e-charset-picker.h"
+#include "widgets/misc/e-error.h"
 
 #include <e-util/e-dialog-utils.h>
 #include <e-util/e-icon-factory.h>
@@ -125,6 +126,8 @@ static void emfv_setting_setup(EMFolderV
 static void emfv_on_url_cb(GObject *emitter, const char *url, EMFolderView *emfv);
 static void emfv_on_url(EMFolderView *emfv, const char *uri, const char *nice_uri);
 
+static void emfv_set_seen (EMFolderView *emfv, const char *uid);
+
 static gboolean emfv_popup_menu (GtkWidget *widget);
 
 static const EMFolderViewEnable emfv_enable_map[];
@@ -441,6 +444,8 @@ em_folder_view_open_selected(EMFolderVie
 		em_folder_view_set_folder((EMFolderView *)emmb, emfv->folder, emfv->folder_uri);
 		em_folder_view_set_message((EMFolderView *)emmb, views->pdata[i], FALSE);
 		gtk_widget_show(emmb->window);
+		/* TODO: this loads the message twice (!) */
+		em_utils_handle_receipt (emfv->folder, uids->pdata[i], NULL);
 		g_free(views->pdata[i]);
 	}
 	g_ptr_array_free(views, TRUE);
@@ -2101,7 +2106,7 @@ do_mark_seen (gpointer user_data)
 	MessageList *list = emfv->list;
 	
 	if (mst->uid && list->cursor_uid && !strcmp (mst->uid, list->cursor_uid))
-		camel_folder_set_message_flags (emfv->folder, mst->uid, CAMEL_MESSAGE_SEEN, CAMEL_MESSAGE_SEEN);
+		emfv_set_seen (emfv, mst->uid);
 	
 	return FALSE;
 }
@@ -2147,7 +2152,7 @@ emfv_list_done_message_selected(CamelFol
 			emfv->priv->seen_id = g_timeout_add_full(G_PRIORITY_DEFAULT_IDLE, emfv->mark_seen_timeout,
 								 (GSourceFunc)do_mark_seen, mst, (GDestroyNotify)mst_free);
 		} else {
-			camel_folder_set_message_flags(emfv->folder, uid, CAMEL_MESSAGE_SEEN, CAMEL_MESSAGE_SEEN);
+			emfv_set_seen (emfv, uid);
 		}
 	}
 	
@@ -2419,6 +2424,18 @@ emfv_format_popup_event(EMFormatHTMLDisp
 		gtk_menu_popup(menu, NULL, NULL, NULL, NULL, event->button, event->time);
 
 	return TRUE;
+}
+
+static void
+emfv_set_seen(EMFolderView *emfv, const char *uid)
+{
+	guint32 old_flags = camel_folder_get_message_flags(emfv->folder, uid);
+
+	/* If we're setting the SEEN flag on a message, handle receipt requests */
+	if (!(old_flags & CAMEL_MESSAGE_SEEN))
+		em_utils_handle_receipt(emfv->folder, uid, (CamelMimeMessage *)((EMFormat *)emfv->preview)->message);
+
+	camel_folder_set_message_flags(emfv->folder, uid, CAMEL_MESSAGE_SEEN, CAMEL_MESSAGE_SEEN);
 }
 
 /* keep these two tables in sync */
Index: mail/mail-config.glade
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-config.glade,v
retrieving revision 1.158
diff -u -p -r1.158 mail-config.glade
--- mail/mail-config.glade	30 Mar 2005 07:57:45 -0000	1.158
+++ mail/mail-config.glade	8 Apr 2005 04:31:52 -0000
@@ -3056,6 +3056,120 @@ For example: &quot;Work&quot; or &quot;P
 	      <property name="fill">False</property>
 	    </packing>
 	  </child>
+
+	  <child>
+	    <widget class="GtkVBox" id="vbox205">
+	      <property name="visible">True</property>
+	      <property name="homogeneous">False</property>
+	      <property name="spacing">6</property>
+
+	      <child>
+		<widget class="GtkLabel" id="label578">
+		  <property name="visible">True</property>
+		  <property name="label" translatable="yes">&lt;span weight=&quot;bold&quot;&gt;Message Receipts&lt;/span&gt;</property>
+		  <property name="use_underline">False</property>
+		  <property name="use_markup">True</property>
+		  <property name="justify">GTK_JUSTIFY_LEFT</property>
+		  <property name="wrap">False</property>
+		  <property name="selectable">False</property>
+		  <property name="xalign">0</property>
+		  <property name="yalign">0.5</property>
+		  <property name="xpad">0</property>
+		  <property name="ypad">0</property>
+		</widget>
+		<packing>
+		  <property name="padding">0</property>
+		  <property name="expand">False</property>
+		  <property name="fill">False</property>
+		</packing>
+	      </child>
+
+	      <child>
+		<widget class="GtkHBox" id="hbox231">
+		  <property name="visible">True</property>
+		  <property name="homogeneous">False</property>
+		  <property name="spacing">12</property>
+
+		  <child>
+		    <widget class="GtkLabel" id="label581">
+		      <property name="visible">True</property>
+		      <property name="label" translatable="yes"></property>
+		      <property name="use_underline">False</property>
+		      <property name="use_markup">False</property>
+		      <property name="justify">GTK_JUSTIFY_LEFT</property>
+		      <property name="wrap">False</property>
+		      <property name="selectable">False</property>
+		      <property name="xalign">0.5</property>
+		      <property name="yalign">0.5</property>
+		      <property name="xpad">0</property>
+		      <property name="ypad">0</property>
+		    </widget>
+		    <packing>
+		      <property name="padding">0</property>
+		      <property name="expand">False</property>
+		      <property name="fill">False</property>
+		    </packing>
+		  </child>
+
+		  <child>
+		    <widget class="GtkHBox" id="hbox232">
+		      <property name="visible">True</property>
+		      <property name="homogeneous">False</property>
+		      <property name="spacing">12</property>
+
+		      <child>
+			<widget class="GtkLabel" id="label583">
+			  <property name="visible">True</property>
+			  <property name="label" translatable="yes">Send message receipts:</property>
+			  <property name="use_underline">False</property>
+			  <property name="use_markup">False</property>
+			  <property name="justify">GTK_JUSTIFY_LEFT</property>
+			  <property name="wrap">False</property>
+			  <property name="selectable">False</property>
+			  <property name="xalign">0.5</property>
+			  <property name="yalign">0.5</property>
+			  <property name="xpad">0</property>
+			  <property name="ypad">0</property>
+			</widget>
+			<packing>
+			  <property name="padding">0</property>
+			  <property name="expand">False</property>
+			  <property name="fill">False</property>
+			</packing>
+		      </child>
+
+		      <child>
+			<widget class="GtkComboBox" id="receipt_policy_dropdown">
+			  <property name="visible">True</property>
+			  <property name="items" translatable="yes"></property>
+			</widget>
+			<packing>
+			  <property name="padding">0</property>
+			  <property name="expand">True</property>
+			  <property name="fill">True</property>
+			</packing>
+		      </child>
+		    </widget>
+		    <packing>
+		      <property name="padding">0</property>
+		      <property name="expand">True</property>
+		      <property name="fill">True</property>
+		    </packing>
+		  </child>
+		</widget>
+		<packing>
+		  <property name="padding">0</property>
+		  <property name="expand">False</property>
+		  <property name="fill">False</property>
+		</packing>
+	      </child>
+	    </widget>
+	    <packing>
+	      <property name="padding">0</property>
+	      <property name="expand">True</property>
+	      <property name="fill">True</property>
+	    </packing>
+	  </child>
 	</widget>
 	<packing>
 	  <property name="tab_expand">False</property>
Index: mail/mail-errors.xml
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-errors.xml,v
retrieving revision 1.13
diff -u -p -r1.13 mail-errors.xml
--- mail/mail-errors.xml	1 Apr 2005 00:43:27 -0000	1.13
+++ mail/mail-errors.xml	8 Apr 2005 04:31:52 -0000
@@ -347,5 +347,13 @@ Please check your account settings and t
 </secondary>
 </error>
 
+  <error id="ask-receipt" type="question" default="GTK_RESPONSE_NO">
+    <title>Read receipt requested.</title>
+    <primary>Read receipt requested.</primary>
+    <secondary>A read receipt notification has been requested for &quot;{1}&quot;.  Send the reciept notification to {0}?</secondary>
+    <button stock="gtk-no" response="GTK_RESPONSE_NO"/>
+    <button stock="gtk-yes" label="Send Receipt" response="GTK_RESPONSE_YES"/>
+  </error>
+
 </error-list>
 
Index: mail/mail-errors.xml.h
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-errors.xml.h,v
retrieving revision 1.13
diff -u -p -r1.13 mail-errors.xml.h
--- mail/mail-errors.xml.h	1 Apr 2005 00:43:27 -0000	1.13
+++ mail/mail-errors.xml.h	8 Apr 2005 04:31:52 -0000
@@ -258,3 +258,10 @@ char *s = N_("Unable to connect to the G
 char *s = N_("\n"
 	"Please check your account settings and try again.\n"
 	"");
+/* mail:ask-receipt title */
+char *s = N_("Read receipt requested.");
+/* mail:ask-receipt primary */
+char *s = N_("Read receipt requested.");
+/* mail:ask-receipt secondary */
+char *s = N_("A read receipt notification has been requested for \"{1}\".  Send the reciept notification to {0}?");
+char *s = N_("Send Receipt");
Index: ui/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/ui/ChangeLog,v
retrieving revision 1.408
diff -u -p -r1.408 ChangeLog
--- ui/ChangeLog	14 Feb 2005 15:55:00 -0000	1.408
+++ ui/ChangeLog	8 Apr 2005 04:31:53 -0000
@@ -1,3 +1,13 @@
+2005-04-08  Not Zed  <NotZed Ximian com>
+
+	* evolution-message-composer.xml: change the label to "Request
+	read receipt".
+
+2004-03-31  ERDI Gergo  <cactus cactus rulez org>
+
+	* evolution-message-composer.xml: Added new menu item for
+	requesting message receipts when composing a new message
+
 2005-02-14  Rodney Dawes  <dobey novell com>
 
 	* evolution-mail-list.xml:
Index: ui/evolution-message-composer.xml
===================================================================
RCS file: /cvs/gnome/evolution/ui/evolution-message-composer.xml,v
retrieving revision 1.44
diff -u -p -r1.44 evolution-message-composer.xml
--- ui/evolution-message-composer.xml	4 Jan 2005 19:43:20 -0000	1.44
+++ ui/evolution-message-composer.xml	8 Apr 2005 04:31:53 -0000
@@ -31,6 +31,10 @@
 		pixtype="stock" pixname="gtk-delete"
 		_tip="Delete all but signature"/>
 
+		<cmd name="RequestReceipt" _label="Request read receipt"
+		     _tip="Check to get delivery notification when your message is read"
+		     type="toggle" state="0"/>
+		
 		<cmd name="FormatHtml" _label="HT_ML" _tip="Send the mail in HTML format"
 		type="toggle" state="0"/> 
 		
@@ -132,6 +136,8 @@
 	                <menuitem name="FileAttach" verb=""
 	                _label="_Attachment..." pixtype="pixbuf"/>
                 	<placeholder name="Component"/>
+			<separator f="" name="emailcomposer"/>
+			<menuitem name="RequestReceipt" verb=""/>
                 </submenu>
 		
                 <submenu name="Security" _label="_Security">


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