diff options
Diffstat (limited to 'lisp/acdw-mail.el')
-rw-r--r-- | lisp/acdw-mail.el | 113 |
1 files changed, 112 insertions, 1 deletions
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 @@ | |||
25 | (defun +message-send-set-variables () | 25 | (defun +message-send-set-variables () |
26 | "Set variables for `message-send' depending on the From: header. | 26 | "Set variables for `message-send' depending on the From: header. |
27 | Useful in `message-send-hook'." | 27 | Useful in `message-send-hook'." |
28 | (unless +message-send-dispatch-rules | ||
29 | (load notmuch-init-file) | ||
30 | (or +message-send-dispatch-rules | ||
31 | (error "`+message-send-dispatch-rules' isn't set!"))) | ||
28 | (let ((from (message-fetch-field "from"))) | 32 | (let ((from (message-fetch-field "from"))) |
29 | (cl-loop for (var . val) in (cl-loop for (address . bindings) | 33 | (cl-loop for (var . val) in (cl-loop for (address . bindings) |
30 | in +message-send-dispatch-rules | 34 | in +message-send-dispatch-rules |
@@ -145,6 +149,112 @@ the saved search as well." | |||
145 | ;;(user-error "Feature `async' not found!") | 149 | ;;(user-error "Feature `async' not found!") |
146 | (notmuch-poll))) | 150 | (notmuch-poll))) |
147 | 151 | ||
152 | ;;; https://kitchingroup.cheme.cmu.edu/blog/2015/09/04/Checking-for-email-attachments-before-you-send-email/ | ||
153 | |||
154 | (defun email-says-attach-p () | ||
155 | "Return t if email suggests there could be an attachment." | ||
156 | (save-excursion | ||
157 | (goto-char (point-min)) | ||
158 | (re-search-forward "attach" nil t))) | ||
159 | |||
160 | (defun email-has-attachment-p () | ||
161 | "Return t if the currently open email has an attachment." | ||
162 | (save-excursion | ||
163 | (goto-char (point-min)) | ||
164 | (re-search-forward "<#part" nil t))) | ||
165 | |||
166 | (defun email-pre-send-check-attachment () | ||
167 | (when (and (email-says-attach-p) | ||
168 | (not (email-has-attachment-p))) | ||
169 | (unless | ||
170 | (y-or-n-p | ||
171 | "Your email suggests an attachment, but none was found. Send anyway?") | ||
172 | (error "No attachment. Aborting send.")))) | ||
173 | |||
174 | ;;; Process ical attachments | ||
175 | |||
176 | (defun notmuch-save-ics () | ||
177 | "Save a .ics file in a message." | ||
178 | (interactive) | ||
179 | (with-current-notmuch-show-message | ||
180 | (notmuch-foreach-mime-part | ||
181 | (lambda (part) | ||
182 | (message "%S" part) | ||
183 | (when (and (listp part) | ||
184 | (or (equal "application/ics" (caadr part)) | ||
185 | ;; (equal "text/calendar" (caadr part)) | ||
186 | )) | ||
187 | (save-window-excursion | ||
188 | (let* ((filename "/tmp/notmuch.ics") | ||
189 | (buf (find-file-noselect filename))) | ||
190 | (delete-file filename) | ||
191 | (kill-buffer (get-file-buffer filename)) | ||
192 | (mm-save-part-to-file part filename) | ||
193 | (icalendar-import-file filename diary-file) | ||
194 | (kill-buffer buf))))) | ||
195 | (mm-dissect-buffer t t)))) | ||
196 | |||
197 | |||
198 | ;;; Fixes | ||
199 | |||
200 | ;; https://nmbug.notmuchmail.org/nmweb/show/87bklhricc.fsf%40tethera.net | ||
201 | |||
202 | (defun notmuch--indent-rigidly (start end count) | ||
203 | (cond | ||
204 | ((zerop count) t) | ||
205 | ((< count 0) (indent-rigidly start end count)) | ||
206 | (t | ||
207 | (save-excursion | ||
208 | (let ((startpt (progn (goto-char start) (line-beginning-position))) | ||
209 | (endpt (progn (goto-char end) (line-end-position))) | ||
210 | (spaces (spaces-string count))) | ||
211 | (goto-char startpt) | ||
212 | (while | ||
213 | (progn | ||
214 | (insert spaces) | ||
215 | (cl-incf endpt count) | ||
216 | (and (zerop (forward-line 1)) (bolp) | ||
217 | (<= (point) endpt))))))))) | ||
218 | |||
219 | (with-eval-after-load 'notmuch-show | ||
220 | ;; Redefine `notmuch-show-lazy-part' --- XXX: this is the most braindead way | ||
221 | ;; of doing this | ||
222 | (defun notmuch-show-lazy-part (part-args button) | ||
223 | ;; Insert the lazy part after the button for the part. We would just | ||
224 | ;; move to the start of the new line following the button and insert | ||
225 | ;; the part but that point might have text properties (eg colours | ||
226 | ;; from a message header etc) so instead we start from the last | ||
227 | ;; character of the button by adding a newline and finish by | ||
228 | ;; removing the extra newline from the end of the part. | ||
229 | (save-excursion | ||
230 | (goto-char (button-end button)) | ||
231 | (insert "\n") | ||
232 | (let* ((inhibit-read-only t) | ||
233 | ;; We need to use markers for the start and end of the part | ||
234 | ;; because the part insertion functions do not guarantee | ||
235 | ;; to leave point at the end of the part. | ||
236 | (part-beg (copy-marker (point) nil)) | ||
237 | (part-end (copy-marker (point) t)) | ||
238 | ;; We have to save the depth as we can't find the depth | ||
239 | ;; when narrowed. | ||
240 | (depth (notmuch-show-get-depth))) | ||
241 | (save-restriction | ||
242 | (narrow-to-region part-beg part-end) | ||
243 | (delete-region part-beg part-end) | ||
244 | (apply #'notmuch-show-insert-bodypart-internal part-args) | ||
245 | (notmuch--indent-rigidly part-beg | ||
246 | part-end | ||
247 | (* notmuch-show-indent-messages-width depth))) | ||
248 | (goto-char part-end) | ||
249 | (delete-char 1) | ||
250 | (notmuch-show-record-part-information (cadr part-args) | ||
251 | (button-start button) | ||
252 | part-end) | ||
253 | ;; Create the overlay. If the lazy-part turned out to be empty/not | ||
254 | ;; showable this returns nil. | ||
255 | (notmuch-show-create-part-overlays button part-beg part-end)))) | ||
256 | ) | ||
257 | |||
148 | 258 | ||
149 | ;;; Packages | 259 | ;;; Packages |
150 | 260 | ||
@@ -173,7 +283,6 @@ the saved search as well." | |||
173 | :preface (defdir notmuch/ (sync/ "emacs/notmuch/") | 283 | :preface (defdir notmuch/ (sync/ "emacs/notmuch/") |
174 | "Notmuch configuration directory." | 284 | "Notmuch configuration directory." |
175 | :makedir) | 285 | :makedir) |
176 | :bind (("C-c m" . notmuch-mua-new-mail)) | ||
177 | :config | 286 | :config |
178 | ;; Options | 287 | ;; Options |
179 | (setopt notmuch-init-file (notmuch/ "notmuch-init.el" t) | 288 | (setopt notmuch-init-file (notmuch/ "notmuch-init.el" t) |
@@ -196,6 +305,7 @@ the saved search as well." | |||
196 | notmuch-saved-searches nil | 305 | notmuch-saved-searches nil |
197 | notmuch-poll-script "~/usr/scripts/syncmail" ; XXX: Deprecated option | 306 | notmuch-poll-script "~/usr/scripts/syncmail" ; XXX: Deprecated option |
198 | ) | 307 | ) |
308 | (load notmuch-init-file) | ||
199 | ;; Key bindings | 309 | ;; Key bindings |
200 | (keymap-set notmuch-search-mode-map "!" #'+notmuch-search-mark-spam) | 310 | (keymap-set notmuch-search-mode-map "!" #'+notmuch-search-mark-spam) |
201 | (keymap-set notmuch-search-mode-map "RET" #'notmuch-search-show-thread) | 311 | (keymap-set notmuch-search-mode-map "RET" #'notmuch-search-show-thread) |
@@ -221,6 +331,7 @@ the saved search as well." | |||
221 | (+notmuch-define-saved-search "all mail" "a" 'tree "*") | 331 | (+notmuch-define-saved-search "all mail" "a" 'tree "*") |
222 | ;; Hooks and advice | 332 | ;; Hooks and advice |
223 | (add-hook 'message-send-hook #'+message-send-set-variables) | 333 | (add-hook 'message-send-hook #'+message-send-set-variables) |
334 | (add-hook 'message-send-hook #'email-pre-send-check-attachment) | ||
224 | (add-hook 'message-setup-hook #'+message-signature-setup) | 335 | (add-hook 'message-setup-hook #'+message-signature-setup) |
225 | (autoload 'visual-fill-column-mode "visual-fill-column" nil t) | 336 | (autoload 'visual-fill-column-mode "visual-fill-column" nil t) |
226 | (add-hook 'notmuch-message-mode-hook #'visual-fill-column-mode) | 337 | (add-hook 'notmuch-message-mode-hook #'visual-fill-column-mode) |