feat: move mblog header handling into mime4cl
Accessing the headers of a MIME message feels like something mime4cl should handle. We implemented this ad hoc in mblog before in order to not need to worry about doing it in a sensible way. Now we introduce a decent-ish interface for getting a header from a MIME message, mime-message-header-values: * It returns a list because MIME message headers may appear multiple times. * It decodes RFC2047 only upon request, as you may want to be stricter about parsing certain fields. * It checks header name equality case insensitively. The code for decoding the RFC2047 string is retained and still uses babel for doing the actual decoding. Change-Id: I58bbbe4b46dbded04160b481a28a40d14775673d Reviewed-on: https://cl.tvl.fyi/c/depot/+/5150 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
parent
81c47da91c
commit
5bc73de59d
7 changed files with 43 additions and 37 deletions
14
third_party/lisp/mime4cl/mime.lisp
vendored
14
third_party/lisp/mime4cl/mime.lisp
vendored
|
|
@ -622,6 +622,20 @@ found in STREAM."
|
|||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defun mime-message-header-values (name message &key decode)
|
||||
"Return all values of the header with NAME in MESSAGE, optionally decoding
|
||||
it according to RFC2047 if :DECODE is T."
|
||||
(loop ;; A header may occur multiple times
|
||||
for header in (mime-message-headers message)
|
||||
;; MIME Headers should be case insensitive
|
||||
;; https://stackoverflow.com/a/6143644
|
||||
when (string-equal (car header) name)
|
||||
collect (if decode
|
||||
(decode-RFC2047 (cdr header))
|
||||
(cdr header))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defvar *lazy-mime-decode* t
|
||||
"If true don't decode mime bodies in memory.")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue