[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/org-mime c49eb00fc6 021/118: can create email from org sub
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/org-mime c49eb00fc6 021/118: can create email from org subtree |
Date: |
Wed, 5 Jan 2022 07:58:43 -0500 (EST) |
branch: elpa/org-mime
commit c49eb00fc629f2a6ec39a531dec782cd921e17fb
Author: Chen Bin <chenbin.sh@gmail.com>
Commit: Chen Bin <chenbin.sh@gmail.com>
can create email from org subtree
- restore accidently deleted subtree functionality
- can handle CC and BCC headers properly when exporting subtree
- clean code to remove warnings
---
README.org | 14 ++++++++++++++
org-mime.el | 55 ++++++++++++++++++++++++++++++++++++++++++++++++-------
2 files changed, 62 insertions(+), 7 deletions(-)
diff --git a/README.org b/README.org
index 1677df63fe..17e2ef1996 100644
--- a/README.org
+++ b/README.org
@@ -37,6 +37,20 @@ The following key bindings are suggested, which bind the C-c
M-o key sequence to
(local-set-key (kbd "C-c M-o") 'org-mime-org-buffer-htmlize)))
#+end_src
+** =M-x org-mime-org-subtree-htmlize=
+=org-mime-org-subtree-htmlize= is similar to =org-mime-org-buffer-htmlize=
+but works on subtree. It can also read subtree properties MAIL_SUBJECT,
+MAIL_TO, MAIL_CC, and MAIL_BCC. Here is the sample of subtree:
+#+begin_src org
+* mail one
+ :PROPERTIES:
+ :MAIL_SUBJECT: mail title
+ :MAIL_TO: person1@gmail.com
+ :MAIL_CC: person2@gmail.com
+ :MAIL_BCC: person3@gmail.com
+ :END:
+content ...
+#+end_src
** CSS style customization
Email clients will often strip all global CSS from email messages. In the case
of web-based email readers this is essential in order to protect the CSS of the
containing web site. To ensure that your CSS styles are rendered correctly they
must be included in the actual body of the elements to which they apply.
diff --git a/org-mime.el b/org-mime.el
index 2fafa7f51d..6b46f1abc9 100644
--- a/org-mime.el
+++ b/org-mime.el
@@ -41,6 +41,18 @@
;; package the results into an email handling with appropriate MIME
;; encoding.
;;
+;; `org-mime-org-subtree-htmlize' is similar to `org-mime-org-buffer-htmlize'
+;; but works on subtree. It can also read subtree properties MAIL_SUBJECT,
+;; MAIL_TO, MAIL_CC, and MAIL_BCC. Here is the sample of subtree:
+;;
+;; * mail one
+;; :PROPERTIES:
+;; :MAIL_SUBJECT: mail title
+;; :MAIL_TO: person1@gmail.com
+;; :MAIL_CC: person2@gmail.com
+;; :MAIL_BCC: person3@gmail.com
+;; :END:
+;;
;; Quick start:
;; Write mail in message-mode, make sure the mail body follows org format.
;; Before sending mail, `M-x org-mime-htmlize'
@@ -63,6 +75,11 @@
(require 'cl-lib)
(require 'org)
+(defcustom org-mime-use-property-inheritance nil
+ "Non-nil means al MAIL_ properties apply also for sublevels."
+ :group 'org-mime
+ :type 'boolean)
+
(defcustom org-mime-default-header
"#+OPTIONS: latex:t toc:nil H:3\n"
"Default header to control html export options.
@@ -101,8 +118,8 @@ buffer holding\nthe text to be exported.")
(defvar org-mime-debug nil
"Enable debug logger.")
-(defun org-mime--export-string (s)
- "Export string S into HTML format."
+(defun org-mime--export-string (s &optional opts)
+ "Export string S into HTML format. OPTS is export options."
(if (fboundp 'org-export-string-as)
;; emacs24
(org-export-string-as s 'html t nil)
@@ -252,13 +269,13 @@ If ARG is not NIL, use `org-mime-fixedwith-wrap' to wrap
the exported text."
(set-text-properties 0 (length txt) nil txt)
txt))))
-(defun org-mime-compose (body file &optional subject)
- "Create mail BODY in FILE with SUBJECT."
+(defun org-mime-compose (body file &optional to subject headers opts)
+ "Create mail BODY in FILE with SUBJECT, HEADERS and OPTS."
(if org-mime-debug (message "org-mime-compose called => %s" file))
(let* ((fmt 'html))
(unless (featurep 'message)
(require 'message))
- (message-mail nil subject nil nil)
+ (message-mail to subject headers nil)
(message-goto-body)
(cl-labels ((bhook (body fmt)
(let ((hook 'org-mime-pre-html-hook))
@@ -275,7 +292,7 @@ If ARG is not NIL, use `org-mime-fixedwith-wrap' to wrap
the exported text."
(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 plain html)
@@ -297,7 +314,31 @@ If ARG is not NIL, use `org-mime-fixedwith-wrap' to wrap
the exported text."
(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 file subject)))
+ (org-mime-compose body file nil subject)))
+
+;;;###autoload
+(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)
+ (save-excursion
+ (org-up-heading-safe)
+ (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"))
+ (cc (mp "MAIL_CC"))
+ (bcc (mp "MAIL_BCC"))
+ ;; Thanks for Matt Price improving handling of cc & bcc headers
+ (other-headers (cond
+ ((and cc bcc) `((cc . ,cc) (bcc . ,bcc)))
+ (cc `((cc . ,cc)))
+ (bcc `((bcc . ,bcc)))
+ (t nil)))
+ (opts (org-export--get-subtree-options))
+ (body (org-get-entry)))
+ (org-mime-compose body file to subject other-headers opts)))))
(provide 'org-mime)
;;; org-mime.el ends here
- [nongnu] branch elpa/org-mime created (now 613969effc), ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime a1a7fb329f 003/118: clean doc, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 3c4f24c8d4 016/118: clean code. github organization created, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 2347595278 002/118: emacs24 use org-export-string instead of org-export-string-as, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime a0b82a6c1a 024/118: better export format (not TOC, etc) and bug fix, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 9d32b819f0 025/118: updated README, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime caa1f19d4b 009/118: Fix getting the subect, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 0311662889 017/118: Correct 'interactive' position, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime ffbf3e3e47 010/118: Support mime encoding current subtree, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime c49eb00fc6 021/118: can create email from org subtree,
ELPA Syncer <=
- [nongnu] elpa/org-mime e554d8821d 020/118: Merge pull request #1 from syohex/fix-package, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 91d8f48775 023/118: can set org export options, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 7c3483b2b0 030/118: sample for advanced setup, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime e3329c7c4d 032/118: README, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 0a0aa9b110 034/118: README, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime ad30f199cb 036/118: provide org-mime-find-html-start callback, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 5f253f541c 037/118: only use export header when creating html, keep out of email, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime c6e2b95664 047/118: clean code, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 64a3f56651 041/118: (setq org-html-with-latex nil) sometimes useful #16, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 10098b001c 049/118: Fix file attachments and equations and enhance emails from org-files, ELPA Syncer, 2022/01/05