branch: elpa/org-mime
commit df99e631c557b892f9d632d938d37ab9e9b2b1ae
Author: Chen Bin <[email protected]>
Commit: Chen Bin <[email protected]>
quoted mail use modern UI style
---
README.org | 2 +-
org-mime.el | 44 ++++++++++++++++++++++++++++++++++++++++----
2 files changed, 41 insertions(+), 5 deletions(-)
diff --git a/README.org b/README.org
index 02f058129a..86452548d0 100644
--- a/README.org
+++ b/README.org
@@ -20,7 +20,7 @@ Tested on Emacs 24.3, 24.4, 24.5, 25.1, 25.2
Export a portion of an email body composed using `mml-mode' to html using
`org-mode'. If called with an active region only export that region, otherwise
export the entire body.
-Warning: There has been some concern voiced over the potential complexity of
email resulting from calling this function on an active region resulting in
multiple =multipart/alternative= sections in the same email. Please see this
email thread for a discussion of the potential pitfalls of this approach.
Speaking from personal experience this has not been a problem for the author.
+Warning: There has been some concern voiced over the potential complexity of
email resulting from calling this function on an active region resulting in
multiple =multipart/alternative= sections in the same email. Please see
[[http://thread.gmane.org/gmane.emacs.orgmode/23617][this email thread]] for a
discussion of the potential pitfalls of this approach. Speaking from personal
experience this has not been a problem for the author.
** =M-x org-mime-org-buffer-htmlize=
=org-mime-org-buffer-htmlize= can be called from within an Org-mode buffer to
export either the whole buffer or the narrowed subtree or active region to
HTML, and open a new email buffer including the resulting HTML content as an
embedded mime section.
diff --git a/org-mime.el b/org-mime.el
index ca8d05d149..9c42802db1 100644
--- a/org-mime.el
+++ b/org-mime.el
@@ -6,8 +6,8 @@
;; Maintainer: Chen Bin (redguardtoo)
;; Keywords: mime, mail, email, html
;; Homepage: http://github.com/org-mime/org-mime
-;; Version: 0.0.7
-;; Package-Requires: ((emacs "24") (cl-lib "0.5"))
+;; Version: 0.0.8
+;; Package-Requires: ((emacs "24.3") (cl-lib "0.5"))
;; This file is not part of GNU Emacs.
@@ -91,11 +91,19 @@
;; (lambda ()
;; (while (re-search-forward "@\\([^@]*\\)@" nil t)
;; (replace-match "<span style=\"color:red\">\\1</span>"))))
+;;
+;; 3. Since v0.0.8, the quoted mail use modern style (like Gmail). If you
prefer
+;; the original style, please set `org-mime-beautify-quoted-mail' to nil.
;;; Code:
(require 'cl-lib)
(require 'org)
+(defcustom org-mime-beautify-quoted-mail t
+ "Beautify quoted mail in more clean HTML, like Gmail."
+ :group 'org-mime
+ :type 'boolean)
+
(defcustom org-mime-use-property-inheritance nil
"Non-nil means al MAIL_ properties apply also for sublevels."
:group 'org-mime
@@ -215,6 +223,34 @@ You could use either `org-up-heading-safe' or
`org-back-to-heading'.")
(buffer-string)))))
(vm "?")))
+(defun org-mime-cleanup-quoted (html)
+ "Clean up quoted mail in modern UI style."
+ (cond
+ (org-mime-beautify-quoted-mail
+ (with-temp-buffer
+ ;; clean title of quoted
+ (insert (replace-regexp-in-string
+ "<p>[\n\r]*>>>>> .* == \\([^\r\n]*\\)[\r\n]*</p>"
+ "<div class=\"gmail_quote\">\\1</div>"
+ html))
+ ;; now handle body, try to find beginning
+ (goto-char (point-min))
+ (search-forward-regexp "^[^ ]*> ")
+ (search-backward-regexp "<p>")
+ ;; gmail use this style
+ (insert "<blockquote class=\"gmail_quote\" style=\"margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex\">\n")
+ ;; find end
+ (goto-char (point-max))
+ (search-backward-regexp "^[^ ]*> ")
+ (search-forward-regexp "</p>")
+ (goto-char (+ (point) 1))
+ (insert "</blockquote>")
+ (setq html (buffer-substring-no-properties (point-min) (point-max))))
+ ;; remove "User> "
+ (replace-regexp-in-string "^ *[^ ]*> " "" html))
+ (t
+ html)))
+
(defun org-mime-multipart (plain html &optional images)
"Markup a multipart/alternative PLAIN with PLAIN and HTML alternatives.
If html portion of message includes IMAGES they are wrapped in
multipart/related part."
@@ -223,7 +259,7 @@ If html portion of message includes IMAGES they are wrapped
in multipart/related
plain
(when images "<#multipart type=related>")
"<#part type=text/html>"
- html
+ (org-mime-cleanup-quoted html)
images
(when images "<#/multipart>\n")
"<#/multipart>\n"))
@@ -385,7 +421,7 @@ and in org formats as mime alternatives."
(interactive)
(save-excursion
(funcall org-mime-up-subtree-heading)
- (flet ((mp (p) (org-entry-get nil p org-mime-use-property-inheritance)))
+ (cl-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"))