unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] Add part filename in notmuch show output if available.
@ 2011-05-07 23:00 Dmitry Kurochkin
  2011-05-07 23:05 ` Dmitry Kurochkin
  2011-05-08 23:21 ` Jameson Graef Rollins
  0 siblings, 2 replies; 3+ messages in thread
From: Dmitry Kurochkin @ 2011-05-07 23:00 UTC (permalink / raw)
  To: Notmuch Mail

Before the change, notmuch show output had filename only for
parts with "Content-Disposition: attachment".  But parts with
inline disposition may have filename as well.

The patch makes notmuch show always output filename if available,
independent of Content-Disposition.  Both JSON and text output
formats are changed.

The main goal of these changes is to have filenames on Emacs
buttons for inline attachments.  In particular, this is very
helpful for inline patches.

Note: text format changes may require updates in clients that use
it.  The changes are:

* text part header format changed from:

    ^Lpart{ ID: 2, Content-type: text/x-diff

  to:

    ^Lpart{ ID: 2, Content-type: text/x-diff, Filename: cool-feature.patch

* attachment format changed from:

    ^Lattachment{ ID: 4, Content-type: application/octet-stream
    Attachment: data.tar.bz2 (application/octet-stream)
    ^Lattachment}

  to:

    ^Lattachment{ ID: 4, Content-type: application/octet-stream
    Attachment: data.tar.bz2
    ^Lattachment}
---
 notmuch-show.c |   25 +++++++++++++------------
 1 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index 4d64d1e..1624b23 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -411,6 +411,7 @@ format_part_text (GMimeObject *part,
 {
     GMimeContentDisposition *disposition;
     GMimeContentType *content_type;
+    const char *filename;
 
     /* Avoid compiler complaints about unused arguments. */
     (void) first;
@@ -458,18 +459,19 @@ format_part_text (GMimeObject *part,
 	return;
     }
 
+    filename = g_mime_part_get_filename (GMIME_PART (part));
+
     disposition = g_mime_object_get_content_disposition (part);
     if (disposition &&
 	strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0)
     {
-	const char *filename = g_mime_part_get_filename (GMIME_PART (part));
 	content_type = g_mime_object_get_content_type (GMIME_OBJECT (part));
 
 	printf ("\fattachment{ ID: %d, Content-type: %s\n",
 		*part_count,
 		g_mime_content_type_to_string (content_type));
-	printf ("Attachment: %s (%s)\n", filename,
-		g_mime_content_type_to_string (content_type));
+	if (filename && *filename)
+	    printf ("Attachment: %s\n", filename);
 
 	if (g_mime_content_type_is_type (content_type, "text", "*") &&
 	    !g_mime_content_type_is_type (content_type, "text", "html"))
@@ -487,9 +489,13 @@ format_part_text (GMimeObject *part,
 
     content_type = g_mime_object_get_content_type (GMIME_OBJECT (part));
 
-    printf ("\fpart{ ID: %d, Content-type: %s\n",
+    printf ("\fpart{ ID: %d, Content-type: %s",
 	    *part_count,
 	    g_mime_content_type_to_string (content_type));
+    if (filename && *filename)
+	printf (", Filename: %s\n", filename);
+    else
+	printf ("\n");
 
     if (g_mime_content_type_is_type (content_type, "text", "*") &&
 	!g_mime_content_type_is_type (content_type, "text", "html"))
@@ -583,12 +589,12 @@ format_part_json (GMimeObject *part,
 
 {
     GMimeContentType *content_type;
-    GMimeContentDisposition *disposition;
     GError* err = NULL;
     void *ctx = talloc_new (NULL);
     GMimeStream *stream_memory = g_mime_stream_mem_new ();
     GByteArray *part_content;
     const char *cid;
+    const char *filename;
 
     *part_count += 1;
 
@@ -722,14 +728,9 @@ format_part_json (GMimeObject *part,
 	return;
     }
 
-    disposition = g_mime_object_get_content_disposition (part);
-    if (disposition &&
-	strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0)
-    {
-	const char *filename = g_mime_part_get_filename (GMIME_PART (part));
-
+    filename = g_mime_part_get_filename (GMIME_PART (part));
+    if (filename && *filename)
 	printf (", \"filename\": %s", json_quote_str (ctx, filename));
-    }
 
     if (g_mime_content_type_is_type (content_type, "text", "*") &&
 	!g_mime_content_type_is_type (content_type, "text", "html"))
-- 
1.7.5.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Add part filename in notmuch show output if available.
  2011-05-07 23:00 [PATCH] Add part filename in notmuch show output if available Dmitry Kurochkin
@ 2011-05-07 23:05 ` Dmitry Kurochkin
  2011-05-08 23:21 ` Jameson Graef Rollins
  1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Kurochkin @ 2011-05-07 23:05 UTC (permalink / raw)
  To: Notmuch Mail

Forgot to note, this patch is for release-candidate/0.6 branch.

Regards,
  Dmitry

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Add part filename in notmuch show output if available.
  2011-05-07 23:00 [PATCH] Add part filename in notmuch show output if available Dmitry Kurochkin
  2011-05-07 23:05 ` Dmitry Kurochkin
@ 2011-05-08 23:21 ` Jameson Graef Rollins
  1 sibling, 0 replies; 3+ messages in thread
From: Jameson Graef Rollins @ 2011-05-08 23:21 UTC (permalink / raw)
  To: Dmitry Kurochkin, Notmuch Mail

[-- Attachment #1: Type: text/plain, Size: 564 bytes --]

On Sun,  8 May 2011 03:00:37 +0400, Dmitry Kurochkin <dmitry.kurochkin@gmail.com> wrote:
> Before the change, notmuch show output had filename only for
> parts with "Content-Disposition: attachment".  But parts with
> inline disposition may have filename as well.
> 
> The patch makes notmuch show always output filename if available,
> independent of Content-Disposition.  Both JSON and text output
> formats are changed.

Hey, Dimitry.  I think this is a nice idea, and a clean patch.

It's now applied to the release-candidate/0.6 branch.

jamie.

[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-05-08 23:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-07 23:00 [PATCH] Add part filename in notmuch show output if available Dmitry Kurochkin
2011-05-07 23:05 ` Dmitry Kurochkin
2011-05-08 23:21 ` Jameson Graef Rollins

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).