From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 768CC6DE1F9D for ; Sun, 26 Feb 2017 10:33:54 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.174 X-Spam-Level: X-Spam-Status: No, score=-0.174 tagged_above=-999 required=5 tests=[AWL=-0.154, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NcW5qFGKCy1r for ; Sun, 26 Feb 2017 10:33:54 -0800 (PST) Received: from mail-lf0-f67.google.com (mail-lf0-f67.google.com [209.85.215.67]) by arlo.cworth.org (Postfix) with ESMTPS id 8C1216DE2018 for ; Sun, 26 Feb 2017 10:33:53 -0800 (PST) Received: by mail-lf0-f67.google.com with SMTP id i17so1002841lfe.3 for ; Sun, 26 Feb 2017 10:33:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nikula-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=7cwrhGNg2E891PcvRe1GKXkgI/dQHyZgmmq13hCyvQQ=; b=uN2ZmAoni+xq8VKBbUuZS+kiehFUVFIebLSoWyqF0rIzG6t1D5u+iRxsuh0qUYvgSy O2TPOoIUPa9XbVs42iD74KvwatbpZvAWUDYnrXBctQw1z3AZYIuGy3Ut5XYX8iBCOulC 9PZf44TOm3z5dN1XJ+RzanAf96hKVamL3QTFH5R74X0CKhem01KBGbK6SaYn6oGSmVEK inMnTUZPtb3s14kXZ12A1bU/FsVOeA3kcNVmYzgIvE7S4IjZJN7XHaoorgm1iayTH4ib ZCpUz1Huy1Gms167oILAuaim8xLf2PqJ8p4wRmyLo5fk3j35N9RgH5A9lQsHt1PBOGj0 v/lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=7cwrhGNg2E891PcvRe1GKXkgI/dQHyZgmmq13hCyvQQ=; b=ObJt6ZLOQYmEfP7XQZrQoeKf64rjBnujp/g5EEzYT8J5nAIaBj9SEE80Oc0RxgxE5g qSaOM1hI0xg/olvEHmmqPRLD2gaubGaV6eaMRX7ZinltV+/H+s0OIYsJQec48wJx8Q4z niEZXv9g43c28lvWD4xwo9AIc7Pglx/w1QhxUk+jzlg9AekeaMy9+EBvu34abCqYDNi3 Yoi8icxjYII0Yopk3QhkO4mkRV2/xOV4WnW/icDRne/UsN4AJB8+yoKbs7kq+w5rBja1 V7wUwr30PeRZL1t4f5ArE0MxRB2nIoRkb+N7XX0se+tCanDa1ZDFlkQu0HUJdD/zuQ4I nS4g== X-Gm-Message-State: AMke39k9Nj3WcUebYhEs38UhMVE1WhohWXXMP08dMkJqtz12w4t75k2ke68b/2TTNDVElw== X-Received: by 10.25.199.135 with SMTP id x129mr3995444lff.42.1488134031739; Sun, 26 Feb 2017 10:33:51 -0800 (PST) Received: from localhost (mobile-access-bcee80-14.dhcp.inet.fi. [188.238.128.14]) by smtp.gmail.com with ESMTPSA id v136sm3332032lfa.66.2017.02.26.10.33.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 26 Feb 2017 10:33:51 -0800 (PST) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [PATCH v2 1/2] cli/show: abstract get content disposition Date: Sun, 26 Feb 2017 20:33:47 +0200 Message-Id: <20170226183348.30470-1-jani@nikula.org> X-Mailer: git-send-email 2.11.0 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.22 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: Sun, 26 Feb 2017 18:33:54 -0000 Reduce duplication in follow-up work. As a side effect, handle error returns from g_mime_content_disposition_get_disposition() without segfaulting. --- notmuch-show.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/notmuch-show.c b/notmuch-show.c index ab4ea1c2bdc1..7630f49dbc59 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -110,6 +110,17 @@ _get_one_line_summary (const void *ctx, notmuch_message_t *message) from, relative_date, tags); } +static const char *_get_disposition(GMimeObject *meta) +{ + GMimeContentDisposition *disposition; + + disposition = g_mime_object_get_content_disposition (meta); + if (!disposition) + return NULL; + + return g_mime_content_disposition_get_disposition (disposition); +} + /* Emit a sequence of key/value pairs for the metadata of message. * The caller should begin a map before calling this. */ static void @@ -463,14 +474,13 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node, notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED) ? 1 : 0, notmuch_message_get_filename (message)); } else { - GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (meta); + const char *disposition = _get_disposition (meta); const char *cid = g_mime_object_get_content_id (meta); const char *filename = leaf ? g_mime_part_get_filename (GMIME_PART (node->part)) : NULL; if (disposition && - strcasecmp (g_mime_content_disposition_get_disposition (disposition), - GMIME_DISPOSITION_ATTACHMENT) == 0) + strcasecmp (disposition, GMIME_DISPOSITION_ATTACHMENT) == 0) part_type = "attachment"; else part_type = "part"; -- 2.11.0