branch: elpa/org-mime commit cf96f585c68ad14751a3f73d937cbfcb890171b9 Author: Chen Bin <chenbin...@gmail.com> Commit: Chen Bin <chenbin...@gmail.com>
clean code per elpa.gnu style again --- .gitignore | 3 ++ README.org | 2 +- org-mime.el | 38 +++++++++++--------------- test/org-mime-tests.el | 74 ++++++++++++++++++++++++-------------------------- 4 files changed, 56 insertions(+), 61 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/README.org b/README.org index f319ba8d5f..2330c65ceb 100644 --- a/README.org +++ b/README.org @@ -95,7 +95,7 @@ Below code renders text between "#" in red color, #+end_src For other customization options see the org-mime customization group. ** Beautify quoted mail when replying -It already works out of box. Currently it emulates Gmail's style. You can go back the old style by =(setq org-mime-beautify-quoted-mail-p nil)=. +It already works out of box. Currently it emulates Gmail's style. ** Export options To avoid exporting TOC, you can setup =org-mime-export-options= which overrides Org default settings (but still inferior to file-local settings), #+begin_src elisp diff --git a/org-mime.el b/org-mime.el index 51617ba98e..a73baadbfd 100644 --- a/org-mime.el +++ b/org-mime.el @@ -1,12 +1,12 @@ -;;; 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.2.6 +;; Version: 0.3.1 ;; Package-Requires: ((emacs "25.1")) ;; This file is not part of GNU Emacs. @@ -109,8 +109,7 @@ ;; (while (re-search-forward "#\\([^#]*\\)#" nil t) ;; (replace-match "<span style=\"color:red\">\\1</span>")))) ;; -;; 3. The quoted mail uses Gmail's style, so mail replies looks clean and modern. -;; If you prefer the old style, please set `org-mime-beautify-quoted-mail-p' to nil. +;; 3. The quoted mail uses Gmail's style, so reply looks clean and modern. ;; ;; 4. Please note this program can only embed exported HTML into mail. ;; Org-mode is responsible for rendering HTML. @@ -127,6 +126,7 @@ (require 'outline) (require 'org) (require 'ox-org) +(require 'message) (defcustom org-mime-beautify-quoted-mail-p t "Beautify quoted mail in more clean HTML, like Gmail." @@ -446,8 +446,8 @@ 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." (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 @@ -581,7 +581,7 @@ If called with an active region only export that region, otherwise entire body." (insert "\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 @@ -596,13 +596,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) @@ -612,7 +610,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))) (defun org-mime-buffer-properties () "Extract buffer properties." @@ -655,7 +653,6 @@ 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)) (file (buffer-file-name (current-buffer))) (props (org-mime-buffer-properties)) (subject (or (plist-get props :MAIL_SUBJECT) @@ -671,7 +668,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) (message-goto-to))) (defun org-mime-org-major-version () @@ -723,10 +720,7 @@ 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 ;; exposed depending on the backend. @@ -734,7 +728,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)) (message-goto-to))))) (defun org-mime-src--remove-overlay () @@ -807,8 +801,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 @@ -891,7 +885,7 @@ Following headline properties can determine the mail headers. (message "Can not find plain text mail."))))) (defun org-mime-confirm-when-no-multipart () - "Prompts whether to send email if the buffer is not htmlized." + "Prompt whether to send email if the buffer is not htmlized." (let ((found-multipart (save-excursion (save-restriction (widen) diff --git a/test/org-mime-tests.el b/test/org-mime-tests.el index c043b43ee3..bab33369a4 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,11 +25,11 @@ (require 'org-mime) (require 'message) -(defconst mail-header '("To: myn...@mail.com\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 mail-footer '("--\n" +(defconst org-mime--mail-footer '("--\n" "Yous somebody\n\n" "--\n" "Some quote\n")) @@ -37,9 +37,9 @@ (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) @@ -63,7 +63,7 @@ (should (not (string-match "Table of Contents" str))))) (ert-deftest test-org-mime-org-subtree-htmlize () - (let* (str opts) + (let* (str) (with-temp-buffer (insert "* hello\n" "** world\n" @@ -72,16 +72,15 @@ "#+end_src\n") (org-mode) (goto-char (point-min)) - (setq opts (org-mime-get-export-options t)) - (should opts) + (should (org-mime-get-export-options t)) (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)))) (ert-deftest test-org-mime-org-buffer-htmlize () - (let* (str opts props) + (let* (str props) (with-temp-buffer (insert "#+PROPERTY: MAIL_SUBJECT My mail subject\n" @@ -98,10 +97,9 @@ (org-mode) (goto-char (point-min)) (setq props (org-mime-buffer-properties)) - (setq opts (org-mime-get-export-options t)) - (should opts) + (should (org-mime-get-export-options t)) (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))) @@ -144,8 +142,9 @@ ;;; 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 (str + (orgBuf (generate-new-buffer "*org-mode-test-buf*"))) + (with-current-buffer orgBuf (insert "#+OPTIONS: toc:nil num:nil\n" "\n#+begin_example\n" @@ -153,19 +152,17 @@ "#+end_example\n") (org-mode) (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))) + (should (org-mime-get-export-options t)) + (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 +170,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,7 +192,7 @@ ;; Title, TOC, and Author. (ert-deftest test-org-mime-org-subtree-htmlize-ascii-opts-t () - (let (str opts) + (let (str orgBuf) (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*")) @@ -214,13 +211,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,7 +230,7 @@ (kill-buffer orgBuf))) (ert-deftest test-org-mime-org-subtree-htmlize-ascii-opts-nil () - (let (str opts) + (let (str orgBuf) (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*")) @@ -252,13 +249,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)) @@ -270,6 +267,7 @@ (kill-buffer orgBuf))) (ert-deftest test-org-mime-beautify-quoted-para-breaks () + (let (html expected) (setq html (concat "<p>\n" "Hello there\n" "</p>\n" @@ -296,8 +294,8 @@ "\n" "</div></blockquote>\n" "</p>\n")) - (setq beautified (org-mime-beautify-quoted html)) - (should (equal beautified expected))) + (should (equal (org-mime-beautify-quoted html) + expected)))) (ert-deftest test-org-mime-extract-non-org ()