[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/org-mime 21692f16ce 110/118: use buffer properties
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/org-mime 21692f16ce 110/118: use buffer properties |
Date: |
Wed, 5 Jan 2022 07:58:51 -0500 (EST) |
branch: elpa/org-mime
commit 21692f16ce436d9d2a546230f1e124beec0be7ee
Author: Chen Bin <chenbin.sh@gmail.com>
Commit: Chen Bin <chenbin.sh@gmail.com>
use buffer properties
---
org-mime.el | 59 ++++++++++++++++++++++++++++++--------------------
test/org-mime-tests.el | 25 ++++++++++++++++-----
2 files changed, 54 insertions(+), 30 deletions(-)
diff --git a/org-mime.el b/org-mime.el
index 639d6a2ab3..de0912031e 100644
--- a/org-mime.el
+++ b/org-mime.el
@@ -1,13 +1,13 @@
;;; org-mime.el --- org html export for text/html MIME emails
-;; Copyright (C) 2010-2015 Eric Schulte
+;; Copyright (C) 2010-2015 Eric Schulte, 2016-2021 Chen Bin
;; Author: Eric Schulte
;; Maintainer: Chen Bin (redguardtoo)
;; Keywords: mime, mail, email, html
;; Homepage: http://github.com/org-mime/org-mime
-;; Version: 0.2.1
-;; Package-Requires: ((emacs "25.1") (cl-lib "0.5"))
+;; Version: 0.2.2
+;; Package-Requires: ((emacs "25.1"))
;; This file is not part of GNU Emacs.
@@ -533,17 +533,20 @@ If SUBTREEP is t, current org node is subtree."
;; insert text
(org-mime-insert-html-content plain file patched-html export-opts)))
-(defun org-mime-extract-keywords ()
- "Extract keywords."
- (cond
- ((>= (org-mime-org-major-version) 9)
+(defun org-mime-buffer-properties ()
+ "Extract buffer properties."
+ (let* (rlt value key)
(org-element-map (org-element-parse-buffer) 'keyword
(lambda (keyword)
- (cons (org-element-property :key keyword)
- (org-element-property :value keyword)))))
- (t
- (message "Warning: org-element-map is not available. File keywords will
not work.")
- '())))
+ (when (and (string= (org-element-property :key keyword) "PROPERTY")
+ (string-match "^MAIL_\\(TO\\|SUBJECT\\|CC\\|BCC\\|FROM\\) +"
+ (setq value (org-element-property :value
keyword)))
+ (setq key (concat "MAIL_" (match-string 1 value)))
+ (setq rlt
+ (plist-put rlt
+ (intern (concat ":" key))
+ (string-trim (replace-regexp-in-string key
"" value))))))))
+ rlt))
(defun org-mime-build-mail-other-headers (cc bcc from)
"Build mail header from CC, BCC, and FROM."
@@ -573,18 +576,20 @@ The cursor ends in the TO field."
(let* ((org-html-klipsify-src nil)
(region-p (org-region-active-p))
(file (buffer-file-name (current-buffer)))
- (keywords (org-mime-extract-keywords))
- (subject (or (cdr (assoc "MAIL_SUBJECT" keywords))
+ (props (org-mime-buffer-properties))
+ (subject (or (plist-get props :MAIL_SUBJECT)
(org-mime--get-buffer-title)
(if (not file) (buffer-name (buffer-base-buffer))
(file-name-sans-extension
(file-name-nondirectory file)))))
(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)))
- (from (cdr (assoc "MAIL_FROM" keywords)))
- (other-headers (org-mime-build-mail-other-headers cc bcc from)))
+ (to (plist-get props :MAIL_TO))
+ (cc (plist-get props :MAIL_CC))
+ (bcc (plist-get props :MAIL_BCC))
+ (from (plist-get props :MAIL_FROM))
+ (other-headers (org-mime-build-mail-other-headers cc
+ bcc
+ from)))
(org-mime-compose exported file to subject other-headers nil)
(message-goto-to)))
@@ -622,12 +627,18 @@ Following headline properties can determine the mail
headers.
(when (outline-on-heading-p nil)
(let* ((file (buffer-file-name (current-buffer)))
+ (props (org-mime-buffer-properties))
(subject (or (org-mime-attr "MAIL_SUBJECT")
+ (plist-get props :MAIL_SUBJECT)
(nth 4 (org-heading-components))))
- (to (org-mime-attr "MAIL_TO"))
- (cc (org-mime-attr "MAIL_CC"))
- (bcc (org-mime-attr "MAIL_BCC"))
- (from (org-mime-attr "MAIL_FROM"))
+ (to (or (org-mime-attr "MAIL_TO")
+ (plist-get props :MAIL_TO)))
+ (cc (or (org-mime-attr "MAIL_CC")
+ (plist-get props :MAIL_CC)))
+ (bcc (or (org-mime-attr "MAIL_BCC")
+ (plist-get props :MAIL_BCC)))
+ (from (or (org-mime-attr "MAIL_FROM")
+ (plist-get props :MAIL_FROM)))
;; Thanks to Matt Price improving handling of cc & bcc headers
(other-headers (org-mime-build-mail-other-headers cc bcc from))
(org-export-show-temporary-export-buffer nil)
@@ -639,7 +650,7 @@ Following headline properties can determine the mail
headers.
;; they get exported again. This makes each block conditionally
;; exposed depending on the backend.
(exported (save-restriction (org-narrow-to-subtree)
- (org-mime-export-buffer-or-subtree
t))))
+ (org-mime-export-buffer-or-subtree
t))))
(save-restriction
(org-narrow-to-subtree)
(org-mime-compose exported file to subject other-headers t))
diff --git a/test/org-mime-tests.el b/test/org-mime-tests.el
index fb790bf469..8b95a28434 100644
--- a/test/org-mime-tests.el
+++ b/test/org-mime-tests.el
@@ -82,20 +82,33 @@
(should (string-match "<#multipart" str))))
(ert-deftest test-org-mime-org-buffer-htmlize ()
- (let* (str opts)
+ (let* (str opts props)
(with-temp-buffer
- (insert "* hello\n"
- "** world\n"
- "#+begin_src javascript\n"
- "console.log('hello world');\n"
- "#+end_src\n")
+ (insert
+ "#+PROPERTY: MAIL_SUBJECT My mail subject\n"
+ "#+PROPERTY: MAIL_TO Someone <someone@somewhere.tld>\n"
+ "#+PROPERTY: MAIL_FROM Me <me@mine.tld>\n"
+ "#+PROPERTY: MAIL_CC ccme@somewhere.tld\n"
+ "#+PROPERTY: MAIL_BCC bccme@mine.tld\n"
+ "* hello\n"
+ "* hello\n"
+ "** world\n"
+ "#+begin_src javascript\n"
+ "console.log('hello world');\n"
+ "#+end_src\n")
(org-mode)
(goto-char (point-min))
+ (setq props (org-mime-buffer-properties))
(setq opts (org-mime-get-export-options t))
(should opts)
(org-mime-org-buffer-htmlize)
(switch-to-buffer (car (message-buffers)))
(setq str (buffer-string)))
+ (should (string= "My mail subject" (plist-get props :MAIL_SUBJECT)))
+ (should (string= "Someone <someone@somewhere.tld>" (plist-get props
:MAIL_TO)))
+ (should (string= "Me <me@mine.tld>" (plist-get props :MAIL_FROM)))
+ (should (string= "ccme@somewhere.tld" (plist-get props :MAIL_CC)))
+ (should (string= "bccme@mine.tld" (plist-get props :MAIL_BCC)))
(should (string-match "<#multipart" str))))
(ert-deftest test-org-mime-build-mail-other-headers ()
- [nongnu] elpa/org-mime 7475a592c2 081/118: drop emacs 24 support, (continued)
- [nongnu] elpa/org-mime 7475a592c2 081/118: drop emacs 24 support, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime e81651d848 084/118: clean code, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 9bb6351b25 085/118: un-bundled htmlize.el, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 2581fc2dd9 091/118: org-mime-confirm-when-no-multipart function + docs, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 8ad1218456 095/118: Combine two insert calls, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 2cbd5de7bd 100/118: general export options should always override buffer options, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime ecbc66f16a 106/118: fixed typo, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime c6a3d73e78 107/118: remove org-mime-default-header, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 04e6ce9db6 108/118: try fixing ci again, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime eb21c02ba8 109/118: fixed org subtree htmlize, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 21692f16ce 110/118: use buffer properties,
ELPA Syncer <=
- [nongnu] elpa/org-mime 59bf130c76 113/118: secure tag should be at the beginning of email body, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime df99e631c5 031/118: quoted mail use modern UI style, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime e5e4c59022 103/118: fixed some typo, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 3b119a22be 112/118: handle file url on Windows elegantly, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime f7a45f5573 115/118: Upgrade test file to GPLv3, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 77c3f07ce4 046/118: documentation, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime e5c68b1c66 044/118: minor changes to docstrings for readability and style changes., ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime e35c367e7d 048/118: clean code, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 41ea9818b4 050/118: fix cc, bcc compiling error, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 0db41d5b4e 065/118: emergency fix of broken 0.1.4, ELPA Syncer, 2022/01/05