emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/org-mime 4105d1bb9c 004/118: support Emacs 23.4, 24.3 24.4


From: ELPA Syncer
Subject: [nongnu] elpa/org-mime 4105d1bb9c 004/118: support Emacs 23.4, 24.3 24.4, 24.5
Date: Wed, 5 Jan 2022 07:58:41 -0500 (EST)

branch: elpa/org-mime
commit 4105d1bb9ca3712f403f5c47c1ec1c74f3749f0e
Author: Chen Bin <chenbin.sh@gmail.com>
Commit: Chen Bin <chenbin.sh@gmail.com>

    support Emacs 23.4, 24.3 24.4, 24.5
    
    - remove ascii, org export (24.4+ issue)
    - `org-export-as-string` only use hard coded parameter (24.4+ issue)
---
 org-mime.el | 152 +++++++++++++++++++-----------------------------------------
 1 file changed, 48 insertions(+), 104 deletions(-)

diff --git a/org-mime.el b/org-mime.el
index d9e14d1fd7..20d903b408 100644
--- a/org-mime.el
+++ b/org-mime.el
@@ -6,7 +6,7 @@
 ;; Maintainer: Chen Bin (redguardtoo)
 ;; Keywords: mime, mail, email, html
 ;; Homepage: http://github.com/redguardtoo/org-mime
-;; Version: 0.0.2
+;; Version: 0.0.3
 
 ;; This file is not part of GNU Emacs.
 
@@ -59,13 +59,10 @@
 ;;               (local-set-key (kbd "C-c M-o") 'org-mime-org-buffer-htmlize)))
 
 ;;; Code:
-(require 'cl)
-(require 'org)
+(eval-when-compile
+  (require 'cl))
 
-(defcustom org-mime-use-property-inheritance nil
-  "Non-nil means al MAIL_ properties apply also for sublevels."
-  :group 'org-mime
-  :type 'boolean)
+(require 'org)
 
 (defcustom org-mime-default-header
   "#+OPTIONS: latex:t\n"
@@ -91,33 +88,24 @@
   :group 'org-mime
   :type 'string)
 
-(defcustom org-mime-html-hook nil
+(defvar org-mime-html-hook nil
   "Hook to run over the html buffer before attachment to email.
-  This could be used for example to post-process html elements."
-  :group 'org-mime
-  :type 'hook)
+This could be used for example to post-process html elements.")
 
-(mapc (lambda (fmt)
-       (eval `(defcustom
-                ,(intern (concat "org-mime-pre-" fmt "-hook"))
-                nil
-                (concat "Hook to run before " fmt " export.\nFunctions "
-                        "should take no arguments and will be run in a "
-                        "buffer holding\nthe text to be exported."))))
-      '("ascii" "org" "html"))
+(defvar org-mime-pre-html-hook nil
+  "Hook to run before html export.
+Functions should take no arguments and will be run in a
+buffer holding\nthe text to be exported.")
 
-(defcustom org-mime-send-subtree-hook nil
-  "Hook to run in the subtree in the Org-mode file before export.")
-
-(defcustom org-mime-send-buffer-hook nil
+(defvar org-mime-send-buffer-hook nil
   "Hook to run in the Org-mode file before export.")
 
-(defun org-mime--export-string (s fmt)
+(defun org-mime--export-string (s)
   (if (fboundp 'org-export-string-as)
-      ;; emacs23
-      (org-export-string-as s (make-symbol fmt) t)
-    ;; emacs 24
-    (org-export-string s fmt)))
+      ;; emacs24
+      (org-export-string-as s 'html t)
+    ;; emacs 23
+    (org-export-string s "html")))
 
 ;; example hook, for setting a dark background in <pre 
style="background-color: #EEE;"> elements
 (defun org-mime-change-element-style (element style)
@@ -216,11 +204,10 @@ export that region, otherwise export the entire body."
          (html-end (or (and region-p (region-end))
                        ;; TODO: should catch signature...
                        (point-max)))
-         (raw-body (concat org-mime-default-header
+         (body (concat org-mime-default-header
                           (buffer-substring html-start html-end)))
          (tmp-file (make-temp-name (expand-file-name
                                    "mail" temporary-file-directory)))
-         (body (org-mime--export-string raw-body "org"))
          ;; because we probably don't want to export a huge style file
          (org-export-htmlize-output-type 'inline-css)
          ;; makes the replies with ">"s look nicer
@@ -230,7 +217,7 @@ export that region, otherwise export the entire body."
          ;; to hold attachments for inline html images
          (html-and-images
           (org-mime-replace-images
-          (org-mime--export-string raw-body "html") tmp-file))
+          (org-mime--export-string body) tmp-file))
          (html-images (unless arg (cdr html-and-images)))
          (html (org-mime-apply-html-hook
                 (if arg
@@ -254,28 +241,7 @@ export that region, otherwise export the entire body."
 (defmacro org-mime-try (&rest body)
   `(condition-case nil ,@body (error nil)))
 
-(defun org-mime-send-subtree (&optional fmt)
-  (save-restriction
-    (org-narrow-to-subtree)
-    (run-hooks 'org-mime-send-subtree-hook)
-    (flet ((mp (p) (org-entry-get nil p org-mime-use-property-inheritance)))
-      (let* ((file (buffer-file-name (current-buffer)))
-            (subject (or (mp "MAIL_SUBJECT") (nth 4 (org-heading-components))))
-            (to (mp "MAIL_TO"))
-            (cc (mp "MAIL_CC"))
-            (bcc (mp "MAIL_BCC"))
-            (body (buffer-substring
-                   (save-excursion (goto-char (point-min))
-                                   (forward-line 1)
-                                   (when (looking-at "[ \t]*:PROPERTIES:")
-                                     (re-search-forward ":END:" nil)
-                                     (forward-char))
-                                   (point))
-                   (point-max))))
-       (org-mime-compose body (or fmt 'org) file to subject
-                         `((cc . ,cc) (bcc . ,bcc)))))))
-
-(defun org-mime-send-buffer (&optional fmt)
+(defun org-mime-send-buffer ()
   (run-hooks 'org-mime-send-buffer-hook)
   (let* ((region-p (org-region-active-p))
         (subject (org-export-grab-title-from-buffer))
@@ -285,62 +251,40 @@ export that region, otherwise export the entire body."
          (body-end (or (and region-p (region-end)) (point-max)))
         (temp-body-file (make-temp-file "org-mime-export"))
         (body (buffer-substring body-start body-end)))
-    (org-mime-compose body (or fmt 'org) file nil subject)))
-
-(defun org-mime-compose (body fmt file &optional to subject headers)
-  (unless (featurep 'message)
-    (require 'message))
-  (message-mail to subject headers nil)
-  (message-goto-body)
-  (flet ((bhook (body fmt)
-               (let ((hook (intern (concat "org-mime-pre-"
-                                           (symbol-name fmt)
-                                           "-hook"))))
-                 (if (> (eval `(length ,hook)) 0)
-                     (with-temp-buffer
-                       (insert body)
-                       (goto-char (point-min))
-                       (eval `(run-hooks ',hook))
-                       (buffer-string))
-                   body))))
-    (let ((fmt (if (symbolp fmt) fmt (intern fmt))))
-      (cond
-       ((eq fmt 'org)
-       (insert (org-mime--export-string
-                (org-babel-trim (bhook body 'org)) "org")))
-       ((eq fmt 'ascii)
-       (insert (org-mime--export-string
-                (concat "#+Title:\n" (bhook body 'ascii)) "ascii")))
-       ((or (eq fmt 'html) (eq fmt 'html-ascii))
-       (let* ((org-link-file-path-type 'absolute)
-              ;; we probably don't want to export a huge style file
-              (org-export-htmlize-output-type 'inline-css)
-              (html-and-images
-               (org-mime-replace-images
-                (org-mime--export-string (bhook body 'html) "html") file))
-              (images (cdr html-and-images))
-              (html (org-mime-apply-html-hook (car html-and-images))))
-         (insert (org-mime-multipart
-                  (org-mime--export-string
-                   (org-babel-trim
-                    (bhook body (if (eq fmt 'html) "org" "ascii")))
-                   (if (eq fmt 'html) 'org 'ascii) t)
-                  html)
-                 (mapconcat 'identity images "\n"))))))))
+    (org-mime-compose body file nil subject)))
+
+(defun org-mime-compose (body file &optional to subject headers)
+  (let* ((fmt 'html))
+    (unless (featurep 'message)
+      (require 'message))
+    (message-mail to subject headers nil)
+    (message-goto-body)
+    (flet ((bhook (body fmt)
+                  (let ((hook 'org-mime-pre-html-hook))
+                    (if (> (eval `(length ,hook)) 0)
+                        (with-temp-buffer
+                          (insert body)
+                          (goto-char (point-min))
+                          (eval `(run-hooks ',hook))
+                          (buffer-string))
+                      body))))
+      (let* ((org-link-file-path-type 'absolute)
+             ;; we probably don't want to export a huge style file
+             (org-export-htmlize-output-type 'inline-css)
+             (html-and-images
+              (org-mime-replace-images
+               (org-mime--export-string (bhook body 'html)) 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)
+                (mapconcat 'identity images "\n"))))))
 
 (defun org-mime-org-buffer-htmlize ()
   "Create an email buffer containing the current org-mode file
   exported to html and encoded in both html and in org formats as
   mime alternatives."
   (interactive)
-  (org-mime-send-buffer 'html))
-
-(defun org-mime-subtree ()
-  "Create an email buffer containing the current org-mode subtree
-  exported to a org format or to the format specified by the
-  MAIL_FMT property of the subtree."
-  (interactive)
-  (org-mime-send-subtree
-   (or (org-entry-get nil "MAIL_FMT" org-mime-use-property-inheritance) 'org)))
+  (org-mime-send-buffer))
 
 (provide 'org-mime)
+;;; org-mime.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]