Skip to content

Commit

Permalink
Support removal of undesired headers from the original email
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jeremy-compostella committed Jul 16, 2021
1 parent 4c92c62 commit 6e02ad2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 19 additions & 8 deletions org-msg.el
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
(require 'mml)
(require 'org)
(require 'ox)
(require 'subr-x)
(require 'url-parse)
(require 'xml)

Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 6e02ad2

Please sign in to comment.