branch: elpa/org-mime commit 1a57b9c926e8b23b93c8c376a6d37d34fc949285 Author: Chen Bin <chenbin...@gmail.com> Commit: Chen Bin <chenbin...@gmail.com>
support more quote title style --- org-mime.el | 24 ++++++++++++++++++------ test/org-mime-tests.el | 8 ++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/org-mime.el b/org-mime.el index 9c91bfaf1f..332b428b77 100644 --- a/org-mime.el +++ b/org-mime.el @@ -171,11 +171,12 @@ Default (nil) selects the original org file." :group 'org-mime :type 'string) -(defcustom org-mime-mail-quoted-separator - "^>>>>>[^>=]+==\\([^=\r\n]+\\)" - "Below this separator is mostly quoted mail." +(defcustom org-mime-mail-quoted-separators + '("^>>>>>[^>=]+==\\([^=\r\n]+\\)$" + "^\\(On [^\r\n]+ wrote:\\)$") + "Possible separators. Below the separator is mostly quoted mail." :group 'org-mime - :type 'string) + :type '(repeat string)) (defvar org-mime-export-options '(:with-latex dvipng) "Default export options which may override org buffer/subtree options. @@ -499,9 +500,20 @@ CURRENT-FILE is used to calculate full path of images." (list :secure-tags (nreverse secure-tags) :part-tags (nreverse part-tags))))) +(defun org-mime-find-quoted-separator (content) + "Find correct separator to extract quoted mail from CONTENT." + (let ((rlt (cl-find-if (lambda (p) + (string-match p content)) + org-mime-mail-quoted-separators))) + (when org-mime-debug + (message "org-mime-find-quoted-separator called => %s" rlt)) + rlt)) + (defun org-mime-extract-my-reply (content) "Extract my reply from CONTENT (no quoted content)." - (let* ((arr (split-string content org-mime-mail-quoted-separator)) + (let* ((quoted-separator (org-mime-find-quoted-separator content)) + (arr (if quoted-separator (split-string content quoted-separator) + (list content))) rlt) ;; extract reply @@ -509,7 +521,7 @@ CURRENT-FILE is used to calculate full path of images." ;; extract quoted mail (when (> (length arr) 1) - (when (string-match org-mime-mail-quoted-separator content) + (when (and quoted-separator (string-match quoted-separator content) ) (setq rlt (plist-put rlt 'REPLY-QUOTED-TITLE (string-trim (match-string 1 content))))) diff --git a/test/org-mime-tests.el b/test/org-mime-tests.el index ed27f80a20..ee74224055 100644 --- a/test/org-mime-tests.el +++ b/test/org-mime-tests.el @@ -304,4 +304,12 @@ (org-mime-revert-to-plain-text-mail) (should (string= (string-trim (buffer-string)) "--text follows this line--\ntest\nhello")))) + +(ert-deftest test-org-mime-reply-quoted-separator () + (should (not (org-mime-find-quoted-separator "No pattern"))) + (should (string= (org-mime-find-quoted-separator ">>>>> \"chen\" == chen bin <chen...@email.com> writes:") + "^>>>>>[^>=]+==\\([^=\r\n]+\\)$")) + (should (string= (org-mime-find-quoted-separator "On Sat, May 14 2022 at 23:30 -07, Chen Bin <notificati...@github.com> wrote:") + "^\\(On [^\r\n]+ wrote:\\)$"))) + (ert-run-tests-batch-and-exit)