emacs-elpa-diffs
[Top][All Lists]
Advanced

[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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]