[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/gnorb 32ecc09 026/449: gnorb-org.el: gnorb-org-handle-m
From: |
Stefan Monnier |
Subject: |
[elpa] externals/gnorb 32ecc09 026/449: gnorb-org.el: gnorb-org-handle-mail, gnorb-org-email-subtree |
Date: |
Fri, 27 Nov 2020 23:15:01 -0500 (EST) |
branch: externals/gnorb
commit 32ecc09bc17c1bd8ee9c1efc88cfb0f3d9f649a6
Author: Eric Abrahamsen <eric@ericabrahamsen.net>
Commit: Eric Abrahamsen <eric@ericabrahamsen.net>
gnorb-org.el: gnorb-org-handle-mail, gnorb-org-email-subtree
Refactoring of these two functions, they now share more functionality.
Not actually sure that's a good thing -- going to use them for a while
and see.
---
lisp/gnorb-org.el | 88 +++++++++++++++++++++++++++++++++++--------------------
1 file changed, 56 insertions(+), 32 deletions(-)
diff --git a/lisp/gnorb-org.el b/lisp/gnorb-org.el
index ff8297c..8ade90f 100644
--- a/lisp/gnorb-org.el
+++ b/lisp/gnorb-org.el
@@ -61,15 +61,8 @@ point."
(when (member todo gnorb-org-mail-todos)
(call-interactively 'org-agenda-todo))))
-(defun gnorb-org-handle-mail (&optional from-agenda)
- "Handle mail-related links for current headline."
- (interactive)
- (unless (org-back-to-heading t)
- (error "Not in an org item"))
- (unless from-agenda
- ;; window conf should return to the agenda.
- (setq gnorb-org-window-conf (current-window-configuration)))
- (let (message mailto)
+(defsubst gnorb-org-extract-mail-stuff ()
+ (let (message mails)
(while (re-search-forward org-any-link-re (line-end-position) t)
(let ((addr (or (match-string-no-properties 2)
(match-string-no-properties 0))))
@@ -77,32 +70,56 @@ point."
((string-match "^<?gnus:" addr)
(push (substring addr (match-end 0)) message))
((string-match "^<?mailto:" addr)
- (push (substring addr (match-end 0)) mailto))
+ (push (substring addr (match-end 0)) mails))
((string-match-p "^<?bbdb:" addr)
(with-current-buffer bbdb-buffer-name
(let ((recs bbdb-records))
(org-open-link-from-string addr)
(let ((mail (bbdb-mail-address (bbdb-current-record))))
(bbdb-display-records recs)
- (push mail mailto))))))))
- (cond
- (message
- (org-gnus-open (org-link-unescape (car message)))
- (call-interactively
- 'gnus-summary-wide-reply-with-original)
- (when mailto
- (message-goto-to)
- (insert ", ")
- (insert (mapconcat 'identity mailto ", ")))
- (add-to-list 'message-exit-actions
- 'gnorb-org-restore-after-send t)
- (message-goto-body))
- (mailto
- (compose-mail (mapconcat 'identity mailto ", ")
+ (push mail mails))))))))
+ (list message mails)))
+
+(defsubst gnorb-org-setup-message (message mails)
+ (if (not message)
+ (compose-mail (mapconcat 'identity mails ", ")
nil nil nil nil nil nil
- 'gnorb-org-restore-after-send))
- (t
- (error "No mail-related links in headline")))))
+ 'gnorb-org-restore-after-send)
+ (org-gnus-open (org-link-unescape (car message)))
+ (call-interactively
+ 'gnus-summary-wide-reply-with-original)
+ (when mails
+ (message-goto-to)
+ (insert ", ")
+ (insert (mapconcat 'identity mails ", ")))
+ (add-to-list 'message-exit-actions
+ 'gnorb-org-restore-after-send t)
+ (message-goto-body)))
+
+(defsubst gnorb-org-attachment-list ()
+ (when (featurep 'org-attach)
+ (let* ((attach-dir (org-attach-dir t))
+ (files (org-attach-file-list attach-dir)))
+ files)))
+
+(defun gnorb-org-handle-mail (&optional from-agenda)
+ "Handle mail-related links for current headline."
+ (interactive)
+ (unless (org-back-to-heading t)
+ (error "Not in an org item"))
+ (unless from-agenda
+ ;; window conf should return to the agenda.
+ (setq gnorb-org-window-conf (current-window-configuration)))
+ (let ((mail-stuff (gnorb-org-extract-mail-stuff))
+ (attachments (gnorb-org-attachment-list)))
+ (gnorb-org-setup-message (first mail-stuff) (second mail-stuff))
+ (message-goto-body)
+ (when attachments
+ (dolist (a attachments)
+ (and (yes-or-no-p (format "Attach %s to outgoing message? " a))
+ (mml-attach-file a
+ (mm-default-file-encoding a)
+ nil "attachment"))))))
(defun gnorb-org-handle-mail-agenda ()
"Examine item at point for mail-related links, and handle them."
@@ -171,6 +188,7 @@ default set of parameters."
;; I sure would have liked to use the built-in dispatch ui, but it's
;; got too much hard-coded stuff.
(interactive)
+ (org-back-to-heading t)
(let* ((backend-string
(org-completing-read
"Export backend: "
@@ -197,10 +215,11 @@ default set of parameters."
(second (assoc backend-symbol
gnorb-org-export-extensions))
t gnorb-tmp-dir)
,@opts
- ,gnorb-org-email-subtree-parameters)))))
+ ,gnorb-org-email-subtree-parameters))))
+ (mail-stuff (gnorb-org-extract-mail-stuff))
+ (attachments (gnorb-org-attachment-list)))
(setq gnorb-org-window-conf (current-window-configuration))
- (compose-mail nil nil nil nil nil nil nil
- 'org-gnorb-restore-after-send)
+ (gnorb-org-setup-message (first mail-stuff) (second mail-stuff))
(message-goto-body)
(insert "\n")
(if (equal f-or-b "text")
@@ -209,7 +228,12 @@ default set of parameters."
result
(mm-default-file-encoding result)
nil "attachment"))
- (message-goto-to)))
+ (when attachments
+ (dolist (a attachments)
+ (and (yes-or-no-p (format "Attach %s to outgoing message? " a))
+ (mml-attach-file a
+ (mm-default-file-encoding a)
+ nil "attachment"))))))
(provide 'gnorb-org)
;;; gnorb-org.el ends here
- [elpa] externals/gnorb ba4ec1b 004/449: Add customization skeleton., (continued)
- [elpa] externals/gnorb ba4ec1b 004/449: Add customization skeleton., Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb 1b037b7 006/449: gnorb-utils.el: Common utility file., Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb d090df9 007/449: gnorb-bbdb.el: New function gnorb-bbdb-mail-search, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb cc208a0 010/449: gnorb-bbdb.el: (gnorb-bbdb-mail-search), Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb 869940a 015/449: README.org: Change file format to Org mode, expand docs, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb 3429f3b 009/449: gnorb-org.el: (gnorb-org-contact-link), Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb b7dce0b 016/449: gnorb-utils.el: Require the cl library., Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb d79617f 019/449: gnorb-org.el: Email current subtree as exported text or file, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb 27d08ef 022/449: README.org: Reorganize README, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb 3edf1c9 025/449: gnorb-utils.el: gnorb-prompt-for-bbdb-record, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb 32ecc09 026/449: gnorb-org.el: gnorb-org-handle-mail, gnorb-org-email-subtree,
Stefan Monnier <=
- [elpa] externals/gnorb 123b521 031/449: gnorb-org.el: bugfix gnorb-org-restore-after-send, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb a9c7410 032/449: gnorb-gnus.el: bugfix gnorb-gnus-attach-part, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb 5adcc84 008/449: gnorb-utils: (gnorb-prompt-for-bbdb-record), Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb bedce9d 012/449: gnorb-gnus.el: (gnorb-gnus(article|mime)-org-attach), Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb d28a099 005/449: gnorb-bbdb.el: New function gnorb-bbdb-tag-agenda, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb 63ac8f6 011/449: gnorb-org.el: (gnorb-org-handle-mail, gnorb-org-handle-mail-agenda), Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb c2b1a3a 013/449: Docstring for gnorb-org-contact-link, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb d4987a7 014/449: gnorb-utils.el: More likely requires for Org libraries, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb 62368b7 017/449: gnorb-gnus.el: Make attachment fiddling work in org capture, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb da7cf10 018/449: gnorb-utils.el: Require mailcap, and parse, Stefan Monnier, 2020/11/27