diff --git a/third_party/lisp/mime4cl/endec.lisp b/third_party/lisp/mime4cl/endec.lisp index 2e282c237..3f1fdb3bc 100644 --- a/third_party/lisp/mime4cl/endec.lisp +++ b/third_party/lisp/mime4cl/endec.lisp @@ -656,6 +656,7 @@ sequence, a charset string indicating the original coding." (cons (flexi-streams:octets-to-string (car part) :external-format (flexi-streams:make-external-format + ;; TODO(sterni): sanitize charset before interning (intern (string-upcase (cdr part)) 'keyword)))) (string part)))) (apply #'concatenate diff --git a/third_party/lisp/mime4cl/mime.lisp b/third_party/lisp/mime4cl/mime.lisp index 657c1fd86..da13a1126 100644 --- a/third_party/lisp/mime4cl/mime.lisp +++ b/third_party/lisp/mime4cl/mime.lisp @@ -201,8 +201,25 @@ because they are stored in dedicated slots in MIME-PART.") :test #'string=) (mime= (mime-body part1) (mime-body part2)))) -(defun mime-body-stream (mime-part) - (make-input-adapter (mime-body mime-part))) +(defgeneric mime-body-stream (mime-part) + (:documentation + "Returns stream that allows reading the decoded body of the given part. +STREAM-ELEMENT-TYPE depends on part type.")) + +;; TODO(sterni): Allow accessing underlying binary stream? +;; Would need matching behavior with :7bit +(defmethod mime-body-stream ((part mime-text)) + (let ((underlying-stream (call-next-method))) + (if (eq (stream-element-type underlying-stream) 'character) + underlying-stream + (make-flexi-stream underlying-stream + :external-format + ;; TODO(sterni): sanitize charset before interning + (intern (string-upcase (mime-text-charset part)) + 'keyword))))) + +(defmethod mime-body-stream ((part mime-part)) + (make-input-adapter (mime-body part))) (defmacro with-input-from-mime-body-stream ((stream part) &body forms) `(with-open-stream (,stream (mime-body-stream ,part)) diff --git a/third_party/lisp/mime4cl/test/samples/mail-note-from-notemap.msg b/third_party/lisp/mime4cl/test/samples/mail-note-from-notemap.msg new file mode 100644 index 000000000..2f74313b1 --- /dev/null +++ b/third_party/lisp/mime4cl/test/samples/mail-note-from-notemap.msg @@ -0,0 +1,13 @@ +From: +Date: Wed, 25 Dec 2024 23:54:39 +0100 +X-Universally-Unique-Identifier: d2ccdc74-830c-41ee-9d64-2221f1c35449 +X-Uniform-Type-Identifier: com.apple.mail-note +X-Mailer: notemap +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: quoted-printable +Subject: =?utf-8?Q?test.txt?= +X-TUID: clxSN23/djqG + +gr=C3=BC=C3=9Fe from notemap + diff --git a/third_party/lisp/mime4cl/test/samples/mail-note.msg b/third_party/lisp/mime4cl/test/samples/mail-note-from-notes-app.msg similarity index 100% rename from third_party/lisp/mime4cl/test/samples/mail-note.msg rename to third_party/lisp/mime4cl/test/samples/mail-note-from-notes-app.msg diff --git a/users/sterni/mblog/golden/default.nix b/users/sterni/mblog/golden/default.nix index 17350112c..a35cb5b21 100644 --- a/users/sterni/mblog/golden/default.nix +++ b/users/sterni/mblog/golden/default.nix @@ -6,8 +6,11 @@ let maildir = pkgs.runCommandNoCC "mblog-golden-example-maildir" { } '' mkdir -p "$out/cur" cp --reflink=auto \ - "${depot.path.origSrc + "/third_party/lisp/mime4cl/test/samples/mail-note.msg"}" \ + "${depot.path.origSrc + "/third_party/lisp/mime4cl/test/samples/mail-note-from-notes-app.msg"}" \ "$out/cur/1732277542.274467_1.wolfgang,U=1:2,S" + cp --reflink=auto \ + "${depot.path.origSrc + "/third_party/lisp/mime4cl/test/samples/mail-note-from-notemap.msg"}" \ + "$out/cur/1735167350.823243_1.wolfgang,U=32:2,S" ''; # Make golden test based on the given mblog derivation and add subtarget diff --git a/users/sterni/mblog/golden/expected/d2ccdc74-830c-41ee-9d64-2221f1c35449/index.html b/users/sterni/mblog/golden/expected/d2ccdc74-830c-41ee-9d64-2221f1c35449/index.html new file mode 100644 index 000000000..4abafc462 --- /dev/null +++ b/users/sterni/mblog/golden/expected/d2ccdc74-830c-41ee-9d64-2221f1c35449/index.html @@ -0,0 +1,4 @@ + +test.txt
grüße from notemap + +
\ No newline at end of file diff --git a/users/sterni/mblog/golden/expected/index.html b/users/sterni/mblog/golden/expected/index.html index fc2cd83b2..6fe6846ab 100644 --- a/users/sterni/mblog/golden/expected/index.html +++ b/users/sterni/mblog/golden/expected/index.html @@ -1,2 +1,2 @@ -mblog

mblog

example note2024-11-22T11·49+00
\ No newline at end of file +mblog

mblog

test.txt2024-12-25T22·54+00
example note2024-11-22T11·49+00
\ No newline at end of file