[PATCH v1 0/3] support for format=flowed display

classic Classic list List threaded Threaded
6 messages Options
David Edmondson David Edmondson
Reply | Threaded
Open this post in threaded view
|

[PATCH v1 0/3] support for format=flowed display


This patch improves the display of format=flowed text parts.

I suspect that format=flowed display and some of the other content
washing might interact in annoying ways, but the only way to be sure
is to see how people feel about the results.


David Edmondson (3):
  notmuch: Include the format parameter of text/plain parts
  emacs: Pass the part to text/plain hook functions
  emacs: Process format=flowed text

 emacs/notmuch-show.el |  5 +++--
 emacs/notmuch-wash.el | 24 +++++++++++++++++++-----
 notmuch-show.c        | 13 +++++++++++++
 3 files changed, 35 insertions(+), 7 deletions(-)

--
2.11.0

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
David Edmondson David Edmondson
Reply | Threaded
Open this post in threaded view
|

[PATCH v1 1/3] notmuch: Include the format parameter of text/plain parts

During formatted output, if a content type of a text/plain part
has a "format" paramter, include it in the output.
---
 notmuch-show.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/notmuch-show.c b/notmuch-show.c
index 07e9a5db..92d18bb8 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -708,6 +708,19 @@ format_part_sprinter (const void *ctx, sprinter_t *sp, mime_node_t *node,
     }
 
     if (GMIME_IS_PART (node->part)) {
+ /* Include the format parameter of text/plain parts if it
+ * exists, allowing the UI to adapt the display of the part as
+ * appropriate.
+ */
+ if (g_mime_content_type_is_type (content_type, "text", "plain")) {
+    const char *format =
+ g_mime_object_get_content_type_parameter (node->part, "format");
+    if (format) {
+ sp->map_key (sp, "format");
+ sp->string (sp, format);
+    }
+ }
+
  /* For non-HTML text parts, we include the content in the
  * JSON. Since JSON must be Unicode, we handle charset
  * decoding here and do not report a charset to the caller.
--
2.11.0

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
David Edmondson David Edmondson
Reply | Threaded
Open this post in threaded view
|

[PATCH v1 2/3] emacs: Pass the part to text/plain hook functions

In reply to this post by David Edmondson
Some text/plain hook functions may wish to access the details of the
part that is being manipulated.
---
 emacs/notmuch-show.el |  2 +-
 emacs/notmuch-wash.el | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 78f1af47..b3cefcd9 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -744,7 +744,7 @@ will return nil if the CID is unknown or cannot be retrieved."
     (save-excursion
       (save-restriction
  (narrow-to-region start (point-max))
- (run-hook-with-args 'notmuch-show-insert-text/plain-hook msg depth))))
+ (run-hook-with-args 'notmuch-show-insert-text/plain-hook msg part depth))))
   t)
 
 (defun notmuch-show-insert-part-text/calendar (msg part content-type nth depth button)
diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
index 54108d93..54275ec7 100644
--- a/emacs/notmuch-wash.el
+++ b/emacs/notmuch-wash.el
@@ -222,7 +222,7 @@ that PREFIX should not include a newline."
    :type button-type)))
   (overlay-put overlay 'notmuch-wash-button button))))))
 
-(defun notmuch-wash-excerpt-citations (msg depth)
+(defun notmuch-wash-excerpt-citations (msg part depth)
   "Excerpt citations and up to one signature."
   (goto-char (point-min))
   (beginning-of-line)
@@ -267,7 +267,7 @@ that PREFIX should not include a newline."
 
 ;;
 
-(defun notmuch-wash-elide-blank-lines (msg depth)
+(defun notmuch-wash-elide-blank-lines (msg part depth)
   "Elide leading, trailing and successive blank lines."
 
   ;; Algorithm derived from `article-strip-multiple-blank-lines' in
@@ -295,7 +295,7 @@ that PREFIX should not include a newline."
 
 ;;
 
-(defun notmuch-wash-tidy-citations (msg depth)
+(defun notmuch-wash-tidy-citations (msg part depth)
   "Improve the display of cited regions of a message.
 
 Perform several transformations on the message body:
@@ -326,7 +326,7 @@ Perform several transformations on the message body:
 
 ;;
 
-(defun notmuch-wash-wrap-long-lines (msg depth)
+(defun notmuch-wash-wrap-long-lines (msg part depth)
   "Wrap long lines in the message.
 
 If `notmuch-wash-wrap-lines-length' is a number, this will wrap
@@ -392,7 +392,7 @@ original filename the sender had."
   (or (notmuch-wash-subject-to-patch-sequence-number subject) 1)
   (notmuch-wash-subject-to-filename subject 52)))
 
-(defun notmuch-wash-convert-inline-patch-to-part (msg depth)
+(defun notmuch-wash-convert-inline-patch-to-part (msg part depth)
   "Convert an inline patch into a fake 'text/x-diff' attachment.
 
 Given that this function guesses whether a buffer includes a
--
2.11.0

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
David Edmondson David Edmondson
Reply | Threaded
Open this post in threaded view
|

[PATCH v1 3/3] emacs: Process format=flowed text

In reply to this post by David Edmondson
If a text/plain part is declared as format=flowed, apply the
appropriate transformation for display using flow-fill.el.
---
 emacs/notmuch-show.el |  3 ++-
 emacs/notmuch-wash.el | 14 ++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index b3cefcd9..823a2d19 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -90,7 +90,8 @@ visible for any given message."
   :group 'notmuch-show
   :group 'notmuch-hooks)
 
-(defcustom notmuch-show-insert-text/plain-hook '(notmuch-wash-wrap-long-lines
+(defcustom notmuch-show-insert-text/plain-hook '(notmuch-wash-format=flowed
+ notmuch-wash-wrap-long-lines
  notmuch-wash-tidy-citations
  notmuch-wash-elide-blank-lines
  notmuch-wash-excerpt-citations)
diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
index 54275ec7..d4f0e883 100644
--- a/emacs/notmuch-wash.el
+++ b/emacs/notmuch-wash.el
@@ -426,6 +426,20 @@ for error."
 
 ;;
 
+(require 'flow-fill)
+
+(defun notmuch-wash-format=flowed (msg part depth)
+  "If the current part content-type included 'format=flowed',
+apply the appropriate transformation."
+  (when (string= (plist-get part :format) "flowed")
+    ;; Adjust `fill-flowed-display-column' to allow for the indent
+    ;; that we will later apply to this content.
+    (let ((fill-flowed-display-column (- (eval fill-flowed-display-column)
+ (* depth notmuch-show-indent-messages-width))))
+      (fill-flowed))))
+
+;;
+
 (provide 'notmuch-wash)
 
 ;;; notmuch-wash.el ends here
--
2.11.0

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
David Bremner-2 David Bremner-2
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v1 1/3] notmuch: Include the format parameter of text/plain parts

In reply to this post by David Edmondson
David Edmondson <[hidden email]> writes:

> During formatted output, if a content type of a text/plain part
> has a "format" paramter, include it in the output.
> ---
>  notmuch-show.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/notmuch-show.c b/notmuch-show.c
> index 07e9a5db..92d18bb8 100644
> --- a/notmuch-show.c
> +++ b/notmuch-show.c
> @@ -708,6 +708,19 @@ format_part_sprinter (const void *ctx, sprinter_t *sp, mime_node_t *node,
>      }
>  
>      if (GMIME_IS_PART (node->part)) {
> + /* Include the format parameter of text/plain parts if it
> + * exists, allowing the UI to adapt the display of the part as
> + * appropriate.
> + */
> + if (g_mime_content_type_is_type (content_type, "text", "plain")) {
> +    const char *format =
> + g_mime_object_get_content_type_parameter (node->part, "format");
> +    if (format) {
> + sp->map_key (sp, "format");
> + sp->string (sp, format);
> +    }
> + }
> +
>   /* For non-HTML text parts, we include the content in the
>   * JSON. Since JSON must be Unicode, we handle charset
>   * decoding here and do not report a charset to the caller.

We need to update devel/schemata for this change.

Have you thought about the failure modes for mismatched notmuch.el <->
notmuch? Since you don't bump the format version, the emacs side has no
way of knowing if the notmuch side supports the 'format' key. That's
probably fine since the key is optional.
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
David Edmondson David Edmondson
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v1 1/3] notmuch: Include the format parameter of text/plain parts

On Saturday, 2018-12-22 at 07:41:37 +09, David Bremner wrote:

> David Edmondson <[hidden email]> writes:
>
>> During formatted output, if a content type of a text/plain part
>> has a "format" paramter, include it in the output.
>> ---
>>  notmuch-show.c | 13 +++++++++++++
>>  1 file changed, 13 insertions(+)
>>
>> diff --git a/notmuch-show.c b/notmuch-show.c
>> index 07e9a5db..92d18bb8 100644
>> --- a/notmuch-show.c
>> +++ b/notmuch-show.c
>> @@ -708,6 +708,19 @@ format_part_sprinter (const void *ctx, sprinter_t *sp, mime_node_t *node,
>>      }
>>  
>>      if (GMIME_IS_PART (node->part)) {
>> + /* Include the format parameter of text/plain parts if it
>> + * exists, allowing the UI to adapt the display of the part as
>> + * appropriate.
>> + */
>> + if (g_mime_content_type_is_type (content_type, "text", "plain")) {
>> +    const char *format =
>> + g_mime_object_get_content_type_parameter (node->part, "format");
>> +    if (format) {
>> + sp->map_key (sp, "format");
>> + sp->string (sp, format);
>> +    }
>> + }
>> +
>>   /* For non-HTML text parts, we include the content in the
>>   * JSON. Since JSON must be Unicode, we handle charset
>>   * decoding here and do not report a charset to the caller.
>
> We need to update devel/schemata for this change.

Will do in a v2.

> Have you thought about the failure modes for mismatched notmuch.el <->
> notmuch? Since you don't bump the format version, the emacs side has no
> way of knowing if the notmuch side supports the 'format' key. That's
> probably fine since the key is optional.

If notmuch-show.el is newer than notmuch it will never see the “format”
parameter and so will not attempt to fill the flowed text. This is the
same as the current behaviour.

If notmuch is newer than notmuch-show.el it will include the “format”
parameter but the notmuch-show.el will not look for it. This is the same
as the current behaviour.

I think that it's safe in all cases.

dme.
--
Facts don't do what I want them to.
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch