X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fmodest-tny-msg-view.c;h=13ece7ae5879e1df133511af7a2e1cafe2163f07;hb=5bf2f24ec962205cc2c0af1e658189913ce7cfef;hp=675abb25661cbd098ee30464117197d7af1ee23a;hpb=3e9540a1c3f1f6711af46b7a011c05f7727b913b;p=modest diff --git a/src/modest-tny-msg-view.c b/src/modest-tny-msg-view.c index 675abb2..13ece7a 100644 --- a/src/modest-tny-msg-view.c +++ b/src/modest-tny-msg-view.c @@ -30,6 +30,10 @@ static gboolean on_url_requested (GtkWidget *widget, const gchar *uri, ModestTnyMsgView *msg_view); static gchar *construct_virtual_filename(const gchar *filename, const gint position, const gchar *id, const gboolean active); static gchar *construct_virtual_filename_from_mime_part(TnyMsgMimePartIface *msg, const gint position); + +#define ATTACHMENT_ID_INLINE "attachment-inline" +#define ATTACHMENT_ID_LINK "attachment-link" + gint virtual_filename_get_pos(const gchar *filename); /* * we need these regexps to find URLs in plain text e-mails @@ -68,7 +72,7 @@ typedef struct _ModestTnyMsgViewPrivate ModestTnyMsgViewPrivate; struct _ModestTnyMsgViewPrivate { GtkWidget *gtkhtml; TnyMsgIface *msg; - ModestConf *conf; + gboolean show_attachments_inline; }; #define MODEST_TNY_MSG_VIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ MODEST_TYPE_TNY_MSG_VIEW, \ @@ -125,7 +129,7 @@ modest_tny_msg_view_init (ModestTnyMsgView *obj) priv->gtkhtml = gtk_html_new(); - priv->conf = NULL; + priv->show_attachments_inline = FALSE; gtk_html_set_editable (GTK_HTML(priv->gtkhtml), FALSE); gtk_html_allow_selection (GTK_HTML(priv->gtkhtml), TRUE); @@ -144,11 +148,11 @@ modest_tny_msg_view_init (ModestTnyMsgView *obj) static void modest_tny_msg_view_finalize (GObject *obj) { - + /* TODO! */ } GtkWidget* -modest_tny_msg_view_new (TnyMsgIface *msg, ModestConf *conf) +modest_tny_msg_view_new (TnyMsgIface *msg, const gboolean show_attachments_inline) { GObject *obj; ModestTnyMsgView* self; @@ -163,25 +167,25 @@ modest_tny_msg_view_new (TnyMsgIface *msg, ModestConf *conf) GTK_POLICY_AUTOMATIC); if (priv->gtkhtml) - gtk_container_add (GTK_CONTAINER(obj), priv->gtkhtml); + gtk_container_add (GTK_CONTAINER(obj), priv->gtkhtml); if (msg) modest_tny_msg_view_set_message (self, msg); - priv->conf = conf; + modest_tny_msg_view_set_show_attachments_inline_flag(self, show_attachments_inline); return GTK_WIDGET(self); } - static gboolean on_link_clicked (GtkWidget *widget, const gchar *uri, ModestTnyMsgView *msg_view) { - if (g_str_has_prefix(uri, "attachment:")) { + if (g_str_has_prefix(uri, ATTACHMENT_ID_LINK)) { /* save or open attachment */ + g_message ("link-to-save: %s", uri); /* FIXME */ return TRUE; } g_message ("link clicked: %s", uri); /* FIXME */ @@ -257,6 +261,9 @@ on_url_requested (GtkWidget *widget, const gchar *uri, g_message ("url requested: %s", uri); + if (!modest_tny_msg_view_get_show_attachments_inline_flag(msg_view)) + return TRUE; /* debatable */ + if (g_str_has_prefix (uri, "cid:")) { /* +4 ==> skip "cid:" */ @@ -270,8 +277,9 @@ on_url_requested (GtkWidget *widget, const gchar *uri, tny_msg_mime_part_iface_decode_to_stream (part,tny_stream); gtk_html_stream_close (stream, GTK_HTML_STREAM_OK); } - } else if (g_str_has_prefix (uri, "Attachment:")) { - TnyMsgMimePartIface *part = find_attachment_by_filename (priv->msg, uri); + } else if (g_str_has_prefix (uri, ATTACHMENT_ID_INLINE)) { + TnyMsgMimePartIface *part; + part = find_attachment_by_filename (priv->msg, uri); if (!part) { g_message ("%s not found", uri); gtk_html_stream_close (stream, GTK_HTML_STREAM_ERROR); @@ -286,8 +294,6 @@ on_url_requested (GtkWidget *widget, const gchar *uri, } - - typedef struct { guint offset; guint len; @@ -295,7 +301,29 @@ typedef struct { } url_match_t; - +static gchar * +secure_filename(const gchar *fn) +{ + gchar *tmp, *p; + GString *s; + + s = g_string_new(""); +#if 1 || DEBUG + tmp = g_strdup(fn); + for (p = tmp; p[0] ; p++ ) { + p[0] &= 0x5f; /* 01011111 */ + p[0] |= 0x40; /* 01000000 */ + } + g_string_printf(s, "0x%x:%s", g_str_hash(fn), tmp); + g_free(tmp); + return g_string_free(s, FALSE); +#else + g_string_printf(s, "0x%x", g_str_hash(fn)); + return g_string_free(s, FALSE); +#endif +} + + static gchar * construct_virtual_filename(const gchar *filename, const gint position, @@ -303,21 +331,25 @@ construct_virtual_filename(const gchar *filename, const gboolean active) { GString *s; + gchar *fn; if (position < 0) - return "AttachmentInvalid"; + return g_strdup("AttachmentInvalid"); s = g_string_new(""); if (active) - g_string_append(s, "Attachment:"); + g_string_append(s, ATTACHMENT_ID_INLINE); else - g_string_append(s, "attachment:"); - g_string_append_printf(s, "%d:", position); + g_string_append(s, ATTACHMENT_ID_LINK); + g_string_append_printf(s, ":%d:", position); if (id) g_string_append(s, id); g_string_append_c(s, ':'); - if (filename) - g_string_append(s, filename); + + fn = secure_filename(filename); + if (fn) + g_string_append(s, fn); + g_free(fn); g_string_append_c(s, ':'); return g_string_free(s, FALSE); } @@ -365,13 +397,13 @@ virtual_filename_get_pos(const gchar *filename) gint len, pos; GString *dummy; - i1 = filename; - i2 = filename; - /* check prefix */ - i2 = get_next_token(i2, &len); - if (strncmp(i1, "Attachment", len) != 0) + if ((!g_str_has_prefix(filename, ATTACHMENT_ID_INLINE ":")) && + (!g_str_has_prefix(filename, ATTACHMENT_ID_LINK ":"))) return -1; + + i2 = filename; + i2 = get_next_token(i2, &len); i1 = i2; /* get position */ @@ -394,15 +426,14 @@ attachments_as_html(ModestTnyMsgView *self, TnyMsgIface *msg) const GList *attachment_list, *attachment; const gchar *content_type, *filename, *id; gchar *virtual_filename; - gboolean show_attachments_inline; if (!msg) return g_malloc0(1); priv = MODEST_TNY_MSG_VIEW_GET_PRIVATE (self); - /* CLEANUP: starting a new HTML may be unsupported */ - appendix = g_string_new("
\n