From 96da1c622caac904e3f60e306847a4e68ca15e0c Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Sun, 3 Jan 2021 06:34:39 +0000 Subject: Decode more message headers piem-extract-mbox-info feeds the "from" header value through rfc2047-decode-string, but the same treatment should be applied to other header values. Message-Id: <20210103063425.22718-1-kyle@kyleam.com> --- 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 dd0234c..c6b9d0c 100644 --- a/piem-gnus.el +++ b/piem-gnus.el @@ -31,6 +31,7 @@ (require 'gnus-sum) (require 'message) (require 'piem) +(require 'rfc2047) (defgroup piem-gnus nil "Gnus integration for piem." @@ -85,8 +86,10 @@ message itself if it looks like a patch." (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 b9df925..bf79813 100644 --- a/piem.el +++ b/piem.el @@ -302,17 +302,22 @@ non-nil, make the match specific for that message." (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 @@ attachment file name, if any." 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) -- cgit v1.2.3