Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 00EEC429E20 for ; Sat, 7 May 2011 16:01:45 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Scjq8DBql6hN for ; Sat, 7 May 2011 16:01:44 -0700 (PDT) Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 11D37431FB5 for ; Sat, 7 May 2011 16:01:43 -0700 (PDT) Received: by bwg12 with SMTP id 12so3585475bwg.26 for ; Sat, 07 May 2011 16:01:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer; bh=mbMTWauJMjFs1wVGQkRbyKZECLqaIYVorMZzM8OerdY=; b=jzJ9XGWAy5hD49hZClY6l25pMiVG7pRHAdtR+0QpX7weEb06GB2s9yvVkusRH5LiZv 4Dz2otqOBCcmIeOwjDpS4BVSXXDWuwCQUYpvc+zq6rAYs/ymhlA0zelLvsYT2VJ3MknP qgmcZN60TCK3H8zXOPL3mlZ68slMaxJie5yFw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=N7Ng6yvJOntlntrcikdkgNKPc/ygbXVIXgr5k+swqbgKK/tzJJuTvTkaxrF/exXr7Q AI5YpIUh9Zs7DGtguxdObmf7iM7b64pfdwP0GgGn1MbupSEBEXmP71btd+5M9QkLGXQ/ e1Ae46WqhDdh751YeKMPReIHg3aE1R9wMIOCY= Received: by 10.205.82.10 with SMTP id aa10mr2527131bkc.97.1304809302324; Sat, 07 May 2011 16:01:42 -0700 (PDT) Received: from localhost ([91.144.186.21]) by mx.google.com with ESMTPS id 5sm403837faz.2.2011.05.07.16.01.40 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 07 May 2011 16:01:41 -0700 (PDT) From: Dmitry Kurochkin To: Notmuch Mail Subject: [PATCH] Add part filename in notmuch show output if available. Date: Sun, 8 May 2011 03:00:37 +0400 Message-Id: <1304809237-10583-1-git-send-email-dmitry.kurochkin@gmail.com> X-Mailer: git-send-email 1.7.5.1 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 May 2011 23:01:45 -0000 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