mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-22 02:48:08 +01:00
Add part filename and content-id in notmuch show output if available.
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. Also, the patch adds Content-id to text output format of notmuch show. 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, Filename: cool-feature.patch, Content-type: text/x-diff * attachment format changed from: ^Lattachment{ ID: 4, Content-type: application/octet-stream Attachment: data.tar.bz2 (application/octet-stream) Non-text part: application/octet-stream ^Lattachment} to: ^Lattachment{ ID: 4, Filename: data.tar.bz2, Content-type: application/octet-stream Non-text part: application/octet-stream ^Lattachment}
This commit is contained in:
parent
a854d06e92
commit
1a27b33f20
1 changed files with 12 additions and 12 deletions
|
@ -454,19 +454,21 @@ format_part_start_text (GMimeObject *part, int *part_count)
|
||||||
static void
|
static void
|
||||||
format_part_content_text (GMimeObject *part)
|
format_part_content_text (GMimeObject *part)
|
||||||
{
|
{
|
||||||
GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (part);
|
const char *cid = g_mime_object_get_content_id (part);
|
||||||
GMimeContentType *content_type = g_mime_object_get_content_type (GMIME_OBJECT (part));
|
GMimeContentType *content_type = g_mime_object_get_content_type (GMIME_OBJECT (part));
|
||||||
|
|
||||||
printf (", Content-type: %s\n", g_mime_content_type_to_string (content_type));
|
if (GMIME_IS_PART (part))
|
||||||
|
|
||||||
if (disposition &&
|
|
||||||
strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0)
|
|
||||||
{
|
{
|
||||||
const char *filename = g_mime_part_get_filename (GMIME_PART (part));
|
const char *filename = g_mime_part_get_filename (GMIME_PART (part));
|
||||||
printf ("Attachment: %s (%s)\n", filename,
|
if (filename)
|
||||||
g_mime_content_type_to_string (content_type));
|
printf (", Filename: %s", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cid)
|
||||||
|
printf (", Content-id: %s", cid);
|
||||||
|
|
||||||
|
printf (", Content-type: %s\n", g_mime_content_type_to_string (content_type));
|
||||||
|
|
||||||
if (g_mime_content_type_is_type (content_type, "text", "*") &&
|
if (g_mime_content_type_is_type (content_type, "text", "*") &&
|
||||||
!g_mime_content_type_is_type (content_type, "text", "html"))
|
!g_mime_content_type_is_type (content_type, "text", "html"))
|
||||||
{
|
{
|
||||||
|
@ -591,7 +593,6 @@ format_part_content_json (GMimeObject *part)
|
||||||
GMimeStream *stream_memory = g_mime_stream_mem_new ();
|
GMimeStream *stream_memory = g_mime_stream_mem_new ();
|
||||||
const char *cid = g_mime_object_get_content_id (part);
|
const char *cid = g_mime_object_get_content_id (part);
|
||||||
void *ctx = talloc_new (NULL);
|
void *ctx = talloc_new (NULL);
|
||||||
GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (part);
|
|
||||||
GByteArray *part_content;
|
GByteArray *part_content;
|
||||||
|
|
||||||
printf (", \"content-type\": %s",
|
printf (", \"content-type\": %s",
|
||||||
|
@ -600,12 +601,11 @@ format_part_content_json (GMimeObject *part)
|
||||||
if (cid != NULL)
|
if (cid != NULL)
|
||||||
printf(", \"content-id\": %s", json_quote_str (ctx, cid));
|
printf(", \"content-id\": %s", json_quote_str (ctx, cid));
|
||||||
|
|
||||||
if (disposition &&
|
if (GMIME_IS_PART (part))
|
||||||
strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0)
|
|
||||||
{
|
{
|
||||||
const char *filename = g_mime_part_get_filename (GMIME_PART (part));
|
const char *filename = g_mime_part_get_filename (GMIME_PART (part));
|
||||||
|
if (filename)
|
||||||
printf (", \"filename\": %s", json_quote_str (ctx, filename));
|
printf (", \"filename\": %s", json_quote_str (ctx, filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_mime_content_type_is_type (content_type, "text", "*") &&
|
if (g_mime_content_type_is_type (content_type, "text", "*") &&
|
||||||
|
|
Loading…
Reference in a new issue