fix(users/sterni/mblog): handle RFC2047 in subjects
Non ASCII Subjects will use RFC2047 to encode their content. Using mime4cl's parse-RFC2047-text we obtain a list of ASCII strings and byte vectors tagged with their encoding. Using babel we can then decode the byte sequence, assuming the encoding is named the same in babel and RFC2047 (which it is for UTF-8 at least…). Change-Id: I2840672409452bd194fb1635721e338364d9b484 Reviewed-on: https://cl.tvl.fyi/c/depot/+/5078 Reviewed-by: sterni <sternenseemann@systemli.org> Tested-by: BuildkiteCI
This commit is contained in:
parent
c3cf66f248
commit
5789814dec
3 changed files with 20 additions and 1 deletions
|
@ -17,6 +17,7 @@ depot.nix.buildLisp.program {
|
|||
default = depot.nix.buildLisp.bundled "asdf";
|
||||
}
|
||||
depot.third_party.lisp.alexandria
|
||||
depot.third_party.lisp.babel
|
||||
depot.third_party.lisp.closure-html
|
||||
depot.third_party.lisp.cl-date-time-parser
|
||||
depot.third_party.lisp.cl-who
|
||||
|
|
|
@ -66,6 +66,20 @@
|
|||
:test #'string-equal))
|
||||
(string-equal (cdr uniform-id) "com.apple.mail-note")))
|
||||
|
||||
(defun decode-RFC2047-to-string (input)
|
||||
(apply
|
||||
#'concatenate
|
||||
(cons 'string
|
||||
(mapcar
|
||||
(lambda (el)
|
||||
(etypecase el
|
||||
(cons (babel:octets-to-string
|
||||
(car el)
|
||||
:encoding (babel-encodings:get-character-encoding
|
||||
(intern (string-upcase (cdr el)) 'keyword))))
|
||||
(string el)))
|
||||
(mime:parse-RFC2047-text input)))))
|
||||
|
||||
(defun make-apple-note (msg)
|
||||
(check-type msg mime-message)
|
||||
|
||||
|
@ -73,7 +87,9 @@
|
|||
(error "Passed message is not an Apple Note according to headers"))
|
||||
|
||||
(let ((text-part (mime:find-mime-text-part msg))
|
||||
(subject (find-mime-message-header "Subject" msg))
|
||||
(subject (when-let ((val (find-mime-message-header "Subject" msg)))
|
||||
;; TODO(sterni): mime4cl should do this
|
||||
(decode-RFC2047-to-string val)))
|
||||
(uuid (when-let ((val (find-mime-message-header
|
||||
"X-Universally-Unique-Identifier"
|
||||
msg)))
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
(defpackage :note
|
||||
(:use
|
||||
:common-lisp
|
||||
:babel
|
||||
:babel-encodings
|
||||
:closure-html
|
||||
:who
|
||||
:cl-date-time-parser
|
||||
|
|
Loading…
Reference in a new issue