[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/org-mime 23cc52bb53 111/118: donot htmlize security signat
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/org-mime 23cc52bb53 111/118: donot htmlize security signature and attachment |
Date: |
Wed, 5 Jan 2022 07:58:51 -0500 (EST) |
branch: elpa/org-mime
commit 23cc52bb539c898de228fc438cd24ed10213bea3
Author: Chen Bin <chenbin.sh@gmail.com>
Commit: Chen Bin <chenbin.sh@gmail.com>
donot htmlize security signature and attachment
---
org-mime.el | 47 ++++++++++++++++++++++++++++++++++++++++++++---
test/org-mime-tests.el | 17 +++++++++++++++--
2 files changed, 59 insertions(+), 5 deletions(-)
diff --git a/org-mime.el b/org-mime.el
index de0912031e..c4df091dce 100644
--- a/org-mime.el
+++ b/org-mime.el
@@ -6,7 +6,7 @@
;; Maintainer: Chen Bin (redguardtoo)
;; Keywords: mime, mail, email, html
;; Homepage: http://github.com/org-mime/org-mime
-;; Version: 0.2.2
+;; Version: 0.2.3
;; Package-Requires: ((emacs "25.1"))
;; This file is not part of GNU Emacs.
@@ -467,13 +467,49 @@ CURRENT-FILE is used to calculate full path of images."
(goto-char (point-max))
(re-search-backward org-mime-mail-signature-separator nil t nil)))
+
+(defun org-mime-extract-non-org ()
+ "Extract content not in org format (gpg signature, attachments ...)."
+ (unless (org-region-active-p)
+ (let* (rlt str b e (old-pos (point)))
+ (goto-char (point-min))
+ (while (re-search-forward "<#secure \\|<#part " (point-max) t)
+ (setq str (match-string 0))
+ (setq b (match-beginning 0))
+ (cond
+ ;; one line gpg signature tag
+ ((string-match "^<#secure " str)
+ (setq e (line-end-position)))
+
+ ;; multi-lines attachment
+ ((string-match "^<#part " str)
+ (save-excursion
+ (unless (re-search-forward "<#/part>" (point-max) t)
+ (error (format "\"%s\" should have end tag." str)))
+ (setq e (match-end 0)))))
+
+ ;; delete tag
+ (when (and b e (< b e))
+ (push (buffer-substring-no-properties b e) rlt)
+ (delete-region b e))
+
+ ;; search next tag
+ (goto-char (point-min)))
+
+ ;; move cursor back to its original position
+ (goto-char old-pos)
+
+ (nreverse rlt))))
+
;;;###autoload
(defun org-mime-htmlize ()
"Export a portion of an email to html using `org-mode'.
If called with an active region only export that region, otherwise entire
body."
(interactive)
(when org-mime-debug (message "org-mime-htmlize called"))
+
(let* ((region-p (org-region-active-p))
+ (tags (org-mime-extract-non-org))
(html-start (funcall org-mime-find-html-start
(or (and region-p (region-beginning))
(org-mime-mail-body-begin))))
@@ -493,8 +529,13 @@ If called with an active region only export that region,
otherwise entire body."
;; delete current region
(delete-region html-start html-end)
(goto-char html-start)
- ;; insert new current
- (org-mime-insert-html-content plain file html opts)))
+
+ ;; insert converted html
+ (org-mime-insert-html-content plain file html opts)
+
+ ;; restore non-org tags
+ (dolist (tag tags)
+ (insert (concat "\n" tag "\n")))))
(defun org-mime-apply-html-hook (html)
"Apply HTML hook."
diff --git a/test/org-mime-tests.el b/test/org-mime-tests.el
index 8b95a28434..cdecd42f41 100644
--- a/test/org-mime-tests.el
+++ b/test/org-mime-tests.el
@@ -298,7 +298,20 @@
"</div></blockquote>\n"
"</p>\n"))
(setq beautified (org-mime-beautify-quoted html))
- (should (equal beautified expected))
-)
+ (should (equal beautified expected)))
+
+
+(ert-deftest test-org-mime-extract-non-org ()
+ (let* ((content (concat "*hello world\n"
+ "<#part type=\"application/pdf\" filename=\"1.pdl\"
disposition=attachment>\n<#/part>\n"
+ "<#secure method=pgpmime mode=sign>\n"))
+ tags)
+
+ (with-temp-buffer
+ (insert content)
+ (message-mode)
+ (setq tags (org-mime-extract-non-org)))
+ (should (string= (nth 0 tags) "<#part type=\"application/pdf\"
filename=\"1.pdl\" disposition=attachment>\n<#/part>"))
+ (should (string= (nth 1 tags) "<#secure method=pgpmime mode=sign>"))))
(ert-run-tests-batch-and-exit)
- [nongnu] elpa/org-mime 73c13fdd0b 075/118: Merge pull request #39 from czan/master, (continued)
- [nongnu] elpa/org-mime 73c13fdd0b 075/118: Merge pull request #39 from czan/master, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 1162095645 086/118: Catch signature in html convert, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 722a295672 088/118: Merge pull request #48 from ahttraga/sigfix, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 168fe3a6a1 092/118: Merge pull request #51 from borwickatuw/master, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 4e5d50789b 097/118: Clean up name of test file in comment, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 73fdd3f40d 098/118: Merge pull request #53 from tomheon/clean-up-test-header, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime d71f57dc0d 096/118: Add a simple test for quoting of multi-line paragraphs, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 5df12989cd 101/118: clean code, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime d725955399 105/118: stop bundling htmlize, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime e5345ae5b6 104/118: fixed ci, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 23cc52bb53 111/118: donot htmlize security signature and attachment,
ELPA Syncer <=
- [nongnu] elpa/org-mime d52a7b52b6 114/118: fixed revert plain text email bug, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime b1fc1cc53c 116/118: Fix byte-compiler warnings, ELPA Syncer, 2022/01/05
- [nongnu] elpa/org-mime 613969effc 118/118: Merge pull request #67 from skangas/silence-byte-compiler, ELPA Syncer, 2022/01/05