From 6e02ad2a669ab5fe45933ea0a60d3e6d5998b4ca Mon Sep 17 00:00:00 2001 From: Jeremy Compostella Date: Wed, 23 Jun 2021 15:34:40 -0700 Subject: [PATCH] Support removal of undesired headers from the original email Depending on the end user configuration, some headers such as the "Attachments:" header may appear in the rendered original email and then end up in the separator preceding the original email. To offer a solution without having to alter the end-user configuration, this patch introduces the `org-msg-undesirable-headers' customization variable. This variable list the undesirable headers name which will be deleted by the `org-msg-improve-reply-header' function. This patch addresses #119. Signed-off-by: Jeremy Compostella --- README.org | 2 ++ org-msg.el | 27 +++++++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/README.org b/README.org index 5b8e091..2f3de48 100644 --- a/README.org +++ b/README.org @@ -82,6 +82,8 @@ Alternatives list should be placed in increasing order of preference to meet [[h *OrgMsg* composes reply to HTML emails in [[https://en.wikipedia.org/wiki/Posting_style#Top-posting][top-posting]] style. This behavior can be disabled by setting ~org-msg-posting-style~ to any value other than ~top-posting~. +The original HTML message generated by gnus includes fields such as ~From~ and ~To~. Unfortunately, some less desirable field like ~attachment~ are sometimes added. These fields can be listed in ~org-msg-undesirable-headers~ to be automatically removed by *OrgMsg*. + In order to avoid CSS conflict, *OrgMsg* performs inline replacement when it generates the final HTML message. See the ~org-msg-enforce-css~ variable to customize the style (and the default ~org-msg-default-style~ variable for reference). Setting the org export option ~tex:dvipng~ or ~tex:dvisvgm~ is handeled correctly by this mode by producing inline images or inlining the generated SVG. Note that most mailclients however sadly do not display SVG content in mails so it might be best to stick to settings producing images unless you know your recipient's mailclient supports SVG. diff --git a/org-msg.el b/org-msg.el index fb59f8e..24ee1d5 100644 --- a/org-msg.el +++ b/org-msg.el @@ -41,6 +41,7 @@ (require 'mml) (require 'org) (require 'ox) +(require 'subr-x) (require 'url-parse) (require 'xml) @@ -153,6 +154,10 @@ Example: Can be either `top-posting' or nil." :type '(symbol)) +(defcustom org-msg-undesirable-headers '("^attachments?$") + "List of undesirable header to delete from the original email." + :type '(list regexp)) + (defcustom org-msg-dnd-protocol-alist '(("^file:" . org-msg-dnd-handle-file)) "The functions to call when a file drop is made." @@ -638,14 +643,20 @@ is the XML tree and CSS the style." (concat (car e) (cl-caddr e)))) (setcdr e (cl-cdddr e))) (setf e (cdr e))))) - ;; Add a bold property to the prefixes like "From", "Date", - ;; "Subject", ... - (org-msg-list-foreach (e (cdr div)) - (when (stringp (cadr e)) - (let ((prefix (car (split-string (cadr e) ":")))) - (setcar (cdr e) (replace-regexp-in-string prefix "" (cadr e))) - (setcdr e (cons `(b nil ,(capitalize prefix)) (cdr e))) - (setf e (cdr e))))) + ;; Add a bold property to the prefixes like "From", "Date", "Subject", + ;; ... This section also deletes the undesirable header lines as + ;; specified by `org-msg-undesirable-headers'. + (let ((e (cdr div))) + (while e + (if (stringp (cadr e)) + (let ((prefix (car (split-string (cadr e) ":")))) + (if (cl-find prefix org-msg-undesirable-headers + :test (lambda (x y) (string-match-p y (string-trim x)))) + (setcdr e (cdddr e)) + (setcar (cdr e) (replace-regexp-in-string prefix "" (cadr e))) + (setcdr e (cons `(b nil ,(capitalize prefix)) (cdr e))) + (setf e (cddr e)))) + (setf e (cdr e))))) ;; Transform mail addresses into "mailto" links (org-msg-list-foreach (e (cdr div)) (when (stringp (cadr e))