aboutsummaryrefslogtreecommitdiffstats
path: root/mail/mail-display.c
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2000-06-01 04:47:22 +0800
committerDan Winship <danw@src.gnome.org>2000-06-01 04:47:22 +0800
commit74ff74bf9b704a9cd6c007d25256d2ee6bbdad2f (patch)
treef5e9984c37b0ab63bde0476ab5a119016b560c78 /mail/mail-display.c
parente7255c4c78f45c25b736558fb511615ab47edc69 (diff)
downloadgsoc2013-evolution-74ff74bf9b704a9cd6c007d25256d2ee6bbdad2f.tar
gsoc2013-evolution-74ff74bf9b704a9cd6c007d25256d2ee6bbdad2f.tar.gz
gsoc2013-evolution-74ff74bf9b704a9cd6c007d25256d2ee6bbdad2f.tar.bz2
gsoc2013-evolution-74ff74bf9b704a9cd6c007d25256d2ee6bbdad2f.tar.lz
gsoc2013-evolution-74ff74bf9b704a9cd6c007d25256d2ee6bbdad2f.tar.xz
gsoc2013-evolution-74ff74bf9b704a9cd6c007d25256d2ee6bbdad2f.tar.zst
gsoc2013-evolution-74ff74bf9b704a9cd6c007d25256d2ee6bbdad2f.zip
Initialize the "urls" hash table stored on the message and store cid and
* mail-format.c (mail_format_mime_message): Initialize the "urls" hash table stored on the message and store cid and other URLs there rather than as object data on the message. (get_cid): rewrite this a bunch (handle_text_enriched): move the code from write_iframe_string() into here, since it's the only place that actually needs it. (handle_text_html): simplify this a lot. We can use a cid: URL here rather than x-evolution-data. (get_url_for_icon): New routine to return URLs for icons, and cache the results, so we don't have to keep re-reading the icon files (and so we can't be spoofed into reading non-icon files). (handle_mystery, handle_audio): use get_url_for_icon. * mail-display.c (save_data): move the CamelMimePart filename extracting code from get_cid to here. (on_link_clicked, on_object_requested): Update for cid: changes. (on_url_requested): Kill off the kludgy, exploitable x-gnome-icon URL schema, update cid and x-evolution-data to match mail-format.c. It should now be easier to implement RFC 2557 (Content-Location, etc), but that RFC still pretty much sucks. svn path=/trunk/; revision=3314
Diffstat (limited to 'mail/mail-display.c')
-rw-r--r--mail/mail-display.c91
1 files changed, 50 insertions, 41 deletions
diff --git a/mail/mail-display.c b/mail/mail-display.c
index 4456ad7f81..4ab6dbed02 100644
--- a/mail/mail-display.c
+++ b/mail/mail-display.c
@@ -10,6 +10,7 @@
*/
#include <config.h>
#include <sys/stat.h>
+#include <ctype.h>
#include <fcntl.h>
#include <errno.h>
#include <gnome.h>
@@ -90,20 +91,39 @@ save_data_cb (GtkWidget *widget, gpointer user_data)
static void
save_data (const char *cid, CamelMimeMessage *message)
{
+ GHashTable *urls;
+ CamelMimePart *part;
CamelDataWrapper *data;
GtkFileSelection *file_select;
char *filename;
g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message));
- data = gtk_object_get_data (GTK_OBJECT (message), cid);
- g_return_if_fail (CAMEL_IS_DATA_WRAPPER (data));
+ urls = gtk_object_get_data (GTK_OBJECT (message), "urls");
+ part = g_hash_table_lookup (urls, cid);
+ g_return_if_fail (CAMEL_IS_MIME_PART (part));
+ data = camel_medium_get_content_object (CAMEL_MEDIUM (part));
+
+ filename = (char *)camel_mime_part_get_filename (part);
+ if (filename) {
+ char *p;
+
+ p = strrchr (filename, '/');
+ if (p)
+ filename = g_strdup_printf ("%s%s", evolution_dir, p);
+ else {
+ filename = g_strdup_printf ("%s/%s", evolution_dir,
+ filename);
+ }
- file_select = GTK_FILE_SELECTION (gtk_file_selection_new ("Save Attachment"));
- filename = gtk_object_get_data (GTK_OBJECT (data), "filename");
- if (filename)
- filename = g_strdup_printf ("%s/%s", evolution_dir, filename);
- else
+ for (p = strrchr (filename, '/') + 1; *p; p++) {
+ if (!isascii ((unsigned char)*p) ||
+ strchr (" /'\"`&();|<>${}!", *p))
+ *p = '_';
+ }
+ } else
filename = g_strdup_printf ("%s/attachment", evolution_dir);
+
+ file_select = GTK_FILE_SELECTION (gtk_file_selection_new ("Save Attachment"));
gtk_file_selection_set_filename (file_select, filename);
g_free (filename);
@@ -120,13 +140,17 @@ save_data (const char *cid, CamelMimeMessage *message)
static void
on_link_clicked (GtkHTML *html, const char *url, gpointer user_data)
{
+ CamelMimeMessage *message;
+
+ message = gtk_object_get_data (GTK_OBJECT (html), "message");
+
if (!strncasecmp (url, "news:", 5) ||
!strncasecmp (url, "nntp:", 5))
g_warning ("Can't handle news URLs yet.");
else if (!strncasecmp (url, "mailto:", 7))
send_to_url (url);
else if (!strncasecmp (url, "cid:", 4))
- save_data (url + 4, user_data);
+ save_data (url, message);
else
gnome_url_show (url);
}
@@ -163,6 +187,8 @@ static gboolean
on_object_requested (GtkHTML *html, GtkHTMLEmbedded *eb, gpointer data)
{
CamelMimeMessage *message;
+ GHashTable *urls;
+ CamelMedium *medium;
CamelDataWrapper *wrapper;
const char *goad_id;
GtkWidget *embedded;
@@ -176,8 +202,10 @@ on_object_requested (GtkHTML *html, GtkHTMLEmbedded *eb, gpointer data)
if (strncmp (eb->classid, "cid:", 4) != 0)
return FALSE;
message = gtk_object_get_data (GTK_OBJECT (html), "message");
- wrapper = gtk_object_get_data (GTK_OBJECT (message), eb->classid + 4);
- g_return_val_if_fail (CAMEL_IS_DATA_WRAPPER (wrapper), FALSE);
+ urls = gtk_object_get_data (GTK_OBJECT (message), "urls");
+ medium = g_hash_table_lookup (urls, eb->classid);
+ g_return_val_if_fail (CAMEL_IS_MEDIUM (medium), FALSE);
+ wrapper = camel_medium_get_content_object (medium);
goad_id = gnome_mime_get_value (eb->type, "bonobo-goad-id");
if (!goad_id) {
@@ -241,39 +269,22 @@ on_url_requested (GtkHTML *html, const char *url, GtkHTMLStream *handle,
gpointer user_data)
{
CamelMimeMessage *message;
+ GHashTable *urls;
message = gtk_object_get_data (GTK_OBJECT (html), "message");
+ urls = gtk_object_get_data (GTK_OBJECT (message), "urls");
- if (strncmp (url, "x-gnome-icon:", 13) == 0) {
- const char *name = url + 13;
- /* FIXME: gnome_pixmap_file will cheerily accept icon
- * names like "../../../dev/zero". Anyway, this whole
- * hack needs to be replaced with something more
- * efficient anyway.
- */
- char *path = gnome_pixmap_file (name), buf[1024];
- int fd, nread;
-
- g_return_if_fail (path != NULL);
- fd = open (path, O_RDONLY);
- g_free (path);
- g_return_if_fail (fd != -1);
-
- while (1) {
- nread = read (fd, buf, sizeof (buf));
- if (nread < 1)
- break;
- gtk_html_write (html, handle, buf, nread);
- }
- close (fd);
- } else if (strncmp (url, "cid:", 4) == 0) {
- const char *cid = url + 4;
+ user_data = g_hash_table_lookup (urls, url);
+ g_return_if_fail (user_data != NULL);
+
+ if (strncmp (url, "cid:", 4) == 0) {
+ CamelMedium *medium = user_data;
CamelDataWrapper *data;
CamelStream *stream_mem;
GByteArray *ba;
- data = gtk_object_get_data (GTK_OBJECT (message), cid);
- g_return_if_fail (CAMEL_IS_DATA_WRAPPER (data));
+ g_return_if_fail (CAMEL_IS_MEDIUM (medium));
+ data = camel_medium_get_content_object (medium);
ba = g_byte_array_new ();
stream_mem = camel_stream_mem_new_with_byte_array (ba);
@@ -281,12 +292,10 @@ on_url_requested (GtkHTML *html, const char *url, GtkHTMLStream *handle,
gtk_html_write (html, handle, ba->data, ba->len);
gtk_object_unref (GTK_OBJECT (stream_mem));
} else if (strncmp (url, "x-evolution-data:", 17) == 0) {
- char *string;
-
- string = gtk_object_get_data (GTK_OBJECT (message), url);
- g_return_if_fail (string != NULL);
+ GByteArray *ba = user_data;
- gtk_html_write (html, handle, string, strlen (string));
+ g_return_if_fail (ba != NULL);
+ gtk_html_write (html, handle, ba->data, ba->len);
}
}