branch: elpa/org-mime commit 1efae43c252db3d1eb3f35ea8a70ada3705121ee Author: Chen Bin <chenbin...@gmail.com> Commit: Chen Bin <chenbin...@gmail.com>
fixed code style for elpa.gnu.org --- .gitignore | 3 ++ org-mime.el | 41 ++++++++++++----------- test/org-mime-tests.el | 89 +++++++++++++++++++++++++------------------------- 3 files changed, 68 insertions(+), 65 deletions(-) diff --git a/.gitignore b/.gitignore index 5ed05fd76d..d29af04fd3 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,9 @@ tramp .org-id-locations *_archive +# ELPA -generated files +/org-mime-autoloads.el +/org-mime-pkg.el ### /Users/cb/.gitignore-boilerplates/Global/Vim.gitignore diff --git a/org-mime.el b/org-mime.el index 36e4f2329a..ea57e831fa 100644 --- a/org-mime.el +++ b/org-mime.el @@ -1,9 +1,9 @@ -;;; org-mime.el --- org html export for text/html MIME emails +;;; org-mime.el --- org html export for text/html MIME emails -*- lexical-binding: t; -*- ;; Copyright (C) 2010-2015 Eric Schulte, 2016-2021 Chen Bin ;; Author: Eric Schulte -;; Maintainer: Chen Bin (redguardtoo) +;; Maintainer: Chen Bin <chenbin...@gmail.com> ;; Keywords: mime, mail, email, html ;; Homepage: http://github.com/org-mime/org-mime ;; Version: 0.3.0 @@ -126,6 +126,7 @@ (require 'outline) (require 'org) (require 'ox-org) +(require 'message) (defcustom org-mime-use-property-inheritance nil "Non-nil means al MAIL_ properties apply also for sub-levels." @@ -403,12 +404,14 @@ CURRENT-FILE is used to calculate full path of images." (buffer-string)) html)) -(defun org-mime-insert-html-content (plain file html opts) - "Insert PLAIN into FILE with HTML content and OPTS." + +(defun org-mime-insert-html-content (plain file html) + "Insert PLAIN into FILE with HTML content." + (defvar org-export-htmlize-output-type) (let* ((files (org-mime-extract-non-image-files)) - ;; dvipng for inline latex because MathJax doesn't work in mail + ;; Use dvipng for inline latex because MathJax doesn't work in mail ;; Also @see https://github.com/org-mime/org-mime/issues/16 - ;; (setq org-html-with-latex nil) sometimes useful + ;; Looks "(setq org-html-with-latex nil)" may be useful (org-html-with-latex org-mime-org-html-with-latex-default) ;; we don't want to convert org file links to html (org-html-link-org-files-as-html nil) @@ -436,7 +439,7 @@ CURRENT-FILE is used to calculate full path of images." (insert (org-mime-multipart (org-mime-apply-plain-text-hook plain) html - (if images (mapconcat 'identity images "\n")))) + (if images (mapconcat #'identity images "\n")))) ;; Attach any residual files (when files @@ -593,7 +596,7 @@ If called with an active region only export that region, otherwise entire body." "</div>\n"))) ;; insert converted html - (org-mime-insert-html-content plain file html opts) + (org-mime-insert-html-content plain file html) ;; restore part tags (when part-tags @@ -608,13 +611,11 @@ 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 (exported file to subject headers subtreep) - "Create mail body from EXPORTED in FILE with TO, SUBJECT, HEADERS. -If SUBTREEP is t, current org node is subtree." +(defun org-mime-compose (exported file to subject headers) + "Create mail body from EXPORTED in FILE with TO, SUBJECT, HEADERS." ;; start composing mail (let* ((html (car exported)) (plain (cdr exported)) - (export-opts (org-mime-get-export-options subtreep)) patched-html) (compose-mail to subject headers nil) (message-goto-body) @@ -624,7 +625,7 @@ If SUBTREEP is t, current org node is subtree." (run-hooks 'org-mime-pre-html-hook) (buffer-string))) ;; insert text - (org-mime-insert-html-content plain file patched-html export-opts))) + (org-mime-insert-html-content plain file patched-html))) ; export-opts (defun org-mime-buffer-properties () "Extract buffer properties." @@ -667,7 +668,7 @@ The cursor ends in the TO field." (interactive) (run-hooks 'org-mime-send-buffer-hook) (let* ((org-html-klipsify-src nil) - (region-p (org-region-active-p)) + ;; (region-p (org-region-active-p)) (file (buffer-file-name (current-buffer))) (props (org-mime-buffer-properties)) (subject (or (plist-get props :MAIL_SUBJECT) @@ -683,7 +684,7 @@ The cursor ends in the TO field." (other-headers (org-mime-build-mail-other-headers cc bcc from))) - (org-mime-compose exported 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 () @@ -719,6 +720,7 @@ Following headline properties can determine the mail headers. (org-back-to-heading)) (when (outline-on-heading-p nil) + (defvar org-major-version) (let* ((file (buffer-file-name (current-buffer))) (props (org-mime-buffer-properties)) (subject (or (org-mime-attr "MAIL_SUBJECT") @@ -735,9 +737,6 @@ Following headline properties can determine the mail headers. ;; 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) - (subtree-opts (when (fboundp 'org-export--get-subtree-options) - (org-export--get-subtree-options))) - (org-export-show-temporary-export-buffer nil) (org-major-version (org-mime-org-major-version)) ;; I wrap these bodies in export blocks because in org-mime-compose ;; they get exported again. This makes each block conditionally @@ -746,7 +745,7 @@ Following headline properties can determine the mail headers. (org-mime-export-buffer-or-subtree t)))) (save-restriction (org-narrow-to-subtree) - (org-mime-compose exported file to subject other-headers t)) + (org-mime-compose exported file to subject other-headers)) ; t (message-goto-to))))) (defun org-mime-src--remove-overlay () @@ -819,8 +818,8 @@ Following headline properties can determine the mail headers. (defvar org-mime-src-mode-map (let ((map (make-sparse-keymap))) - (define-key map (kbd "C-c C-c") 'org-mime-edit-src-exit) - (define-key map (kbd "C-x C-s") 'org-mime-edit-src-save) + (define-key map (kbd "C-c C-c") #'org-mime-edit-src-exit) + (define-key map (kbd "C-x C-s") #'org-mime-edit-src-save) map)) (define-minor-mode org-mime-src-mode diff --git a/test/org-mime-tests.el b/test/org-mime-tests.el index ffe2d75bf9..ed27f80a20 100644 --- a/test/org-mime-tests.el +++ b/test/org-mime-tests.el @@ -1,4 +1,4 @@ -;; org-mime-tests.el --- unit tests for org-mime -*- coding: utf-8 -*- +;; org-mime-tests.el --- unit tests for org-mime -*- lexical-binding: t; -*- ;; Author: Chen Bin <chenbin DOT sh AT gmail DOT com> @@ -25,21 +25,23 @@ (require 'org-mime) (require 'message) -(defconst mail-header '("To: myn...@mail.com\n" - "Subject: test subject\n" - "From: My Name <myn...@yahoo.com>\n" - "--text follows this line--\n")) -(defconst mail-footer '("--\n" - "Yous somebody\n\n" - "--\n" - "Some quote\n")) +(defconst org-mime--mail-header + '("To: myn...@mail.com\n" + "Subject: test subject\n" + "From: My Name <myn...@yahoo.com>\n" + "--text follows this line--\n")) +(defconst org-mime--mail-footer + '("--\n" + "Yous somebody\n\n" + "--\n" + "Some quote\n")) (defun run-org-mime-htmlize (&rest mail-body) "Create mail containing MAIL-BODY and run `org-mime-htmlize'." (with-temp-buffer - (apply #'insert mail-header) + (apply #'insert org-mime--mail-header) (apply #'insert mail-body) - (apply #'insert mail-footer) + (apply #'insert org-mime--mail-footer) (message-mode) (goto-char (point-min)) (org-mime-htmlize) @@ -75,7 +77,7 @@ (setq opts (org-mime-get-export-options t)) (should opts) (org-mime-org-subtree-htmlize) - (switch-to-buffer (car (message-buffers))) + (set-buffer (car (message-buffers))) (setq str (buffer-string))) (should (string-match "Subject: hello" str)) (should (string-match "<#multipart" str)))) @@ -101,7 +103,7 @@ (setq opts (org-mime-get-export-options t)) (should opts) (org-mime-org-buffer-htmlize) - (switch-to-buffer (car (message-buffers))) + (set-buffer (car (message-buffers))) (setq str (buffer-string))) (should (string= "My mail subject" (plist-get props :MAIL_SUBJECT))) (should (string= "Someone <some...@somewhere.tld>" (plist-get props :MAIL_TO))) @@ -138,14 +140,14 @@ (should (string= (car h) "Cc")) (should (string= (cdr h) cc)))) -;;; The two ASCII export tests below check for org-mode markup for the default -;;; case, where the export variable is nil or not valid, and check for absent -;;; org-mode markup for the three valid plain text exports. The ASCII export -;;; tests do not attempt to verify the exported coding type. +;; The two ASCII export tests below check for org-mode markup for the default +;; case, where the export variable is nil or not valid, and check for absent +;; org-mode markup for the three valid plain text exports. The ASCII export +;; tests do not attempt to verify the exported coding type. (ert-deftest test-org-mime-org-buffer-htmlize-ascii-plain-text () - (let (str opts) - (setq orgBuf (generate-new-buffer "*org-mode-test-buf*")) + (let ((orgBuf (generate-new-buffer "*org-mode-test-buf*")) + str opts) (with-current-buffer orgBuf (insert "#+OPTIONS: toc:nil num:nil\n" "\n#+begin_example\n" @@ -155,17 +157,16 @@ (goto-char (point-min)) (setq opts (org-mime-get-export-options t)) (should opts) - (mapcar (lambda (backend) - (setq org-mime-export-ascii backend) - (switch-to-buffer orgBuf) - (org-mime-org-buffer-htmlize) - (switch-to-buffer (car (message-buffers))) - (setq str (buffer-string)) - (should (string-match "<#multipart" str)) - (if (car (memq backend '(ascii latin1 utf-8))) - (should-not (string-match "#\\+begin_example" str)) - (should (string-match "#\\+begin_example" str)))) - '(nil bogus ascii latin1 utf-8))) + (dolist (backend '(nil bogus ascii latin1 utf-8)) + (setq org-mime-export-ascii backend) + (set-buffer orgBuf) + (org-mime-org-buffer-htmlize) + (set-buffer (car (message-buffers))) + (setq str (buffer-string)) + (should (string-match "<#multipart" str)) + (if (car (memq backend '(ascii latin1 utf-8))) + (should-not (string-match "#\\+begin_example" str)) + (should (string-match "#\\+begin_example" str))))) (kill-buffer orgBuf))) (ert-deftest test-org-mime-htmlize-ascii-plain-text () @@ -173,12 +174,12 @@ (mapcar (lambda (backend) (setq org-mime-export-ascii backend) (with-temp-buffer - (apply #'insert mail-header) + (apply #'insert org-mime--mail-header) (insert "#+OPTIONS: toc:nil num:nil\n" "\n#+begin_example\n" "$ echo nothing to see here\n" "#+end_example\n") - (apply #'insert mail-footer) + (apply #'insert org-mime--mail-footer) (message-mode) (goto-char (point-min)) (org-mime-htmlize) @@ -195,10 +196,10 @@ ;; Title, TOC, and Author. (ert-deftest test-org-mime-org-subtree-htmlize-ascii-opts-t () - (let (str opts) - (setq org-mime-export-options nil) ;; allow subtree properties - (setq org-mime-export-ascii 'utf-8) - (setq orgBuf (generate-new-buffer "*org-mode-test-buf*")) + (let (str + (org-mime-export-options nil) ;; allow subtree properties + (org-mime-export-ascii 'utf-8) + (orgBuf (generate-new-buffer "*org-mode-test-buf*"))) (with-current-buffer orgBuf ;; the initial options are ignored in favor of subtree options (insert "#+OPTIONS: toc:nil author:nil title:nil\n" @@ -214,13 +215,13 @@ "$ echo nothing to see here\n" "#+end_example\n") (org-mode) - (switch-to-buffer orgBuf) + (set-buffer orgBuf) ;; export subtree for Section 2 (goto-char (point-min)) (search-forward "Section 2") (goto-char (+ 1 (point))) (org-mime-org-subtree-htmlize) - (switch-to-buffer (car (message-buffers))) + (set-buffer (car (message-buffers))) (setq str (buffer-string)) (setq case-fold-search nil) ;; match case for string-match (should-not (string-match "#\\+begin_example" str)) @@ -233,10 +234,10 @@ (kill-buffer orgBuf))) (ert-deftest test-org-mime-org-subtree-htmlize-ascii-opts-nil () - (let (str opts) - (setq org-mime-export-options nil) ;; allow subtree properties - (setq org-mime-export-ascii 'utf-8) - (setq orgBuf (generate-new-buffer "*org-mode-test-buf*")) + (let (str + (org-mime-export-options nil) ;; allow subtree properties + (org-mime-export-ascii 'utf-8) + (orgBuf (generate-new-buffer "*org-mode-test-buf*"))) (with-current-buffer orgBuf ;; the initial options are ignored in favor of subtree options (insert "#+OPTIONS: toc:t author:t title:t\n" @@ -252,13 +253,13 @@ "$ echo nothing to see here\n" "#+end_example\n") (org-mode) - (switch-to-buffer orgBuf) + (set-buffer orgBuf) ;; export subtree for Section 2 (goto-char (point-min)) (search-forward "Section 2") (goto-char (+ 1 (point))) (org-mime-org-subtree-htmlize) - (switch-to-buffer (car (message-buffers))) + (set-buffer (car (message-buffers))) (setq str (buffer-string)) (setq case-fold-search nil) ;; match case for string-match (should-not (string-match "#\\+begin_example" str))