[evolution-patches] Patch to handle "file://" uri in Mail-component.



Hi,

The attached patch implements handling of file:// uris in
mail-component.

When evolution is executed with a file it just ignores it, even though
it is a "MailDir" file, which it understands very well.  The attached
patch handles such file uris.  With this path, "evolution" can be the
default application to open such "MailDir" files.

Example uri:

"file:///home/foo/maildir/file;action=<view/compose>;mode=<edit/attached>"

where 
        "mode" is applicable only to "action=compose" and it is ignored
when
given with "action=view". 

action=compose: will open the message in the composer window, depending
on the mode parameter. If "mode=edit", the message will be opened like a
message in the drafts folder, will be attached otherwise.

Kindly let me know your comments/suggestions.

Thanks,

V. Varadhan
? .cvsignore
? Evolution-Mail-common.c
? Evolution-Mail-skels.c
? Evolution-Mail-stubs.c
? Evolution-Mail.h
? evolution-mail-2.4.schemas
? forward-patch.diff
? handle-file-uri.patch
? mail-component-gptrarray.c
? mail.error
? default/zh_CN/Makefile
? default/zh_CN/Makefile.in
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/mail/ChangeLog,v
retrieving revision 1.3660
diff -u -p -r1.3660 ChangeLog
--- ChangeLog	25 Jul 2005 04:23:40 -0000	1.3660
+++ ChangeLog	26 Jul 2005 07:36:49 -0000
@@ -1,3 +1,13 @@
+2005-07-26  Veerapuram Varadhan <vvaradhan novell com>
+
+	* mail-component.c (impl_handleURI): Support "file:" uri.
+	(handleuri_got_file): if we get a "file" uri, handle it
+	according to the parameters that are passed. By default, we
+	will open a composer window and attach the file pointed to 
+	by the URI.
+
+	* GNOME_Evolution_Mail.server.in.in: Support "file" uri.
+	
 2005-07-25  Srinivasa Ragavan <sragavan novell com>
 
 	* em-format-html-display.c: (efhd_init) (efhd_finalise) ()
Index: GNOME_Evolution_Mail.server.in.in
===================================================================
RCS file: /cvs/gnome/evolution/mail/GNOME_Evolution_Mail.server.in.in,v
retrieving revision 1.26
diff -u -p -r1.26 GNOME_Evolution_Mail.server.in.in
--- GNOME_Evolution_Mail.server.in.in	18 Jun 2005 11:32:35 -0000	1.26
+++ GNOME_Evolution_Mail.server.in.in	26 Jul 2005 07:36:49 -0000
@@ -42,6 +42,7 @@
     <oaf_attribute name="evolution:uri_schemas" type="stringv">
       <item value="mailto"/>
       <item value="email"/>
+      <item value="file"/>
     </oaf_attribute>
   </oaf_server>
 
Index: mail-component.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-component.c,v
retrieving revision 1.122
diff -u -p -r1.122 mail-component.c
--- mail-component.c	10 Jul 2005 10:03:56 -0000	1.122
+++ mail-component.c	26 Jul 2005 07:36:49 -0000
@@ -79,10 +79,13 @@
 
 #include <camel/camel-file-utils.h>
 #include <camel/camel-vtrash-folder.h>
+#include <camel/camel-stream-fs.h>
 
 #include <bonobo/bonobo-control.h>
 #include <bonobo/bonobo-widget.h>
 
+#include <libedataserver/e-url.h>
+
 #define d(x) 
 
 static void create_local_item_cb(EUserCreatableItemsHandler *handler, const char *item_type_name, void *data);
@@ -819,7 +822,7 @@ static void
 handleuri_got_folder(char *uri, CamelFolder *folder, void *data)
 {
 	CamelURL *url = data;
-	EMMessageBrowser *emmb;
+ 	EMMessageBrowser *emmb;
 
 	if (folder != NULL) {
 		const char *reply = camel_url_get_param(url, "reply");
@@ -873,8 +876,103 @@ handleuri_got_folder(char *uri, CamelFol
 }
 
 static void
+handleuri_got_file (MailComponent* mc, const char* uri)
+{
+	char* name = NULL;
+	const char* compose_mode = NULL;
+	const char* action = NULL;
+	EUri* euri = NULL;
+
+	EMsgComposer* composer = NULL;
+
+	/* For ex: 
+	   file:///home/foo/mails/bar[;action=<view/compose>[mode=<edit/attached>]] 
+	*/
+
+	euri = e_uri_new(uri);
+
+	action = e_uri_get_param(euri, "action");
+	compose_mode = e_uri_get_param(euri, "mode");
+
+	if (action && ((compose_mode && !strcmp(compose_mode, "edit"))
+		    || !strcmp(action, "view"))) {
+		CamelStream* msg_stream = NULL;
+		CamelMimeMessage* message;
+
+		if ((name = euri->path) == NULL)
+			return;
+		
+		if ((msg_stream = camel_stream_fs_new_with_name(name, O_RDONLY, 0)) == NULL)
+			return;
+		
+		message = camel_mime_message_new();
+		if (camel_data_wrapper_construct_from_stream((CamelDataWrapper *)message, msg_stream) == -1) {
+			camel_object_unref((CamelObject *)msg_stream);
+			camel_object_unref((CamelObject *)message);
+			return;
+		}
+
+		if (!strcmp(action, "view")) {
+			EMMessageBrowser *emmb;
+			CamelFolder* folder;
+			CamelException* ex;
+			const char* folder_uri;
+			char* appended_uid;
+
+			ex = camel_exception_new();
+			
+			emmb = (EMMessageBrowser *)em_message_browser_window_new();
+			
+			/* FIXME: session needs to be passed easier than this */
+			em_format_set_session((EMFormat *)((EMFolderView *)emmb)->preview, session);
+			
+			folder = mail_component_get_folder(mc, MAIL_COMPONENT_FOLDER_LOCAL_INBOX);
+			folder_uri = mail_component_get_folder_uri(mc, MAIL_COMPONENT_FOLDER_LOCAL_INBOX);
+			if (folder && folder_uri) {
+				/* FIXME: Should we need to delete this message 
+				   once the message brower window is closed?
+				*/
+				camel_folder_append_message(folder, message, NULL, &appended_uid, ex);
+				em_folder_view_set_folder((EMFolderView *)emmb, folder, folder_uri);
+				em_folder_view_set_message((EMFolderView *)emmb, appended_uid, FALSE);
+				gtk_widget_show(emmb->window);
+			} 
+			camel_exception_free (ex);
+		} else if (!strcmp (action, "compose")){ 
+			/* FIXME: Should check for "mbox" files */
+			em_utils_edit_message(message);
+		}
+		    
+		camel_object_unref((CamelObject *)msg_stream);
+		camel_object_unref((CamelObject *)message);
+	} else { 
+
+		/* Defaults to "action=compose; mode=attach" */		   
+		GSList* file_names_list = NULL;
+		CamelMimePart* part = NULL;
+		
+		file_names_list = g_slist_append(file_names_list, euri->path);
+		
+		composer = e_msg_composer_new ();
+		while (file_names_list) {
+			part = e_msg_composer_add_inline_image_from_file(composer,
+									 file_names_list->data);
+			if (part)
+				e_msg_composer_attach(composer, part);
+			camel_object_unref(part);
+			file_names_list = g_slist_next (file_names_list);
+		}
+		g_slist_free(file_names_list);
+		e_msg_composer_set_headers (composer, NULL, NULL, NULL, NULL, "");
+		gtk_widget_show ((GtkWidget*)composer);
+	}
+	e_uri_free(euri);
+}
+
+static void
 impl_handleURI (PortableServer_Servant servant, const char *uri, CORBA_Environment *ev)
 {
+	MailComponent *mail_component = MAIL_COMPONENT (bonobo_object_from_servant (servant));
 	if (!strncmp (uri, "mailto:";, 7)) {
 		if (!em_utils_check_user_can_send_mail(NULL))
 			return;
@@ -892,6 +990,8 @@ impl_handleURI (PortableServer_Servant s
 			g_warning("email uri's must include a uid parameter");
 			camel_url_free(url);
 		}
+	} else if (!strncmp(uri, "file:", 5)) {
+		handleuri_got_file (mail_component, uri);
 	}
 }
 


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