unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#39230: [PATCH] Expand text/html regardless of it position in the MIME tree
@ 2020-01-21 23:01 Jeremy Compostella
  2020-02-12 18:18 ` Jérémy Compostella
  2020-02-19 13:52 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 5+ messages in thread
From: Jeremy Compostella @ 2020-01-21 23:01 UTC (permalink / raw)
  To: 39230

If the text/html part is not the unique part of the email,
mml-generate-mime does not expand it to a related multipart. This
break uses cases like PGP signing of an HTML email including images.

For instance, if you compose an email with the <multipart sign=pgpmime>
and a <part type="text/html" disposition=inline>, the second part is
not expanded into a multipart related and the images are not included.

Signed-off-by: Jeremy Compostella <jeremy.compostella@gmail.com>
---
 lisp/gnus/mml.el | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/lisp/gnus/mml.el b/lisp/gnus/mml.el
index cdd8f3d3a5..3d86c5bc40 100644
--- a/lisp/gnus/mml.el
+++ b/lisp/gnus/mml.el
@@ -487,11 +487,8 @@ type detected."
 		 (= (length cont) 1)
 		 content-type)
 	(setcdr (assq 'type (cdr (car cont))) content-type))
-      (when (and (consp (car cont))
-		 (= (length cont) 1)
-		 (fboundp 'libxml-parse-html-region)
-		 (equal (cdr (assq 'type (car cont))) "text/html"))
-	(setq cont (mml-expand-html-into-multipart-related (car cont))))
+      (when (fboundp 'libxml-parse-html-region)
+	(setq cont (mapcar 'mml-expand-all-html-into-multipart-related cont)))
       (prog1
 	  (with-temp-buffer
 	    (set-buffer-multibyte nil)
@@ -510,6 +507,18 @@ type detected."
 	    (buffer-string))
 	(setq message-options options)))))
 
+(defun mml-expand-all-html-into-multipart-related (cont)
+  (cond ((and (eq (car cont) 'part)
+	      (equal (cdr (assq 'type cont)) "text/html"))
+	 (mml-expand-html-into-multipart-related cont))
+	((eq (car cont) 'multipart)
+	 (let ((cur (cdr cont)))
+	   (while (consp cur)
+	     (setcar cur (mml-expand-all-html-into-multipart-related (car cur)))
+	     (setf cur (cdr cur))))
+	 cont)
+	(t cont)))
+
 (defun mml-expand-html-into-multipart-related (cont)
   (let ((new-parts nil)
 	(cid 1))
-- 
2.24.1






^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#39230: [PATCH] Expand text/html regardless of it position in the MIME tree
  2020-01-21 23:01 bug#39230: [PATCH] Expand text/html regardless of it position in the MIME tree Jeremy Compostella
@ 2020-02-12 18:18 ` Jérémy Compostella
  2020-02-28 17:13   ` Jérémy Compostella
  2020-02-19 13:52 ` Lars Ingebrigtsen
  1 sibling, 1 reply; 5+ messages in thread
From: Jérémy Compostella @ 2020-02-12 18:18 UTC (permalink / raw)
  To: 39230


[-- Attachment #1.1: Type: text/plain, Size: 2785 bytes --]

Hi,

I would really appreciate if I could receive a feedback on this patch.  I
can't send GPG HTML email because of this limitation and this is is also
blocking an issue reported of my org-msg module.

I have attached the patch here as I have fixed a typo in the commit
headline.

Let me know if I need to address this patch to another mailing list.

Regards,
Jeremy
.

On Tue, Jan 21, 2020 at 4:01 PM Jeremy Compostella <
jeremy.compostella@gmail.com> wrote:

> If the text/html part is not the unique part of the email,
> mml-generate-mime does not expand it to a related multipart. This
> break uses cases like PGP signing of an HTML email including images.
>
> For instance, if you compose an email with the <multipart sign=pgpmime>
> and a <part type="text/html" disposition=inline>, the second part is
> not expanded into a multipart related and the images are not included.
>
> Signed-off-by: Jeremy Compostella <jeremy.compostella@gmail.com>
> ---
>  lisp/gnus/mml.el | 19 ++++++++++++++-----
>  1 file changed, 14 insertions(+), 5 deletions(-)
>
> diff --git a/lisp/gnus/mml.el b/lisp/gnus/mml.el
> index cdd8f3d3a5..3d86c5bc40 100644
> --- a/lisp/gnus/mml.el
> +++ b/lisp/gnus/mml.el
> @@ -487,11 +487,8 @@ type detected."
>                  (= (length cont) 1)
>                  content-type)
>         (setcdr (assq 'type (cdr (car cont))) content-type))
> -      (when (and (consp (car cont))
> -                (= (length cont) 1)
> -                (fboundp 'libxml-parse-html-region)
> -                (equal (cdr (assq 'type (car cont))) "text/html"))
> -       (setq cont (mml-expand-html-into-multipart-related (car cont))))
> +      (when (fboundp 'libxml-parse-html-region)
> +       (setq cont (mapcar 'mml-expand-all-html-into-multipart-related
> cont)))
>        (prog1
>           (with-temp-buffer
>             (set-buffer-multibyte nil)
> @@ -510,6 +507,18 @@ type detected."
>             (buffer-string))
>         (setq message-options options)))))
>
> +(defun mml-expand-all-html-into-multipart-related (cont)
> +  (cond ((and (eq (car cont) 'part)
> +             (equal (cdr (assq 'type cont)) "text/html"))
> +        (mml-expand-html-into-multipart-related cont))
> +       ((eq (car cont) 'multipart)
> +        (let ((cur (cdr cont)))
> +          (while (consp cur)
> +            (setcar cur (mml-expand-all-html-into-multipart-related (car
> cur)))
> +            (setf cur (cdr cur))))
> +        cont)
> +       (t cont)))
> +
>  (defun mml-expand-html-into-multipart-related (cont)
>    (let ((new-parts nil)
>         (cid 1))
> --
> 2.24.1
>
>

-- 
« Si debugger, c'est supprimer des bugs, alors programmer ne peut être que
les ajouter » - Edsger Dijkstra

[-- Attachment #1.2: Type: text/html, Size: 3650 bytes --]

[-- Attachment #2: 0001-Expand-text-html-regardless-of-its-position-in-the-M.patch --]
[-- Type: text/x-patch, Size: 2105 bytes --]

From a3b24bbc6a738e60bc74df3d10822161d742d417 Mon Sep 17 00:00:00 2001
From: Jeremy Compostella <jeremy.compostella@gmail.com>
Date: Tue, 21 Jan 2020 15:41:22 -0700
Subject: [PATCH] Expand text/html regardless of its position in the MIME tree

If the text/html part is not the unique part of the email,
mml-generate-mime does not expand it to a related multipart. This
break uses cases like PGP signing of an HTML email including images.

For instance, if you compose an email with the <#multipart sign=pgpmime>
and a <#part type="text/html" disposition=inline>, the second part is
not expanded into a multipart related and the images are not included.

Signed-off-by: Jeremy Compostella <jeremy.compostella@gmail.com>
---
 lisp/gnus/mml.el | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/lisp/gnus/mml.el b/lisp/gnus/mml.el
index cdd8f3d3a5..3d86c5bc40 100644
--- a/lisp/gnus/mml.el
+++ b/lisp/gnus/mml.el
@@ -487,11 +487,8 @@ type detected."
 		 (= (length cont) 1)
 		 content-type)
 	(setcdr (assq 'type (cdr (car cont))) content-type))
-      (when (and (consp (car cont))
-		 (= (length cont) 1)
-		 (fboundp 'libxml-parse-html-region)
-		 (equal (cdr (assq 'type (car cont))) "text/html"))
-	(setq cont (mml-expand-html-into-multipart-related (car cont))))
+      (when (fboundp 'libxml-parse-html-region)
+	(setq cont (mapcar 'mml-expand-all-html-into-multipart-related cont)))
       (prog1
 	  (with-temp-buffer
 	    (set-buffer-multibyte nil)
@@ -510,6 +507,18 @@ type detected."
 	    (buffer-string))
 	(setq message-options options)))))
 
+(defun mml-expand-all-html-into-multipart-related (cont)
+  (cond ((and (eq (car cont) 'part)
+	      (equal (cdr (assq 'type cont)) "text/html"))
+	 (mml-expand-html-into-multipart-related cont))
+	((eq (car cont) 'multipart)
+	 (let ((cur (cdr cont)))
+	   (while (consp cur)
+	     (setcar cur (mml-expand-all-html-into-multipart-related (car cur)))
+	     (setf cur (cdr cur))))
+	 cont)
+	(t cont)))
+
 (defun mml-expand-html-into-multipart-related (cont)
   (let ((new-parts nil)
 	(cid 1))
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#39230: [PATCH] Expand text/html regardless of it position in the MIME tree
  2020-01-21 23:01 bug#39230: [PATCH] Expand text/html regardless of it position in the MIME tree Jeremy Compostella
  2020-02-12 18:18 ` Jérémy Compostella
@ 2020-02-19 13:52 ` Lars Ingebrigtsen
  1 sibling, 0 replies; 5+ messages in thread
From: Lars Ingebrigtsen @ 2020-02-19 13:52 UTC (permalink / raw)
  To: Jeremy Compostella; +Cc: 39230

Jeremy Compostella <jeremy.compostella@gmail.com> writes:

> If the text/html part is not the unique part of the email,
> mml-generate-mime does not expand it to a related multipart. This
> break uses cases like PGP signing of an HTML email including images.
>
> For instance, if you compose an email with the <multipart sign=pgpmime>
> and a <part type="text/html" disposition=inline>, the second part is
> not expanded into a multipart related and the images are not included.

Makes sense.  I've now applied the patch to Emacs 28.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#39230: [PATCH] Expand text/html regardless of it position in the MIME tree
  2020-02-12 18:18 ` Jérémy Compostella
@ 2020-02-28 17:13   ` Jérémy Compostella
  2020-03-14 11:45     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Jérémy Compostella @ 2020-02-28 17:13 UTC (permalink / raw)
  To: 39230

[-- Attachment #1: Type: text/plain, Size: 4133 bytes --]

An issue has been identified with this patch for which I wrote a fix.

I ran many tests and combination with this additional patch (see
attachement) and I could not find any issue left.

The reason I missed this obvious bug was my configuration using my
`org-msg' module which has an advice on
`mml-expand-html-into-multipart-related' to workaround the limitation
that my previous patch addresses.

The issue originates from the fact that the
`mml-expand-html-into-multipart-related' function returns a list of
list for an untouched part while it returns a simple list for expanded
multipart.  The recursive engine of
`mml-expand-all-html-into-multipart-related' is not handling
this.  Considering that the `mml-expand-html-into-multipart-related'
function is only used by mml as an internal function, IMO the best
approach is to make it consistent on its potential return values
structure. The patch I am submitting here makes
`mml-expand-html-into-multipart-related' returns a simple list
regardless of if it is a part or a multipart.

On Wed, Feb 12, 2020 at 11:18 AM Jérémy Compostella
<jeremy.compostella@gmail.com> wrote:
>
> Hi,
>
> I would really appreciate if I could receive a feedback on this patch.  I can't send GPG HTML email because of this limitation and this is is also blocking an issue reported of my org-msg module.
>
> I have attached the patch here as I have fixed a typo in the commit headline.
>
> Let me know if I need to address this patch to another mailing list.
>
> Regards,
> Jeremy
> .
>
> On Tue, Jan 21, 2020 at 4:01 PM Jeremy Compostella <jeremy.compostella@gmail.com> wrote:
>>
>> If the text/html part is not the unique part of the email,
>> mml-generate-mime does not expand it to a related multipart. This
>> break uses cases like PGP signing of an HTML email including images.
>>
>> For instance, if you compose an email with the <multipart sign=pgpmime>
>> and a <part type="text/html" disposition=inline>, the second part is
>> not expanded into a multipart related and the images are not included.
>>
>> Signed-off-by: Jeremy Compostella <jeremy.compostella@gmail.com>
>> ---
>>  lisp/gnus/mml.el | 19 ++++++++++++++-----
>>  1 file changed, 14 insertions(+), 5 deletions(-)
>>
>> diff --git a/lisp/gnus/mml.el b/lisp/gnus/mml.el
>> index cdd8f3d3a5..3d86c5bc40 100644
>> --- a/lisp/gnus/mml.el
>> +++ b/lisp/gnus/mml.el
>> @@ -487,11 +487,8 @@ type detected."
>>                  (= (length cont) 1)
>>                  content-type)
>>         (setcdr (assq 'type (cdr (car cont))) content-type))
>> -      (when (and (consp (car cont))
>> -                (= (length cont) 1)
>> -                (fboundp 'libxml-parse-html-region)
>> -                (equal (cdr (assq 'type (car cont))) "text/html"))
>> -       (setq cont (mml-expand-html-into-multipart-related (car cont))))
>> +      (when (fboundp 'libxml-parse-html-region)
>> +       (setq cont (mapcar 'mml-expand-all-html-into-multipart-related cont)))
>>        (prog1
>>           (with-temp-buffer
>>             (set-buffer-multibyte nil)
>> @@ -510,6 +507,18 @@ type detected."
>>             (buffer-string))
>>         (setq message-options options)))))
>>
>> +(defun mml-expand-all-html-into-multipart-related (cont)
>> +  (cond ((and (eq (car cont) 'part)
>> +             (equal (cdr (assq 'type cont)) "text/html"))
>> +        (mml-expand-html-into-multipart-related cont))
>> +       ((eq (car cont) 'multipart)
>> +        (let ((cur (cdr cont)))
>> +          (while (consp cur)
>> +            (setcar cur (mml-expand-all-html-into-multipart-related (car cur)))
>> +            (setf cur (cdr cur))))
>> +        cont)
>> +       (t cont)))
>> +
>>  (defun mml-expand-html-into-multipart-related (cont)
>>    (let ((new-parts nil)
>>         (cid 1))
>> --
>> 2.24.1
>>
>
>
> --
> « Si debugger, c'est supprimer des bugs, alors programmer ne peut être que les ajouter » - Edsger Dijkstra



-- 
« Si debugger, c'est supprimer des bugs, alors programmer ne peut être
que les ajouter » - Edsger Dijkstra

[-- Attachment #2: 0001-Fix-nesting-list.patch --]
[-- Type: text/x-patch, Size: 1265 bytes --]

From 0bcdd270715976e1dbe3b096f388f7f3d6689831 Mon Sep 17 00:00:00 2001
From: Jeremy Compostella <jeremy.compostella@gmail.com>
Date: Sat, 22 Feb 2020 10:58:25 -0700
Subject: [PATCH] Fix nesting list

* lisp/gnus/mml.el (mml-expand-html-into-multipart-related): This is
function is now called by a recursive
engine (mml-expand-all-html-into-multipart-related).  The structure of
the returned value should be identical between an untouched part and a
expanded multipart.
---
 lisp/gnus/mml.el | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/lisp/gnus/mml.el b/lisp/gnus/mml.el
index 3d86c5bc40..2006837d6a 100644
--- a/lisp/gnus/mml.el
+++ b/lisp/gnus/mml.el
@@ -547,8 +547,7 @@ type detected."
 			new-parts))
 		(setq cid (1+ cid)))))))
       ;; We have local images that we want to include.
-      (if (not new-parts)
-	  (list cont)
+      (when new-parts
 	(setcdr (assq 'contents cont) (buffer-string))
 	(setq cont
 	      (nconc (list 'multipart (cons 'type "related"))
@@ -561,8 +560,8 @@ type detected."
 				       (nth 1 new-part)
 				       (nth 2 new-part))
 				    (id . ,(concat "<" (nth 0 new-part)
-						   ">")))))))
-	cont))))
+						   ">"))))))))
+      cont)))
 
 (autoload 'image-property "image")
 
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#39230: [PATCH] Expand text/html regardless of it position in the MIME tree
  2020-02-28 17:13   ` Jérémy Compostella
@ 2020-03-14 11:45     ` Lars Ingebrigtsen
  0 siblings, 0 replies; 5+ messages in thread
From: Lars Ingebrigtsen @ 2020-03-14 11:45 UTC (permalink / raw)
  To: Jérémy Compostella; +Cc: 39230

Jérémy Compostella <jeremy.compostella@gmail.com> writes:

> The reason I missed this obvious bug was my configuration using my
> `org-msg' module which has an advice on
> `mml-expand-html-into-multipart-related' to workaround the limitation
> that my previous patch addresses.

Thanks; applied to Emacs 28.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-03-14 11:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-01-21 23:01 bug#39230: [PATCH] Expand text/html regardless of it position in the MIME tree Jeremy Compostella
2020-02-12 18:18 ` Jérémy Compostella
2020-02-28 17:13   ` Jérémy Compostella
2020-03-14 11:45     ` Lars Ingebrigtsen
2020-02-19 13:52 ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).