From 0ead86ec8959ce63e65e0a3fb989b4bca0a94e8c Mon Sep 17 00:00:00 2001 From: sterni Date: Wed, 25 Dec 2024 23:01:07 +0100 Subject: [PATCH] chore(users/sterni/mblog): rename apple-note to mail-note MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The type identifier Apple uses is com.apple.mail-note, so “Mail Note” is actually the best way to refer to this format. Not only doesn't it include a trademark, but it's also more accurate. The iOS and macOS Notes.app(s) allow authoring Notes to be saved in iCloud which seems to use a different API and/or storage format (at least these notes are no longer accessible via IMAP). In this sense they are “Apple Notes”, but not “Mail Notes”. Change-Id: I2fd3d3bd253ed39adf7965008290f7d1e622831d Reviewed-on: https://cl.tvl.fyi/c/depot/+/12815 Autosubmit: sterni Tested-by: BuildkiteCI Reviewed-by: sterni --- users/sterni/mblog/cli.lisp | 6 +-- users/sterni/mblog/default.nix | 6 +-- .../html-transformer.lisp} | 12 ++--- users/sterni/mblog/{ => mail-note}/note.lisp | 54 +++++++++---------- users/sterni/mblog/mblog.lisp | 20 +++---- users/sterni/mblog/packages.lisp | 22 ++++---- 6 files changed, 60 insertions(+), 60 deletions(-) rename users/sterni/mblog/{transformer.lisp => mail-note/html-transformer.lisp} (93%) rename users/sterni/mblog/{ => mail-note}/note.lisp (72%) diff --git a/users/sterni/mblog/cli.lisp b/users/sterni/mblog/cli.lisp index cd0a6ae39..5046db40d 100644 --- a/users/sterni/mblog/cli.lisp +++ b/users/sterni/mblog/cli.lisp @@ -1,5 +1,5 @@ ;; SPDX-License-Identifier: GPL-3.0-only -;; SPDX-FileCopyrightText: Copyright (C) 2022-2023 by sterni +;; SPDX-FileCopyrightText: Copyright (C) 2022-2024 by sterni (in-package :cli) (declaim (optimize (safety 3))) @@ -24,8 +24,8 @@ "Convert all note mime messages given as ARGS to HTML fragments." (declare (ignore name flags)) (loop for arg in args - do (note:apple-note-html-fragment - (note:make-apple-note (mime:mime-message (pathname arg))) + do (mail-note-html-fragment + (make-mail-note (mime:mime-message (pathname arg))) *standard-output*))) (defun mblog (name flags maildir outdir) diff --git a/users/sterni/mblog/default.nix b/users/sterni/mblog/default.nix index 1211dea01..c3c19591e 100644 --- a/users/sterni/mblog/default.nix +++ b/users/sterni/mblog/default.nix @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-3.0-only -# SPDX-FileCopyrightText: Copyright (C) 2022-2023 by sterni +# SPDX-FileCopyrightText: Copyright (C) 2022-2024 by sterni { depot, pkgs, ... }: (depot.nix.buildLisp.program { @@ -9,8 +9,8 @@ ./packages.lisp ./config.lisp ./maildir.lisp - ./transformer.lisp - ./note.lisp + ./mail-note/html-transformer.lisp + ./mail-note/note.lisp ./mblog.lisp ./cli.lisp ]; diff --git a/users/sterni/mblog/transformer.lisp b/users/sterni/mblog/mail-note/html-transformer.lisp similarity index 93% rename from users/sterni/mblog/transformer.lisp rename to users/sterni/mblog/mail-note/html-transformer.lisp index c499eafbe..65d07e0c1 100644 --- a/users/sterni/mblog/transformer.lisp +++ b/users/sterni/mblog/mail-note/html-transformer.lisp @@ -1,7 +1,7 @@ ;; SPDX-License-Identifier: GPL-3.0-only -;; SPDX-FileCopyrightText: Copyright (C) 2022 by sterni +;; SPDX-FileCopyrightText: Copyright (C) 2022, 2024 by sterni -(in-package :note) +(in-package :mail-note) (declaim (optimize (safety 3))) ;; Throw away these tags and all of their children @@ -32,7 +32,7 @@ (def-proxy-handler hax:unescaped (data)) (def-proxy-handler hax:comment (data))) -(defclass apple-note-transformer (hax-proxy-handler) +(defclass mail-note-transformer (hax-proxy-handler) ((cid-lookup :initarg :cid-lookup :initform (lambda (cid) nil) @@ -52,7 +52,7 @@ ;; Define the “boring” handlers which just call the next method (i. e. the next ;; handler) unless discard-until is not nil in which case the event is dropped. (macrolet ((def-filter-handler (name (&rest args)) - `(defmethod ,name ((h apple-note-transformer) ,@args) + `(defmethod ,name ((h mail-note-transformer) ,@args) (when (not (transformer-discard-until h)) (call-next-method))))) (def-filter-handler hax:start-document (name p-id s-id)) @@ -70,7 +70,7 @@ :return-suffix t :test #'char=) (if starts-with-cid-p suffix data)))) -(defmethod hax:start-element ((handler apple-note-transformer) name attrs) +(defmethod hax:start-element ((handler mail-note-transformer) name attrs) (with-accessors ((discard-until transformer-discard-until) (next-handler proxy-next-handler) (cid-lookup transformer-cid-lookup) @@ -109,7 +109,7 @@ (t (call-next-method))) (setf depth (1+ depth)))) -(defmethod hax:end-element ((handler apple-note-transformer) name) +(defmethod hax:end-element ((handler mail-note-transformer) name) (with-accessors ((discard-until transformer-discard-until) (depth transformer-depth)) handler diff --git a/users/sterni/mblog/note.lisp b/users/sterni/mblog/mail-note/note.lisp similarity index 72% rename from users/sterni/mblog/note.lisp rename to users/sterni/mblog/mail-note/note.lisp index f056aaa72..5afe70605 100644 --- a/users/sterni/mblog/note.lisp +++ b/users/sterni/mblog/mail-note/note.lisp @@ -1,7 +1,7 @@ ;; SPDX-License-Identifier: GPL-3.0-only -;; SPDX-FileCopyrightText: Copyright (C) 2022-2023 by sterni +;; SPDX-FileCopyrightText: Copyright (C) 2022-2024 by sterni -(in-package :note) +(in-package :mail-note) (declaim (optimize (safety 3))) ;;; util @@ -15,7 +15,7 @@ do (write-string (who:escape-string-minimal (subseq buf 0 len)) out)))) (defun cid-header-value (cid) - "Takes a Content-ID as present in Apple Notes' tags and properly + "Takes a Content-ID as present in Mail Notes' tags and properly surrounds them with angle brackets for a MIME header" (concatenate 'string "<" cid ">")) @@ -25,49 +25,49 @@ ;;; main implementation -(defun apple-note-mime-subtype-p (x) +(defun mail-note-mime-subtype-p (x) (member x '("plain" "html") :test #'string-equal)) -(deftype apple-note-mime-subtype () - '(satisfies apple-note-mime-subtype-p)) +(deftype mail-note-mime-subtype () + '(satisfies mail-note-mime-subtype-p)) -(defclass apple-note (mime:mime-message) +(defclass mail-note (mime:mime-message) ((text-part :type mime:mime-text :initarg :text-part - :reader apple-note-text-part) + :reader mail-note-text-part) (subject :type string :initarg :subject - :reader apple-note-subject) + :reader mail-note-subject) (uuid :type string :initarg :uuid - :reader apple-note-uuid) + :reader mail-note-uuid) (time :type integer :initarg :time - :reader apple-note-time) + :reader mail-note-time) (mime-subtype - :type apple-note-mime-subtype + :type mail-note-mime-subtype :initarg :mime-subtype - :reader apple-note-mime-subtype)) + :reader mail-note-mime-subtype)) (:documentation - "Representation of a Note created using Apple's Notes via the IMAP backend")) + "Representation of a Mail Note, e.g. created using Apple's Notes App via the IMAP backend")) -(defun apple-note-p (msg) +(defun mail-note-p (msg) "Checks X-Uniform-Type-Identifier of a MIME:MIME-MESSAGE - to determine if a given mime message claims to be an Apple Note." + to determine if a given mime message claims to be an (Apple) Mail Note." (when-let (uniform-id (car (mime:mime-message-header-values "X-Uniform-Type-Identifier" msg))) (string-equal uniform-id "com.apple.mail-note"))) -(defun make-apple-note (msg) +(defun make-mail-note (msg) (check-type msg mime-message) - (unless (apple-note-p msg) - (error "Passed message is not an Apple Note according to headers")) + (unless (mail-note-p msg) + (error "Passed message is not a Mail Note according to headers")) (let ((text-part (mime:find-mime-text-part msg)) (subject (car (mime:mime-message-header-values "Subject" msg :decode t))) @@ -78,16 +78,16 @@ (time (find-mime-message-date msg))) ;; The idea here is that we don't need to check a lot manually, instead ;; the type annotation are going to do this for us (with sufficient safety?) - (change-class msg 'apple-note + (change-class msg 'mail-note :text-part text-part :subject subject :uuid uuid :time time :mime-subtype (mime:mime-subtype text-part)))) -(defgeneric apple-note-html-fragment (note out) +(defgeneric mail-note-html-fragment (note out) (:documentation - "Takes an APPLE-NOTE and writes its text content as HTML to + "Takes an MAIL-NOTE and writes its text content as HTML to the OUT stream. The tags are resolved to which refer to the respective attachment's filename as a relative path, but extraction of the attachments must be done separately. The @@ -95,19 +95,19 @@ discarded completely, so only a fragment which can be included in custom templates remains.")) -(defmethod apple-note-html-fragment ((note apple-note) (out stream)) - (let ((text (apple-note-text-part note))) +(defmethod mail-note-html-fragment ((note mail-note) (out stream)) + (let ((text (mail-note-text-part note))) (cond ;; notemap creates text/plain notes we need to handle properly. ;; Additionally we *could* check X-Mailer which notemap sets - ((string-equal (apple-note-mime-subtype note) "plain") + ((string-equal (mail-note-mime-subtype note) "plain") (html-escape-stream (mime:mime-body-stream text) out)) ;; Notes.app creates text/html parts - ((string-equal (apple-note-mime-subtype note) "html") + ((string-equal (mail-note-mime-subtype note) "html") (closure-html:parse (mime:mime-body-stream text) (make-instance - 'apple-note-transformer + 'mail-note-transformer :cid-lookup (lambda (cid) (when-let* ((part (mime:find-mime-part-by-id note (cid-header-value cid))) diff --git a/users/sterni/mblog/mblog.lisp b/users/sterni/mblog/mblog.lisp index 7823bde20..69c86e8c1 100644 --- a/users/sterni/mblog/mblog.lisp +++ b/users/sterni/mblog/mblog.lisp @@ -1,5 +1,5 @@ ;; SPDX-License-Identifier: GPL-3.0-only -;; SPDX-FileCopyrightText: Copyright (C) 2022-2023 by sterni +;; SPDX-FileCopyrightText: Copyright (C) 2022-2024 by sterni ;; SPDX-FileCopyrightText: Copyright (C) 2006-2010 by Walter C. Pelissero (in-package :mblog) @@ -73,13 +73,13 @@ a:link, a:visited { "Convert NOTE to HTML and write it to index.html in NOTE-DIR alongside any extra attachments NOTE contains." (with-overwrite-file (html-stream (merge-pathnames "index.html" note-dir)) - (render-page (html-stream (apple-note-subject note)) + (render-page (html-stream (mail-note-subject note)) (:article - (apple-note-html-fragment note html-stream)))) + (mail-note-html-fragment note html-stream)))) (mime:do-parts (part note) (unless (string= (mime:mime-id part) - (mime:mime-id (note:apple-note-text-part note))) + (mime:mime-id (mail-note-text-part note))) (let ((attachment-in (mime:mime-body-stream part)) (attachment-dst (merge-pathnames (mime:mime-part-file-name part) @@ -106,11 +106,11 @@ a:link, a:visited { (dolist (note notes-list) (who:htm (:tr - (:td (:a :href (who:escape-string (apple-note-uuid note)) - (who:esc (apple-note-subject note)))) + (:td (:a :href (who:escape-string (mail-note-uuid note)) + (who:esc (mail-note-subject note)))) (:td (who:esc (klatre:format-dottime - (universal-to-timestamp (apple-note-time note))))))))))) + (universal-to-timestamp (mail-note-time note))))))))))) (values)) (defun build-mblog (notes-dir html-dir) @@ -124,10 +124,10 @@ a:link, a:visited { (let ((all-notes '())) (dolist (message-path (maildir:list notes-dir)) - (let* ((note (make-apple-note (mime:mime-message message-path))) + (let* ((note (make-mail-note (mime:mime-message message-path))) (note-dir (merge-pathnames (make-pathname :directory - `(:relative ,(apple-note-uuid note))) + `(:relative ,(mail-note-uuid note))) html-dir))) (format *error-output* "Writing note message ~A to ~A~%" @@ -137,7 +137,7 @@ a:link, a:visited { (push note all-notes))) ;; reverse sort the entries by time for the index page - (setf all-notes (sort all-notes #'> :key #'apple-note-time)) + (setf all-notes (sort all-notes #'> :key #'mail-note-time)) (build-index-page all-notes (merge-pathnames "index.html" html-dir)) diff --git a/users/sterni/mblog/packages.lisp b/users/sterni/mblog/packages.lisp index d6e33955d..e55558267 100644 --- a/users/sterni/mblog/packages.lisp +++ b/users/sterni/mblog/packages.lisp @@ -1,5 +1,5 @@ ;; SPDX-License-Identifier: GPL-3.0-only -;; SPDX-FileCopyrightText: Copyright (C) 2022-2023 by sterni +;; SPDX-FileCopyrightText: Copyright (C) 2022-2024 by sterni (defpackage :maildir (:use :common-lisp) @@ -17,7 +17,7 @@ :init-from-env :*general-buffer-size*)) -(defpackage :note +(defpackage :mail-note (:use :common-lisp :closure-html @@ -32,13 +32,13 @@ :ends-with-subseq) (:import-from :who :escape-string-minimal) (:export - :apple-note - :apple-note-uuid - :apple-note-subject - :apple-note-time - :apple-note-text-part - :make-apple-note - :apple-note-html-fragment)) + :mail-note + :mail-note-uuid + :mail-note-subject + :mail-note-time + :mail-note-text-part + :make-mail-note + :mail-note-html-fragment)) (defpackage :mblog (:use @@ -46,7 +46,7 @@ :klatre :who :maildir - :note + :mail-note :config) (:export :build-mblog) (:import-from :local-time :universal-to-timestamp) @@ -57,7 +57,7 @@ (:use :common-lisp :uiop - :note + :mail-note :config :mblog) (:import-from :alexandria :starts-with)