branch: elpa/org-mime
commit ffbf3e3e47f83295a55d5728b28ee74ae63ade71
Author: Anthony Cowley <[email protected]>
Commit: Anthony Cowley <[email protected]>

    Support mime encoding current subtree
    
    This doesn't require that the user explicitly narrow to a subtree, and
    it adds support for export options set as properties on the subtree.
    
    The latter is fairly crucial as it lets one do things such as suppress
    table of contents generation on a subtree without doing so for the
    entire document.
---
 org-mime.el | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/org-mime.el b/org-mime.el
index 1a15d3bf15..f81bbba44b 100644
--- a/org-mime.el
+++ b/org-mime.el
@@ -98,10 +98,10 @@ buffer holding\nthe text to be exported.")
 (defvar org-mime-send-buffer-hook nil
   "Hook to run in the Org-mode file before export.")
 
-(defun org-mime--export-string (s)
+(defun org-mime--export-string (s &optional opts)
   (if (fboundp 'org-export-string-as)
       ;; emacs24
-      (org-export-string-as s 'html t)
+      (org-export-string-as s 'html t opts)
     ;; emacs 23
     (org-export-string s "html")))
 
@@ -251,7 +251,17 @@ export that region, otherwise export the entire body."
         (body (buffer-substring body-start body-end)))
     (org-mime-compose body file nil subject)))
 
-(defun org-mime-compose (body file &optional to subject headers)
+(defun org-mime-send-subtree ()
+  (run-hooks 'org-mime-send-buffer-hook)
+  (save-excursion
+    (org-up-heading-safe)
+    (let* ((file (buffer-file-name (current-buffer)))
+           (subject (nth 4 (org-heading-components)))
+           (opts (org-export--get-subtree-options))
+           (body (org-get-entry)))
+      (org-mime-compose body file nil subject nil opts))))
+
+(defun org-mime-compose (body file &optional to subject headers opts)
   (let* ((fmt 'html))
     (unless (featurep 'message)
       (require 'message))
@@ -271,7 +281,7 @@ export that region, otherwise export the entire body."
              (org-export-htmlize-output-type 'inline-css)
              (html-and-images
               (org-mime-replace-images
-               (org-mime--export-string (bhook body 'html)) file))
+               (org-mime--export-string (bhook body 'html) opts) file))
              (images (cdr html-and-images))
              (html (org-mime-apply-html-hook (car html-and-images))))
         (insert (org-mime-multipart (org-babel-trim body) html)
@@ -284,5 +294,12 @@ export that region, otherwise export the entire body."
   (interactive)
   (org-mime-send-buffer))
 
+(defun org-mime-org-subtree-htmlize ()
+  "Create an email buffer containing the current subtree of the
+  current org-mode file exported to html and encoded in both html
+  and in org formats as mime alternatives."
+  (interactive)
+  (org-mime-send-subtree))
+
 (provide 'org-mime)
 ;;; org-mime.el ends here

Reply via email to