aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2001-06-20 02:49:01 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2001-06-20 02:49:01 +0800
commitdddc124a9d32d349106803a04040a3edad2a3cbb (patch)
treefda6957a85330d2aeac5944521708c38b50f1ce6 /mail
parent85698a3ff51a20052acd2d3b521c76285753481d (diff)
downloadgsoc2013-evolution-dddc124a9d32d349106803a04040a3edad2a3cbb.tar.gz
gsoc2013-evolution-dddc124a9d32d349106803a04040a3edad2a3cbb.tar.zst
gsoc2013-evolution-dddc124a9d32d349106803a04040a3edad2a3cbb.zip
Accept text/uri-list mime types - this allows us to drag messages from
2001-06-19 Jeffrey Stedfast <fejj@ximian.com> * component-factory.c (destination_folder_handle_drop): Accept text/uri-list mime types - this allows us to drag messages from Nautilus into an Evolution folder. * folder-browser.c (message_list_drag_data_get): Do cleanup and better error handling. svn path=/trunk/; revision=10296
Diffstat (limited to 'mail')
-rw-r--r--mail/ChangeLog9
-rw-r--r--mail/component-factory.c58
-rw-r--r--mail/folder-browser.c78
3 files changed, 130 insertions, 15 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index eefd5c93af..149d88cb3a 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,12 @@
+2001-06-19 Jeffrey Stedfast <fejj@ximian.com>
+
+ * component-factory.c (destination_folder_handle_drop): Accept
+ text/uri-list mime types - this allows us to drag messages from
+ Nautilus into an Evolution folder.
+
+ * folder-browser.c (message_list_drag_data_get): Do cleanup and
+ better error handling.
+
2001-06-19 Jon Trowbridge <trow@ximian.com>
* mail-tools.c (mail_tool_do_movemail): Properly clean up the
diff --git a/mail/component-factory.c b/mail/component-factory.c
index 303b29f443..e561a45c78 100644
--- a/mail/component-factory.c
+++ b/mail/component-factory.c
@@ -69,20 +69,22 @@ static GHashTable *storages_hash;
enum {
ACCEPTED_DND_TYPE_MESSAGE_RFC822,
ACCEPTED_DND_TYPE_X_EVOLUTION_MESSAGE,
+ ACCEPTED_DND_TYPE_TEXT_URI_LIST,
};
static char *accepted_dnd_types[] = {
- "message/rfc822", /* if we drag from nautilus or something... */
- "x-evolution-message", /* if we drag from an evolution message list... */
+ "message/rfc822",
+ "x-evolution-message", /* ...from an evolution message list... */
+ "text/uri-list", /* ...from nautilus... */
NULL
};
enum {
- EXPORTED_DND_TYPE_TEXT_PLAIN,
+ EXPORTED_DND_TYPE_TEXT_URI_LIST,
};
static char *exported_dnd_types[] = {
- "text/plain", /* we have to export to nautilus as text/plain or a uri-list */
+ "text/uri-list", /* we have to export to nautilus as text/uri-list */
NULL
};
@@ -292,6 +294,7 @@ destination_folder_handle_motion (EvolutionShellComponentDndDestinationFolder *f
static gboolean
message_rfc822_dnd (CamelFolder *dest, CamelStream *stream)
{
+ gboolean retval = FALSE;
CamelMimeParser *mp;
CamelException *ex;
@@ -309,6 +312,9 @@ message_rfc822_dnd (CamelFolder *dest, CamelStream *stream)
if (camel_mime_part_construct_from_parser (CAMEL_MIME_PART (msg), mp) == -1) {
camel_object_unref (CAMEL_OBJECT (msg));
break;
+ } else {
+ /* we got at least 1 message so we will return TRUE */
+ retval = TRUE;
}
/* append the message to the folder... */
@@ -324,7 +330,7 @@ message_rfc822_dnd (CamelFolder *dest, CamelStream *stream)
camel_object_unref (CAMEL_OBJECT (mp));
camel_exception_free (ex);
- return TRUE;
+ return retval;
}
static CORBA_boolean
@@ -340,13 +346,53 @@ destination_folder_handle_drop (EvolutionShellComponentDndDestinationFolder *fol
CamelFolder *source;
CamelStream *stream;
GPtrArray *uids;
+ CamelURL *uri;
+ int type, fd;
if (action == GNOME_Evolution_ShellComponentDnd_ACTION_LINK)
return FALSE; /* we can't create links */
g_print ("in destination_folder_handle_drop (%s)\n", physical_uri);
- switch (data->format) {
+ for (type = 0; accepted_dnd_types[type]; type++)
+ if (!strcmp (destination_context->dndType, accepted_dnd_types[type]))
+ break;
+
+ switch (type) {
+ case ACCEPTED_DND_TYPE_TEXT_URI_LIST:
+ source = mail_tool_uri_to_folder (physical_uri, NULL);
+ if (!source)
+ return FALSE;
+
+ url = g_strndup (data->bytes._buffer, data->bytes._length);
+ inend = strchr (url, '\n');
+ if (inend)
+ *inend = '\0';
+
+ /* get the path component */
+ g_strstrip (url);
+ uri = camel_url_new (url, NULL);
+ g_free (url);
+ url = uri->path;
+ uri->path = NULL;
+ camel_url_free (uri);
+
+ fd = open (url, O_RDONLY);
+ if (fd == -1) {
+ g_free (url);
+ return FALSE;
+ }
+
+ stream = camel_stream_fs_new_with_fd (fd);
+ retval = message_rfc822_dnd (source, stream);
+ camel_object_unref (CAMEL_OBJECT (stream));
+ camel_object_unref (CAMEL_OBJECT (source));
+
+ if (action == GNOME_Evolution_ShellComponentDnd_ACTION_MOVE)
+ unlink (url);
+
+ g_free (url);
+ break;
case ACCEPTED_DND_TYPE_MESSAGE_RFC822:
source = mail_tool_uri_to_folder (physical_uri, NULL);
if (!source)
diff --git a/mail/folder-browser.c b/mail/folder-browser.c
index e9ce4df109..3dda5dc45a 100644
--- a/mail/folder-browser.c
+++ b/mail/folder-browser.c
@@ -57,14 +57,17 @@
enum DndTargetType {
DND_TARGET_TYPE_X_EVOLUTION_MESSAGE,
DND_TARGET_TYPE_MESSAGE_RFC822,
+ DND_TARGET_TYPE_TEXT_URI_LIST,
};
#define X_EVOLUTION_MESSAGE_TYPE "x-evolution-message"
#define MESSAGE_RFC822_TYPE "message/rfc822"
+#define TEXT_URI_LIST_TYPE "text/uri-list"
static GtkTargetEntry drag_types[] = {
{ X_EVOLUTION_MESSAGE_TYPE, 0, DND_TARGET_TYPE_X_EVOLUTION_MESSAGE },
{ MESSAGE_RFC822_TYPE, 0, DND_TARGET_TYPE_MESSAGE_RFC822 },
+ { TEXT_URI_LIST_TYPE, 0, DND_TARGET_TYPE_TEXT_URI_LIST },
};
static const int num_drag_types = sizeof (drag_types) / sizeof (drag_types[0]);
@@ -206,15 +209,9 @@ add_uid (MessageList *ml, const char *uid, gpointer data)
}
static void
-message_list_drag_data_get (ETree *tree,
- int row,
- ETreePath path,
- int col,
- GdkDragContext *context,
- GtkSelectionData *selection_data,
- guint info,
- guint time,
- gpointer user_data)
+message_list_drag_data_get (ETree *tree, int row, ETreePath path, int col,
+ GdkDragContext *context, GtkSelectionData *selection_data,
+ guint info, guint time, gpointer user_data)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
GPtrArray *uids = NULL;
@@ -224,6 +221,69 @@ message_list_drag_data_get (ETree *tree,
message_list_foreach (fb->message_list, add_uid, uids);
switch (info) {
+ case DND_TARGET_TYPE_TEXT_URI_LIST:
+ {
+ char dir_template[] = "/tmp/evolution-XXXXXX";
+ const char *dirname, *filename;
+ CamelMimeMessage *message;
+ CamelStream *stream;
+ char *uri_list;
+ int fd;
+
+ dirname = mktemp (dir_template);
+ if (!dirname) {
+ /* cleanup and abort */
+ for (i = 0; i < uids->len; i++)
+ g_free (uids->pdata[i]);
+ g_ptr_array_free (uids, TRUE);
+ return;
+ }
+
+ mkdir (dirname, 0700);
+
+ message = camel_folder_get_message (fb->folder, uids->pdata[0], NULL);
+ g_free (uids->pdata[0]);
+
+ if (uids->len == 1) {
+ filename = camel_mime_message_get_subject (message);
+ if (!filename)
+ filename = "Unknown";
+ } else
+ filename = "mbox";
+
+ uri_list = g_strdup_printf ("file://%s/%s", dirname, filename);
+
+ fd = open (uri_list + 7, O_WRONLY | O_CREAT, 0600);
+ if (fd == -1) {
+ /* cleanup and abort */
+ camel_object_unref (CAMEL_OBJECT (message));
+ for (i = 1; i < uids->len; i++)
+ g_free (uids->pdata[i]);
+ g_ptr_array_free (uids, TRUE);
+ g_free (uri_list);
+ return;
+ }
+
+ stream = camel_stream_fs_new_with_fd (fd);
+
+ camel_stream_write (stream, "From - \n", 8);
+ camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), stream);
+ camel_object_unref (CAMEL_OBJECT (message));
+ for (i = 1; i < uids->len; i++) {
+ message = camel_folder_get_message (fb->folder, uids->pdata[i], NULL);
+ camel_stream_write (stream, "From - \n", 8);
+ camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), stream);
+ camel_object_unref (CAMEL_OBJECT (message));
+ g_free (uids->pdata[i]);
+ }
+
+ camel_object_unref (CAMEL_OBJECT (stream));
+
+ gtk_selection_data_set (selection_data, selection_data->target, 8,
+ uri_list, strlen (uri_list));
+ g_free (uri_list);
+ }
+ break;
case DND_TARGET_TYPE_MESSAGE_RFC822:
{
/* FIXME: this'll be fucking slow for the user... pthread this? */