feat(3p/lisp/mime4cl): search for first (default) mime text part
Adds a simple generic function find-mime-text-part which returns the first suitable text/* part in any MIME part it is given. Has no meaningful alternatives handling at the moment: It will pick the first text part and doesn't allow specifying a preference. Change-Id: Id9b113b3ef3ca1a575ce8f3582a4f85e30edfb43 Reviewed-on: https://cl.tvl.fyi/c/depot/+/3379 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
parent
62fa36c9c2
commit
7f31562acf
2 changed files with 25 additions and 0 deletions
24
third_party/lisp/mime4cl/mime.lisp
vendored
24
third_party/lisp/mime4cl/mime.lisp
vendored
|
@ -1,6 +1,7 @@
|
|||
;;; mime4cl.lisp --- MIME primitives for Common Lisp
|
||||
|
||||
;;; Copyright (C) 2005-2008, 2010 by Walter C. Pelissero
|
||||
;;; Copyright (C) 2021 by the TVL Authors
|
||||
|
||||
;;; Author: Walter C. Pelissero <walter@pelissero.de>
|
||||
;;; Project: mime4cl
|
||||
|
@ -964,6 +965,29 @@ is a string."))
|
|||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defmethod find-mime-text-part (msg)
|
||||
(:documentation
|
||||
"Return message if it is a text message or first text part.
|
||||
If no suitable text part is found, return NIL."))
|
||||
|
||||
(defmethod find-mime-text-part ((part mime-text))
|
||||
part) ; found our target
|
||||
|
||||
(defmethod find-mime-text-part ((msg mime-message))
|
||||
;; mime-body is either a mime-part or mime-multipart
|
||||
(find-mime-text-part (mime-body msg)))
|
||||
|
||||
(defmethod find-mime-text-part ((parts mime-multipart))
|
||||
;; multipart messages may have a body, otherwise we
|
||||
;; search for the first text part
|
||||
(or (call-next-method)
|
||||
(find-if #'find-mime-text-part (mime-parts parts))))
|
||||
|
||||
(defmethod find-mime-text-part ((part mime-part))
|
||||
nil) ; default case
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defgeneric mime-type-string (mime-part)
|
||||
(:documentation
|
||||
"Return the string describing the MIME part."))
|
||||
|
|
1
third_party/lisp/mime4cl/package.lisp
vendored
1
third_party/lisp/mime4cl/package.lisp
vendored
|
@ -65,6 +65,7 @@
|
|||
#:mime=
|
||||
#:find-mime-part-by-path
|
||||
#:find-mime-part-by-id
|
||||
#:find-mime-text-part
|
||||
#:encode-mime-part
|
||||
#:encode-mime-body
|
||||
#:decode-quoted-printable-stream
|
||||
|
|
Loading…
Reference in a new issue