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 QN1cHIBl8V9bJgAAsNZ9tg (envelope-from ); Sun, 03 Jan 2021 06:34:40 +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 iLKrKH9l8V+kGAAAbx9fmQ (envelope-from ); Sun, 03 Jan 2021 06:34:39 +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=1609655679; 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; bh=IDuMC5lORHsua3BHvNhY1XBpmzslFM/UGXMeRylHc7U=; b=JZmJPInhlIQGSqSc3lOpp+twXEbEnM0Py1H7lDyltWz7GBhv7q9x/mQ8nAGsijF4KpPTnQ CWuiy0tXAlTLxLZvh0z9zAwF2Dttam3ihSaH6AdZQlxXBtWWH0RUKl64RJtS5PJ8U/TZNn dx2/R4KinYhdg9suDl8rdV/1q3o3j8Ldst5Ol0W5WGO/nrAcowyGFwsyuNW6ZjEFhJ1TsD 1VyNmSjqXguGWMp9IRIPVOqdqknlEDhG2ZOw3d0DhGEJFlpDhRLdW4cdBMUFXv7UEmEcxU VF30VUT28+BDBLfH3r79fuBJo54Z0krmvKD9VMDQIjqYALekZb0Tu9P78QHHqg== From: Kyle Meyer To: piem@inbox.kyleam.com Subject: [PATCH] Decode more message headers Message-Id: <20210103063425.22718-1-kyle@kyleam.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: kyle@kyleam.com Date: Sun, 03 Jan 2021 06:34:39 GMT X-TUID: 7x5S9alkz62H piem-extract-mbox-info feeds the "from" header value through rfc2047-decode-string, but the same treatment should be applied to other header values. --- piem-gnus.el | 7 +++++-- piem.el | 25 +++++++++++++------------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/piem-gnus.el b/piem-gnus.el index 9dc4ae8..2674d05 100644 --- a/piem-gnus.el +++ b/piem-gnus.el @@ -31,6 +31,7 @@ (require 'gnus) (require 'gnus-sum) (require 'message) (require 'piem) +(require 'rfc2047) (defgroup piem-gnus nil "Gnus integration for piem." @@ -85,8 +86,10 @@ (defun piem-gnus-am-ready-mbox () (when-let ((patch (with-current-buffer gnus-article-buffer (save-restriction (widen) - (and (string-match-p piem-patch-subject-re - (message-field-value "subject")) + (and (string-match-p + piem-patch-subject-re + (rfc2047-decode-string + (message-field-value "subject"))) (buffer-substring-no-properties (point-min) (point-max))))))) (cons (lambda () (insert patch)) diff --git a/piem.el b/piem.el index acbbc4c..b716fea 100644 --- a/piem.el +++ b/piem.el @@ -302,17 +302,22 @@ (defun piem-message-link-re (url &optional mid) (one-or-more (not (any "/" "\n"))))))) string-end))) +(defun piem--message-fetch-decoded-fields (headers) + (save-excursion + (save-restriction + (message-narrow-to-head) + (mapcar (lambda (header) + (when-let ((val (message-fetch-field header))) + (rfc2047-decode-string val))) + headers)))) + (defun piem-inbox-by-header-match () "Return inbox based on matching message headers. This should be called from a buffer containing a message and is intended to be used by libraries implementing a function for `piem-get-mid-functions'." (pcase-let ((`(,listid ,to ,cc) - (save-restriction - (message-narrow-to-head) - (list (message-fetch-field "list-id") - (message-fetch-field "to") - (message-fetch-field "cc"))))) + (piem--message-fetch-decoded-fields '("list-id" "to" "cc")))) (catch 'hit (dolist (inbox piem-inboxes) (let* ((info (cdr inbox)) @@ -582,13 +587,9 @@ (defun piem-extract-mbox-info (&optional buffer) If BUFFER is nil, the current buffer is used. Any message after the first will be ignored." (with-current-buffer (or buffer (current-buffer)) - (let ((info (save-excursion - (save-restriction - (message-narrow-to-head) - (list :date (message-fetch-field "date") - :from (when-let ((from (message-fetch-field "from"))) - (rfc2047-decode-string from)) - :subject (message-fetch-field "subject")))))) + (let ((info (cl-mapcan #'list '(:date :from :subject) + (piem--message-fetch-decoded-fields + '("date" "from" "subject"))))) (when (re-search-forward (rx line-start "base-commit: " (group (>= 40 hex-digit)) line-end) base-commit: 10ac8491c370b683b0e3fad8150462407719957a -- 2.29.2