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

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

[nongnu] elpa/org-mime f8eac8ccde 066/118: restore plain text mail


From: ELPA Syncer
Subject: [nongnu] elpa/org-mime f8eac8ccde 066/118: restore plain text mail
Date: Wed, 5 Jan 2022 07:58:47 -0500 (EST)

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

    restore plain text mail
---
 README.org  |  2 +-
 org-mime.el | 89 +++++++++++++++++++++++++++++++------------------------------
 2 files changed, 46 insertions(+), 45 deletions(-)

diff --git a/README.org b/README.org
index e1e74a3375..97c1761d01 100644
--- a/README.org
+++ b/README.org
@@ -1,4 +1,4 @@
-* org-mime v0.1.5
+* org-mime v0.1.6
 
 
[[https://travis-ci.org/org-mime/org-mime][https://travis-ci.org/org-mime/org-mime.svg?branch=master]]
 
[[http://melpa.org/#/org-mime][file:http://melpa.org/packages/org-mime-badge.svg]]
 
[[http://stable.melpa.org/#/org-mime][file:http://stable.melpa.org/packages/org-mime-badge.svg]]
diff --git a/org-mime.el b/org-mime.el
index 009c8cab53..2eadbae042 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/org-mime/org-mime
-;; Version: 0.1.5
+;; Version: 0.1.6
 ;; Package-Requires: ((emacs "24.4") (cl-lib "0.5"))
 
 ;; This file is not part of GNU Emacs.
@@ -185,29 +185,28 @@ buffer holding the text to be exported.")
   (buffer-substring-no-properties (line-beginning-position)
                                   (line-end-position)))
 
-(defun org-mime-get-exported-content (subtreep)
+(defun org-mime-export-buffer-or-subtree (subtreep)
   "Similar to `org-html-export-as-html' and `org-org-export-as-org'.
 SUBTREEP is t if current node is subtree."
-  (let* ((buf (org-export-to-buffer 'html "*Org Mime Export*"
+  (let* ((plain (buffer-string))
+         (buf (org-export-to-buffer 'html "*Org Mime Export*"
                 nil subtreep nil (org-mime-get-export-options subtreep)))
          (body (prog1
                    (with-current-buffer buf
-                     (format "#+BEGIN_EXPORT html\n%s\n#+END_EXPORT"
-                             (buffer-string)))
+                     (buffer-string))
                  (kill-buffer buf))))
-    body))
+    (cons body plain)))
 
-(defun org-mime--export-string (s fmt &optional opts)
-  "Export string S using FMT as the backend.
+(defun org-mime-export-string (string &optional opts)
+  "Export STRING into html.
 OPTS is export options."
   ;; Emacs 25+ prefer exporting drawer by default
   ;; obviously not acceptable in exporting to mail body
   (let* ((org-export-with-drawers nil))
-    (when org-mime-debug (message "org-mime--export-string called => %s" opts))
     ;; we won't export title from org file anyway
     (if opts (setq opts (plist-put opts 'title nil)))
     ;; emacs24.4+
-    (org-export-string-as s fmt t (or org-mime-export-options opts))))
+    (org-export-string-as string 'html t (or org-mime-export-options opts))))
 
 ;; example hook, for setting a dark background in
 ;; <pre style="background-color: #EEE;"> elements
@@ -278,11 +277,12 @@ HTML is the body of the message."
         (forward-line))
       (buffer-substring (point-min) (point-max)))))
 
-(defun org-mime-multipart (html &optional images)
+(defun org-mime-multipart (plain html &optional images)
   "Markup a multipart/alternative with HTML alternatives.
 If html portion of message includes IMAGES they are wrapped in 
multipart/related part."
   (cl-case org-mime-library
-    (mml (concat "<#multipart type=alternative>"
+    (mml (concat "<#multipart type=alternative>\n<#part type=text/plain>"
+                 plain
                  (when images "<#multipart type=related>")
                  "<#part type=text/html>"
                  (if org-mime-beautify-quoted-mail
@@ -293,6 +293,7 @@ If html portion of message includes IMAGES they are wrapped 
in multipart/related
                  "<#/multipart>\n"))
     (semi (concat
            "--" "<<alternative>>-{\n"
+           "--" "[[text/plain]]\n" plain
            (when images (concat "--" "<<alternative>>-{\n"))
            "--" "[[text/html]]\n"  html
            images
@@ -356,7 +357,8 @@ CURRENT-FILE is used to calculate full path of images."
     (message "Warning: org-element-map is not available. File links will not 
be attached.")
     nil)))
 
-(defun org-mime-insert-html-content (body file s opts)
+(defun org-mime-insert-html-content (plain file html opts)
+  "Insert HTML content."
   (let* ((files (org-mime-extract-non-image-files))
          ;; dvipng for inline latex because MathJax doesn't work in mail
          ;; Also @see https://github.com/org-mime/org-mime/issues/16
@@ -365,14 +367,13 @@ CURRENT-FILE is used to calculate full path of images."
          ;; we don't want to convert org file links to html
          (org-html-link-org-files-as-html nil)
          (org-link-file-path-type 'absolute)
-         ;; makes the replies with ">"s look nicer
+         ;; prettify reply with ">"
          (org-export-preserve-breaks org-mime-preserve-breaks)
          ;; org 9
          (org-html-htmlize-output-type 'inline-css)
          ;; org 8
          (org-export-htmlize-output-type 'inline-css)
-         (html-and-images (org-mime-replace-images (org-mime--export-string s 
'html opts)
-                                                   file))
+         (html-and-images (org-mime-replace-images html file))
          (images (cdr html-and-images))
          (html (org-mime-apply-html-hook (car html-and-images))))
 
@@ -387,7 +388,9 @@ CURRENT-FILE is used to calculate full path of images."
                           html)))
             files))
 
-    (insert (org-mime-multipart html (if images (mapconcat 'identity images 
"\n"))))
+    (insert (org-mime-multipart plain
+                                html
+                                (if images (mapconcat 'identity images "\n"))))
 
     ;; Attach any residual files
     (when files
@@ -412,22 +415,19 @@ If called with an active region only export that region, 
otherwise entire body."
          (html-end (or (and region-p (region-end))
                        ;; TODO: should catch signature...
                        (point-max)))
-         (body (buffer-substring
-                html-start html-end))
-         (str (concat org-mime-default-header body))
-         (file (make-temp-name (expand-file-name
-                                "mail" temporary-file-directory)))
-
-
-         ;; to hold attachments for inline html images
+         (plain (buffer-substring html-start html-end))
+;; to hold attachments for inline html images
          (opts (if (fboundp 'org-export--get-inbuffer-options)
-                   (org-export--get-inbuffer-options))))
+                   (org-export--get-inbuffer-options)))
+         (html (org-mime-export-string (concat org-mime-default-header plain) 
opts))
+         (file (make-temp-name (expand-file-name
+                                "mail" temporary-file-directory))))
 
     ;; delete current region
     (delete-region html-start html-end)
     (goto-char html-start)
     ;; insert new current
-    (org-mime-insert-html-content body file str opts)))
+    (org-mime-insert-html-content plain file html opts)))
 
 (defun org-mime-apply-html-hook (html)
   "Apply HTML hook."
@@ -448,23 +448,24 @@ If called with an active region only export that region, 
otherwise entire body."
         (set-text-properties 0 (length txt) nil txt)
         txt))))
 
-(defun org-mime-compose (body file to subject headers subtreep)
-  "Create mail BODY in FILE with TO, SUBJECT, HEADERS.
+(defun org-mime-compose (exported file to subject headers subtreep)
+  "Create mail body from EXPORTED in FILE with TO, SUBJECT, HEADERS.
 If SUBTREEP is t, curret org node is subtree."
   ;; start composing mail
-  (let* ((export-opts (org-mime-get-export-options subtreep))
-         str)
-    (unless (featurep 'message)
-      (require 'message))
+  (let* ((html (car exported))
+         (plain (cdr exported))
+         (export-opts (org-mime-get-export-options subtreep))
+         patched-html)
+    (unless (featurep 'message) (require 'message))
     (message-mail to subject headers nil)
     (message-goto-body)
-    (setq str (with-temp-buffer
-                (insert body)
-                (goto-char (point-min))
-                (run-hooks 'org-mime-pre-html-hook)
-                (buffer-string)))
+    (setq patched-html (with-temp-buffer
+                         (insert html)
+                         (goto-char (point-min))
+                         (run-hooks 'org-mime-pre-html-hook)
+                         (buffer-string)))
     ;; insert text
-    (org-mime-insert-html-content body file str export-opts)))
+    (org-mime-insert-html-content plain file patched-html export-opts)))
 
 (defun org-mime-extract-keywords ()
   "Extract keywords."
@@ -515,12 +516,12 @@ The cursor ends in the TO field."
                       (if (not file) (buffer-name (buffer-base-buffer))
                         (file-name-sans-extension
                          (file-name-nondirectory file)))))
-         (html-body (org-mime-get-exported-content nil))
+         (exported (org-mime-export-buffer-or-subtree nil))
          (to (cdr (assoc "MAIL_TO" keywords)))
          (cc (cdr (assoc "MAIL_CC" keywords)))
          (bcc (cdr (assoc "MAIL_BCC" keywords)))
          (other-headers (org-mime-build-mail-other-headers cc bcc)))
-    (org-mime-compose html-body file to subject other-headers nil)
+    (org-mime-compose exported file to subject other-headers nil)
     (message-goto-to)))
 
 (defun org-mime-org-major-version ()
@@ -571,11 +572,11 @@ Following headline properties can determine the mail 
headers,
              ;; I wrap these bodies in export blocks because in 
org-mime-compose
              ;; they get exported again. This makes each block conditionally
              ;; exposed depending on the backend.
-             (html-body (save-restriction (org-narrow-to-subtree)
-                                          (org-mime-get-exported-content t))))
+             (exported (save-restriction (org-narrow-to-subtree)
+                                          (org-mime-export-buffer-or-subtree 
t))))
         (save-restriction
           (org-narrow-to-subtree)
-          (org-mime-compose html-body file to subject other-headers t))
+          (org-mime-compose exported file to subject other-headers t))
         (message-goto-to)))))
 
 (provide 'org-mime)



reply via email to

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