From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>
To: Notmuch Mail <notmuch@notmuchmail.org>
Subject: [PATCH] Add part filename in notmuch show output if available.
Date: Sun, 8 May 2011 03:00:37 +0400 [thread overview]
Message-ID: <1304809237-10583-1-git-send-email-dmitry.kurochkin@gmail.com> (raw)
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
next reply other threads:[~2011-05-07 23:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-07 23:00 Dmitry Kurochkin [this message]
2011-05-07 23:05 ` [PATCH] Add part filename in notmuch show output if available Dmitry Kurochkin
2011-05-08 23:21 ` Jameson Graef Rollins
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1304809237-10583-1-git-send-email-dmitry.kurochkin@gmail.com \
--to=dmitry.kurochkin@gmail.com \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).