From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:863f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id mJj7GWR18l+KcQAAsNZ9tg (envelope-from ); Mon, 04 Jan 2021 01:54:44 +0000 Received: from out1.migadu.com ([2001:41d0:2:863f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id AETnJGN18l+iTgAAbx9fmQ (envelope-from ); Mon, 04 Jan 2021 01:54:43 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kyleam.com; s=key1; t=1609725283; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AQOaJOPPerGZMQWiOl2Fh8vJr/U/8vIQg9q+s2J7niU=; b=jP36Z7+eTIWfS64ue2Bk+7TQ/0RGJ67rgRW8cQHliqOwlsRu+G6EBj0QnlX5znxTppEX9r wGJm5fCIKFlXZ69UdqkzFH4A5is6/9WtFJsKwI1zZKEEezUNkxWuRE4MI7KVE3LPJHNivE krvVCsKX6x8DAcqK8UDQJg4AjXezBORqLvbmrwida5K9zEPnIUWRnmijGEImgDttnbNqy6 QvkfuzfRyS715TMVbAa+T30lnAtSdpzv0/WLnb3iXuZYPrrsZmgLR/qcN+auTuPuE08DTy 7JXAlwhuWtbs9OmWHX63wFisRiMQXYx7gXnGFtTiw8d3tpcWU5anMKrBC37rZg== From: Kyle Meyer To: piem@inbox.kyleam.com Subject: [PATCH v2 0/3] notmuch: Improve handling of attached patches Message-Id: <20210104015435.18397-1-kyle@kyleam.com> In-Reply-To: <87zh1pbh7x.fsf@kyleam.com> References: <87zh1pbh7x.fsf@kyleam.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: kyle@kyleam.com Date: Mon, 04 Jan 2021 01:54:43 GMT X-TUID: C5tV4IGHaabx I've hit into a few cases where piem-notmuch-am-ready-mbox hasn't been able to find an attached patch. This series, in particular patch 2, should improve the situation. v2: Fix handling of inline multipart/signed patches by using the attachment count rather than the top-level content-type to decide whether to go down the attachment or inline code path. [1/3] piem-notmuch--with-current-message: Declare debug and indent specs [2/3] piem-notmuch-am-ready-mbox: Improve handling of attachments [3/3] gnus, notmuch: Absorb now-shared bits into patch attachment helper piem-gnus.el | 14 ++------------ piem-notmuch.el | 49 +++++++++++++++++++++++++------------------------ piem.el | 21 +++++++++++++-------- 3 files changed, 40 insertions(+), 44 deletions(-) Range-diff against v1: 1: f4ff1f1 = 1: f4ff1f1 piem-notmuch--with-current-message: Declare debug and indent specs 2: 8eb290d ! 2: ca8d684 piem-notmuch-am-ready-mbox: Improve handling of attachments @@ piem-notmuch.el: (defun piem-notmuch-am-ready-mbox () - (dolist (patch patches) - (insert patch))) - "mbox"))))))) -+ (if (string-prefix-p -+ "multipart/" -+ (plist-get -+ (car (plist-get (notmuch-show-get-message-properties) -+ :body)) -+ :content-type)) -+ (let (patches) -+ (piem-notmuch--with-current-message -+ (notmuch-foreach-mime-part -+ (lambda (p) -+ (and (piem-am-patch-attachment-p -+ (mm-handle-media-type p) -+ (mm-handle-filename p)) -+ (with-temp-buffer -+ (mm-display-inline p) -+ (push (buffer-substring-no-properties -+ (point-min) (point-max)) -+ patches)))) -+ (mm-dissect-buffer))) -+ (when patches -+ (setq patches (nreverse patches)) -+ (cons (lambda () -+ (dolist (patch patches) -+ (insert patch))) -+ "mbox"))) -+ (when (string-match-p piem-patch-subject-re -+ (notmuch-show-get-subject)) -+ (let ((id (notmuch-show-get-message-id))) -+ (lambda () -+ (call-process notmuch-command nil t nil -+ "show" "--format=mbox" id))))))) ++ (let* ((handle (piem-notmuch--with-current-message ++ (mm-dissect-buffer))) ++ (n-attachments (notmuch-count-attachments handle)) ++ patches) ++ (if (= n-attachments 0) ++ (when (string-match-p piem-patch-subject-re ++ (notmuch-show-get-subject)) ++ (let ((id (notmuch-show-get-message-id))) ++ (lambda () ++ (call-process notmuch-command nil t nil ++ "show" "--format=mbox" id)))) ++ (notmuch-foreach-mime-part ++ (lambda (p) ++ (and (piem-am-patch-attachment-p ++ (mm-handle-media-type p) ++ (mm-handle-filename p)) ++ (with-temp-buffer ++ (mm-display-inline p) ++ (push (buffer-substring-no-properties ++ (point-min) (point-max)) ++ patches)))) ++ handle) ++ (when patches ++ (setq patches (nreverse patches)) ++ (cons (lambda () ++ (dolist (patch patches) ++ (insert patch))) ++ "mbox")))))) ;;;###autoload (define-minor-mode piem-notmuch-mode 3: 6bbde3b ! 3: ee314a5 gnus, notmuch: Absorb now-shared bits into patch attachment helper @@ piem-gnus.el: (defun piem-gnus-am-ready-mbox () ## piem-notmuch.el ## @@ piem-notmuch.el: (defun piem-notmuch-am-ready-mbox () - (piem-notmuch--with-current-message - (notmuch-foreach-mime-part - (lambda (p) -- (and (piem-am-patch-attachment-p -- (mm-handle-media-type p) -- (mm-handle-filename p)) -- (with-temp-buffer -- (mm-display-inline p) -- (push (buffer-substring-no-properties -- (point-min) (point-max)) -- patches)))) -+ (when-let ((patch (piem-am-extract-attached-patch p))) -+ (push patch patches))) - (mm-dissect-buffer))) - (when patches - (setq patches (nreverse patches)) + "show" "--format=mbox" id)))) + (notmuch-foreach-mime-part + (lambda (p) +- (and (piem-am-patch-attachment-p +- (mm-handle-media-type p) +- (mm-handle-filename p)) +- (with-temp-buffer +- (mm-display-inline p) +- (push (buffer-substring-no-properties +- (point-min) (point-max)) +- patches)))) ++ (when-let ((patch (piem-am-extract-attached-patch p))) ++ (push patch patches))) + handle) + (when patches + (setq patches (nreverse patches)) ## piem.el ## @@ base-commit: 96da1c622caac904e3f60e306847a4e68ca15e0c -- 2.29.2