discussion and development of piem
 help / color / mirror / code / Atom feed
From: Kyle Meyer <kyle@kyleam.com>
To: piem@inbox.kyleam.com
Subject: [PATCH] Decode more message headers
Date: Sun, 03 Jan 2021 06:34:39 GMT	[thread overview]
Message-ID: <20210103063425.22718-1-kyle@kyleam.com> (raw)

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


                 reply	other threads:[~2021-01-03  6:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://git.kyleam.com/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210103063425.22718-1-kyle@kyleam.com \
    --to=kyle@kyleam.com \
    --cc=piem@inbox.kyleam.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.kyleam.com/piem/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).