summary refs log tree commit diff
path: root/config.org
diff options
context:
space:
mode:
Diffstat (limited to 'config.org')
-rw-r--r--config.org98
1 files changed, 88 insertions, 10 deletions
diff --git a/config.org b/config.org
index 5866bda..5901aea 100644
--- a/config.org
+++ b/config.org
@@ -549,6 +549,14 @@ If we enable this, emphasis markers will be hidden for a more word processor fee
 #+end_src
 
 #+begin_src elisp
+  (defun noa/org-capture-get-mail-body ()
+    "Returns the body of the current mail shown in rmail buffer as a string.  For us during org-capture."
+    (with-current-buffer (org-capture-get :original-buffer)
+      (save-excursion
+        (goto-char (point-min))
+        (search-forward "\n\n")
+        (buffer-substring-no-properties (point) (point-max)))))
+
   (setopt org-startup-with-inline-images t)
   (setopt org-image-actual-width '(300))
   (setopt org-auto-align-tags nil)
@@ -566,18 +574,44 @@ If we enable this, emphasis markers will be hidden for a more word processor fee
   (setopt org-return-follows-link t)
   (setopt org-agenda-files '("~/data/notes/notes.org"))
   (setopt org-capture-bookmark nil)
-  (setopt org-capture-templates '(("j" "Journal" entry (file+olp+datetree "~/data/notes/notes.org") "* %?\n" :empty-lines 1)
-                                  ("w" "Website" entry (file+olp+datetree "~/data/notes/notes.org") "* %a\n%?\n" :empty-lines 1)
-                                  ("c" "Contact" entry (file+olp+datetree "~/data/notes/notes.org")
-                                   "* %^{Name}
+  (setopt org-capture-templates
+          '(("j" "Journal" entry (file+olp+datetree "~/data/notes/notes.org") "* %?\n" :empty-lines 1)
+            
+            ("l" "Website" entry (file+olp+datetree "~/data/notes/notes.org") "* %a\n%?\n" :empty-lines 1)
+            
+            ("M" "Mail" entry (file+olp+datetree "~/data/notes/notes.org") "* %:fromname—%:subject :mail:%^g
+      :PROPERTIES:
+      :MAIL_TO: %:to
+      :MAIL_FROM: %:from
+      :MAIL_DATE: %:date
+      :MAIL_SUBJECT: %:subject
+      :MAIL_MESSAGE_ID: %:message-id
+      :END:
+
+      %?%(noa/org-capture-get-mail-body)\n" :empty-lines 1 :immediate-finish t)
+            
+            ("m" "Compose mail" entry (file+olp+datetree "~/data/notes/notes.org") "* Email
   :PROPERTIES:
-  :ADDRESS: %^{Address}
-  :BIRTHDAY: %^{yyyy-mm-dd}
-  :EMAIL: %^{EMAIL}p
-  :NOTE: %^{NOTE}
+  :MAIL_TO: %?
+  :MAIL_SUBJECT:
+  :MAIL_FROM: noa <noa@noa.pub>
   :END:"
-                                   :empty-lines 1)
-                                  ))
+             :empty-lines 1
+             :jump-to-captured t
+             :immediate-finish t
+             )
+            
+            ("r" "Reply to this mail" entry (file+olp+datetree "~/data/notes/notes.org") "* TODO Reply to %:fromname—%:subject :mail:
+  :PROPERTIES:
+  :MAIL_TO: %:from
+  :MAIL_FROM: %:to
+  :MAIL_SUBJECT: %:subject
+  :MAIL_IN_REPLY_TO: %:message-id
+  :END:
+
+  %?%(noa/org-capture-get-mail-body)\n"
+             :empty-lines 1
+             :immediate-finish t)))
 #+end_src
 
 #+begin_src elisp
@@ -1834,6 +1868,50 @@ I have experimented with lots of different methods of reading mail, both in and
   (setopt mairix-search-file "search.mbox")
 #+end_src
 
+** Composing mail from an org buffer
+As i keep mentioning, i have a big org file which i put everything into.  This includes interesting web articles, which i will paraphrase or quote.  However, this does not include mail, because mail is a bit of a beast.
+
+I have written this function as the first step in bridging that gap.  I can compose an email in org, via an org-capture template that will prompt me for a recipient and subject.  Then i can send the subtree to the mail buffer.
+
+At the moment, i am still recording sent mail in the outbox directory of my mail directory.  This is because at the moment i don't have a way to move whole emails from rmail to org (although i think there are ways to do that, and i have added the in_reply_to header for the future).
+
+#+begin_src elisp
+  (defun noa/org-mail-subtree ()
+    "Prepare a mail buffer to send the current subtree as an email.  Respects the headline properties MAIL_SUBJECT MAIL_TO MAIL_CC MAIL_BCC MAIL_FROM."
+    (interactive)
+    (save-excursion
+      (let* ((subject (org-entry-get nil "MAIL_SUBJECT" nil))
+             (to (org-entry-get nil "MAIL_TO" nil))
+             (from (org-entry-get nil "MAIL_FROM"))
+             (cc (org-entry-get nil "MAIL_CC" nil))
+             (bcc (org-entry-get nil "MAIL_BCC" nil))
+             (in-reply-to (org-entry-get nil "MAIL_IN_REPLY_TO" nil))
+             (other-headers (list (cons "Cc" cc)
+                                  (cons "Bcc" bcc)
+                                  (cons "From" from )
+                                  (cons "In-Reply-To" in-reply-to)))
+             (body (save-restriction (org-narrow-to-subtree)
+                                     (beginning-of-buffer)
+                                     (search-forward-regexp ":END:\n*")
+                                     (buffer-substring (point) (point-max)))))
+        (compose-mail to subject other-headers)
+        (message-goto-body)
+        (insert body))
+      (message-goto-to)))
+#+end_src
+
+#+begin_src elisp
+  (defun noa/org-compose-mail ()
+    "Launch an org buffer to compose a mail."
+    (interactive)
+    (org-capture nil "m"))
+
+  (defun noa/org-todo-reply-mail ()
+    "Capture the current mail as a todo ready to be replied to."
+    (interactive)
+    (org-capture nil "r"))
+#+end_src
+
 ** Sending mail with msmtp
 #+begin_src elisp
   (setopt message-send-mail-function 'message-send-mail-with-sendmail)