From 2d2cab9d97d3e84e5b7158181523fe2c5bbffe85 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 16 Apr 2023 17:06:41 -0500 Subject: uhhh --- lisp/acdw-mail.el | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 112 insertions(+), 1 deletion(-) (limited to 'lisp/acdw-mail.el') diff --git a/lisp/acdw-mail.el b/lisp/acdw-mail.el index 2a7d128..f8111e7 100644 --- a/lisp/acdw-mail.el +++ b/lisp/acdw-mail.el @@ -25,6 +25,10 @@ (defun +message-send-set-variables () "Set variables for `message-send' depending on the From: header. Useful in `message-send-hook'." + (unless +message-send-dispatch-rules + (load notmuch-init-file) + (or +message-send-dispatch-rules + (error "`+message-send-dispatch-rules' isn't set!"))) (let ((from (message-fetch-field "from"))) (cl-loop for (var . val) in (cl-loop for (address . bindings) in +message-send-dispatch-rules @@ -145,6 +149,112 @@ the saved search as well." ;;(user-error "Feature `async' not found!") (notmuch-poll))) +;;; https://kitchingroup.cheme.cmu.edu/blog/2015/09/04/Checking-for-email-attachments-before-you-send-email/ + +(defun email-says-attach-p () + "Return t if email suggests there could be an attachment." + (save-excursion + (goto-char (point-min)) + (re-search-forward "attach" nil t))) + +(defun email-has-attachment-p () + "Return t if the currently open email has an attachment." + (save-excursion + (goto-char (point-min)) + (re-search-forward "<#part" nil t))) + +(defun email-pre-send-check-attachment () + (when (and (email-says-attach-p) + (not (email-has-attachment-p))) + (unless + (y-or-n-p + "Your email suggests an attachment, but none was found. Send anyway?") + (error "No attachment. Aborting send.")))) + +;;; Process ical attachments + +(defun notmuch-save-ics () + "Save a .ics file in a message." + (interactive) + (with-current-notmuch-show-message + (notmuch-foreach-mime-part + (lambda (part) + (message "%S" part) + (when (and (listp part) + (or (equal "application/ics" (caadr part)) + ;; (equal "text/calendar" (caadr part)) + )) + (save-window-excursion + (let* ((filename "/tmp/notmuch.ics") + (buf (find-file-noselect filename))) + (delete-file filename) + (kill-buffer (get-file-buffer filename)) + (mm-save-part-to-file part filename) + (icalendar-import-file filename diary-file) + (kill-buffer buf))))) + (mm-dissect-buffer t t)))) + + +;;; Fixes + +;; https://nmbug.notmuchmail.org/nmweb/show/87bklhricc.fsf%40tethera.net + +(defun notmuch--indent-rigidly (start end count) + (cond + ((zerop count) t) + ((< count 0) (indent-rigidly start end count)) + (t + (save-excursion + (let ((startpt (progn (goto-char start) (line-beginning-position))) + (endpt (progn (goto-char end) (line-end-position))) + (spaces (spaces-string count))) + (goto-char startpt) + (while + (progn + (insert spaces) + (cl-incf endpt count) + (and (zerop (forward-line 1)) (bolp) + (<= (point) endpt))))))))) + +(with-eval-after-load 'notmuch-show + ;; Redefine `notmuch-show-lazy-part' --- XXX: this is the most braindead way + ;; of doing this + (defun notmuch-show-lazy-part (part-args button) + ;; Insert the lazy part after the button for the part. We would just + ;; move to the start of the new line following the button and insert + ;; the part but that point might have text properties (eg colours + ;; from a message header etc) so instead we start from the last + ;; character of the button by adding a newline and finish by + ;; removing the extra newline from the end of the part. + (save-excursion + (goto-char (button-end button)) + (insert "\n") + (let* ((inhibit-read-only t) + ;; We need to use markers for the start and end of the part + ;; because the part insertion functions do not guarantee + ;; to leave point at the end of the part. + (part-beg (copy-marker (point) nil)) + (part-end (copy-marker (point) t)) + ;; We have to save the depth as we can't find the depth + ;; when narrowed. + (depth (notmuch-show-get-depth))) + (save-restriction + (narrow-to-region part-beg part-end) + (delete-region part-beg part-end) + (apply #'notmuch-show-insert-bodypart-internal part-args) + (notmuch--indent-rigidly part-beg + part-end + (* notmuch-show-indent-messages-width depth))) + (goto-char part-end) + (delete-char 1) + (notmuch-show-record-part-information (cadr part-args) + (button-start button) + part-end) + ;; Create the overlay. If the lazy-part turned out to be empty/not + ;; showable this returns nil. + (notmuch-show-create-part-overlays button part-beg part-end)))) + ) + ;;; Packages @@ -173,7 +283,6 @@ the saved search as well." :preface (defdir notmuch/ (sync/ "emacs/notmuch/") "Notmuch configuration directory." :makedir) - :bind (("C-c m" . notmuch-mua-new-mail)) :config ;; Options (setopt notmuch-init-file (notmuch/ "notmuch-init.el" t) @@ -196,6 +305,7 @@ the saved search as well." notmuch-saved-searches nil notmuch-poll-script "~/usr/scripts/syncmail" ; XXX: Deprecated option ) + (load notmuch-init-file) ;; Key bindings (keymap-set notmuch-search-mode-map "!" #'+notmuch-search-mark-spam) (keymap-set notmuch-search-mode-map "RET" #'notmuch-search-show-thread) @@ -221,6 +331,7 @@ the saved search as well." (+notmuch-define-saved-search "all mail" "a" 'tree "*") ;; Hooks and advice (add-hook 'message-send-hook #'+message-send-set-variables) + (add-hook 'message-send-hook #'email-pre-send-check-attachment) (add-hook 'message-setup-hook #'+message-signature-setup) (autoload 'visual-fill-column-mode "visual-fill-column" nil t) (add-hook 'notmuch-message-mode-hook #'visual-fill-column-mode) -- cgit 1.4.1-21-gabe81