[PATCH 0/2] emacs: allow message/rfc822 to be inserted in the mailstore

classic Classic list List threaded Threaded
9 messages Options
Mark Walters Mark Walters
Reply | Threaded
Open this post in threaded view
|

[PATCH 0/2] emacs: allow message/rfc822 to be inserted in the mailstore

Several people including id:87bmnlko2o.fsf@len have asked to be able
to reply directly to message/rfc822 messages from the emacs
frontend. Doing that in emacs would be likely to be a little fragile
as all other replies are generated by the cli code.

This pair of patches provide an alternative approach: let the user
insert the attached message directly into the mailstore. Once it is
there, the user can reply as normal.

I have been running something like this for a long time (see
id:[hidden email] for my
earlier version) with no problems.

This new version includes some better error checking, and allows the
user to specify tags for the inserted message. The new version is not
heavily tested but seems to work.

Best wishes

Mark




Mark Walters (2):
  emacs: maildir fcc make insert more flexible
  emacs: show: allow user to insert rfc822 parts as messages

 emacs/notmuch-maildir-fcc.el | 16 ++++++++++------
 emacs/notmuch-show.el        | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 6 deletions(-)

--
2.1.4

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

[PATCH 1/2] emacs: maildir fcc make insert more flexible

This changeset makes the function
notmuch-maildir-fcc-with-notmuch-insert slightly more flexible by
allowing some of the prompts to be controlled by the caller.
---
 emacs/notmuch-maildir-fcc.el | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index 1551e8b..acff24d 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -227,7 +227,7 @@ should be a list of tag changes to apply to the inserted message."
     (apply 'notmuch-call-notmuch-process
    :stdin-string (buffer-string) "insert" args)))
 
-(defun notmuch-maildir-fcc-with-notmuch-insert (fcc-header &optional create)
+(defun notmuch-maildir-fcc-with-notmuch-insert (fcc-header &optional create header-name)
   "Store message with notmuch insert.
 
 The fcc-header should be of the form \"folder +tag1 -tag2\" where
@@ -239,7 +239,8 @@ quoting each space with an immediately preceding backslash
 or surrounding the entire folder name in double quotes.
 
 If CREATE is non-nil then create the folder if necessary."
-  (let* ((args (split-string-and-unquote fcc-header))
+  (let* ((header-name (or header-name "Fcc header"))
+ (args (split-string-and-unquote fcc-header))
  (folder (car args))
  (tags (cdr args)))
     (condition-case nil
@@ -250,14 +251,17 @@ If CREATE is non-nil then create the folder if necessary."
       ;; how to deal with it.
       (error
        (let ((response (notmuch-read-char-choice
- "Insert failed: (r)etry, (c)reate folder, (i)gnore, or (e)dit the header? "
+ (concat
+ "Insert failed: (r)etry, (c)reate folder, (i)gnore, or (e)dit the "
+ header-name "? ")
  '(?r ?c ?i ?e))))
  (case response
-       (?r (notmuch-maildir-fcc-with-notmuch-insert fcc-header))
-       (?c (notmuch-maildir-fcc-with-notmuch-insert fcc-header 't))
+       (?r (notmuch-maildir-fcc-with-notmuch-insert fcc-header nil header-name))
+       (?c (notmuch-maildir-fcc-with-notmuch-insert fcc-header 't header-name))
        (?i 't)
        (?e (notmuch-maildir-fcc-with-notmuch-insert
-    (read-from-minibuffer "Fcc header: " fcc-header)))))))))
+    (read-from-minibuffer (concat header-name ": ") fcc-header)
+    nil header-name))))))))
 
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
--
2.1.4

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

[PATCH 2/2] emacs: show: allow user to insert rfc822 parts as messages

In reply to this post by Mark Walters
This adds a part-handler function that uses notmuch-insert to insert
an rfc822 part as a message in its own right. This allows the user to
reply directly to that message.

We use notmuch-maildir-fcc-with-notmuch-insert as that has builtin
error handling/retry functionality, and it allows the user to specify
tags to identify the inserted message.

The format of the folder/tags line is the same as for Fcc: headers
when using notmuch insert.
---
 emacs/notmuch-show.el | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index cd901e4..b3717d0 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -143,6 +143,20 @@ indentation."
  (const :tag "View interactively"
  notmuch-show-interactively-view-part)))
 
+(defcustom notmuch-show-part-notmuch-insert-folder ""
+  "Default folder/tags to use when inserting rfc822 parts into the database.
+
+It should be of the form \"folder +tag1 -tag2\" where folder is
+the folder (relative to the notmuch mailstore) to store the
+message in, and tag1 and tag2 are tag changes to apply to the
+stored message. This string is split using
+`split-string-and-unquote', so a folder name containing spaces
+can be specified by quoting each space with an immediately
+preceding backslash or surrounding the entire folder name in
+double quotes."
+  :group 'notmuch-show
+  :type 'string)
+
 (defcustom notmuch-show-only-matching-messages nil
   "Only matching messages are shown by default."
   :type 'boolean
@@ -1448,6 +1462,7 @@ reset based on the original query."
     (define-key map "o" 'notmuch-show-interactively-view-part)
     (define-key map "|" 'notmuch-show-pipe-part)
     (define-key map "m" 'notmuch-show-choose-mime-of-part)
+    (define-key map "i" 'notmuch-show-notmuch-insert-part)
     (define-key map "?" 'notmuch-subkeymap-help)
     map)
   "Submap for part commands")
@@ -2463,6 +2478,26 @@ part to be treated as if it had that mime-type."
   (interactive)
   (notmuch-show-apply-to-current-part-handle #'mm-pipe-part))
 
+(defun notmuch-show--notmuch-insert-handle (handle)
+  "Notmuch insert the part associated with HANDLE."
+  ;; This is based on mm-pipe-part
+  (let* ((folder
+  (read-from-minibuffer "Folder/tags to insert part to: "
+ notmuch-show-part-notmuch-insert-folder)))
+    (mm-with-unibyte-buffer
+     (mm-insert-part handle)
+     (notmuch-maildir-fcc-with-notmuch-insert folder nil "Folder/tags to insert part to")
+     (message nil))))
+
+(defun notmuch-show-notmuch-insert-part ()
+  "If the current part is rfc822 then insert into the mailstore"
+  (interactive)
+  (let* ((part (notmuch-show-get-part-properties))
+ (computed-type (plist-get part :computed-type)))
+    (if (notmuch-match-content-type computed-type "message/rfc822")
+ (notmuch-show-apply-to-current-part-handle
+ #'notmuch-show--notmuch-insert-handle)
+      (message "Not a message/rfc822 part."))))
 
 (defun notmuch-show--mm-display-part (handle)
   "Use mm-display-part to display HANDLE in a new buffer.
--
2.1.4

_______________________________________________
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 1/2] emacs: maildir fcc make insert more flexible

In reply to this post by Mark Walters
On Monday, 2017-08-28 at 08:32:21 +0100, Mark Walters wrote:

> This changeset makes the function
> notmuch-maildir-fcc-with-notmuch-insert slightly more flexible by
> allowing some of the prompts to be controlled by the caller.
> ---
>  emacs/notmuch-maildir-fcc.el | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
> index 1551e8b..acff24d 100644
> --- a/emacs/notmuch-maildir-fcc.el
> +++ b/emacs/notmuch-maildir-fcc.el
> @@ -227,7 +227,7 @@ should be a list of tag changes to apply to the inserted message."
>      (apply 'notmuch-call-notmuch-process
>     :stdin-string (buffer-string) "insert" args)))
>  
> -(defun notmuch-maildir-fcc-with-notmuch-insert (fcc-header &optional create)
> +(defun notmuch-maildir-fcc-with-notmuch-insert (fcc-header &optional create header-name)

Given that this is not FCC specific, perhaps rename it?

>    "Store message with notmuch insert.
>  
>  The fcc-header should be of the form \"folder +tag1 -tag2\" where

I realise that this patch set didn't add this string, but it is mildly
ridiculous. There's no reason that we couldn't use a list, where a
leading “+” or “-” indicates a tag and anything else is a folder.

Even two variables (one for folder and another for tags) would be an
improvement

> @@ -239,7 +239,8 @@ quoting each space with an immediately preceding backslash
>  or surrounding the entire folder name in double quotes.
>  
>  If CREATE is non-nil then create the folder if necessary."
> -  (let* ((args (split-string-and-unquote fcc-header))
> +  (let* ((header-name (or header-name "Fcc header"))
> + (args (split-string-and-unquote fcc-header))
>   (folder (car args))
>   (tags (cdr args)))
>      (condition-case nil
> @@ -250,14 +251,17 @@ If CREATE is non-nil then create the folder if necessary."
>        ;; how to deal with it.
>        (error
>         (let ((response (notmuch-read-char-choice
> - "Insert failed: (r)etry, (c)reate folder, (i)gnore, or (e)dit the header? "
> + (concat
> + "Insert failed: (r)etry, (c)reate folder, (i)gnore, or (e)dit the "
> + header-name "? ")
>   '(?r ?c ?i ?e))))
>   (case response
> -       (?r (notmuch-maildir-fcc-with-notmuch-insert fcc-header))
> -       (?c (notmuch-maildir-fcc-with-notmuch-insert fcc-header 't))
> +       (?r (notmuch-maildir-fcc-with-notmuch-insert fcc-header nil header-name))
> +       (?c (notmuch-maildir-fcc-with-notmuch-insert fcc-header 't header-name))
>         (?i 't)
>         (?e (notmuch-maildir-fcc-with-notmuch-insert
> -    (read-from-minibuffer "Fcc header: " fcc-header)))))))))
> +    (read-from-minibuffer (concat header-name ": ") fcc-header)
> +    nil header-name))))))))
>  
>  
>  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> --
> 2.1.4
>
> _______________________________________________
> notmuch mailing list
> [hidden email]
> https://notmuchmail.org/mailman/listinfo/notmuch

dme.
--
Walk without rhythm and it won't attract the worm.
_______________________________________________
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 2/2] emacs: show: allow user to insert rfc822 parts as messages

In reply to this post by Mark Walters
On Monday, 2017-08-28 at 08:32:22 +0100, Mark Walters wrote:

> This adds a part-handler function that uses notmuch-insert to insert
> an rfc822 part as a message in its own right. This allows the user to
> reply directly to that message.
>
> We use notmuch-maildir-fcc-with-notmuch-insert as that has builtin
> error handling/retry functionality, and it allows the user to specify
> tags to identify the inserted message.
>
> The format of the folder/tags line is the same as for Fcc: headers
> when using notmuch insert.
> ---
>  emacs/notmuch-show.el | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
>
> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
> index cd901e4..b3717d0 100644
> --- a/emacs/notmuch-show.el
> +++ b/emacs/notmuch-show.el
> @@ -143,6 +143,20 @@ indentation."
>   (const :tag "View interactively"
>   notmuch-show-interactively-view-part)))
>  
> +(defcustom notmuch-show-part-notmuch-insert-folder ""
> +  "Default folder/tags to use when inserting rfc822 parts into the database.
> +
> +It should be of the form \"folder +tag1 -tag2\" where folder is

See previous comments.

> +the folder (relative to the notmuch mailstore) to store the
> +message in, and tag1 and tag2 are tag changes to apply to the
> +stored message. This string is split using
> +`split-string-and-unquote', so a folder name containing spaces
> +can be specified by quoting each space with an immediately
> +preceding backslash or surrounding the entire folder name in
> +double quotes."
> +  :group 'notmuch-show
> +  :type 'string)
> +
>  (defcustom notmuch-show-only-matching-messages nil
>    "Only matching messages are shown by default."
>    :type 'boolean
> @@ -1448,6 +1462,7 @@ reset based on the original query."
>      (define-key map "o" 'notmuch-show-interactively-view-part)
>      (define-key map "|" 'notmuch-show-pipe-part)
>      (define-key map "m" 'notmuch-show-choose-mime-of-part)
> +    (define-key map "i" 'notmuch-show-notmuch-insert-part)
>      (define-key map "?" 'notmuch-subkeymap-help)
>      map)
>    "Submap for part commands")
> @@ -2463,6 +2478,26 @@ part to be treated as if it had that mime-type."
>    (interactive)
>    (notmuch-show-apply-to-current-part-handle #'mm-pipe-part))
>  
> +(defun notmuch-show--notmuch-insert-handle (handle)
> +  "Notmuch insert the part associated with HANDLE."
> +  ;; This is based on mm-pipe-part

Missing a period.

> +  (let* ((folder
> +  (read-from-minibuffer "Folder/tags to insert part to: "
> + notmuch-show-part-notmuch-insert-folder)))
> +    (mm-with-unibyte-buffer
> +     (mm-insert-part handle)
> +     (notmuch-maildir-fcc-with-notmuch-insert folder nil "Folder/tags to insert part to")
> +     (message nil))))

Why this? It would be nice to have a comment explaining it.

> +
> +(defun notmuch-show-notmuch-insert-part ()
> +  "If the current part is rfc822 then insert into the mailstore"
> +  (interactive)
> +  (let* ((part (notmuch-show-get-part-properties))
> + (computed-type (plist-get part :computed-type)))
> +    (if (notmuch-match-content-type computed-type "message/rfc822")
> + (notmuch-show-apply-to-current-part-handle
> + #'notmuch-show--notmuch-insert-handle)
> +      (message "Not a message/rfc822 part."))))
>  
>  (defun notmuch-show--mm-display-part (handle)
>    "Use mm-display-part to display HANDLE in a new buffer.
> --
> 2.1.4
>
> _______________________________________________
> notmuch mailing list
> [hidden email]
> https://notmuchmail.org/mailman/listinfo/notmuch

dme.
--
All those lines and circles, to me, a mystery.
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
Mark Walters Mark Walters
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/2] emacs: maildir fcc make insert more flexible

In reply to this post by David Edmondson

Hi

Thanks for the review.

On Mon, 28 Aug 2017, David Edmondson <[hidden email]> wrote:

> On Monday, 2017-08-28 at 08:32:21 +0100, Mark Walters wrote:
>
>> This changeset makes the function
>> notmuch-maildir-fcc-with-notmuch-insert slightly more flexible by
>> allowing some of the prompts to be controlled by the caller.
>> ---
>>  emacs/notmuch-maildir-fcc.el | 16 ++++++++++------
>>  1 file changed, 10 insertions(+), 6 deletions(-)
>>
>> diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
>> index 1551e8b..acff24d 100644
>> --- a/emacs/notmuch-maildir-fcc.el
>> +++ b/emacs/notmuch-maildir-fcc.el
>> @@ -227,7 +227,7 @@ should be a list of tag changes to apply to the inserted message."
>>      (apply 'notmuch-call-notmuch-process
>>     :stdin-string (buffer-string) "insert" args)))
>>  
>> -(defun notmuch-maildir-fcc-with-notmuch-insert (fcc-header &optional create)
>> +(defun notmuch-maildir-fcc-with-notmuch-insert (fcc-header &optional create header-name)
>
> Given that this is not FCC specific, perhaps rename it?

Yes that might make sense.

>
>>    "Store message with notmuch insert.
>>  
>>  The fcc-header should be of the form \"folder +tag1 -tag2\" where
>
> I realise that this patch set didn't add this string, but it is mildly
> ridiculous. There's no reason that we couldn't use a list, where a
> leading “+” or “-” indicates a tag and anything else is a folder.
>
> Even two variables (one for folder and another for tags) would be an
> improvement

The reason for this choice is that, when writing the postpone code, I
wanted to keep within the message mode compose world, which has the fcc
header as a string.

I think I would also only like to be queried once when inserting. Or are
you suggesting that the user types in a lisp list?

Best wishes

Mark




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

Re: [PATCH 2/2] emacs: show: allow user to insert rfc822 parts as messages

In reply to this post by David Edmondson
>
>> +  (let* ((folder
>> +  (read-from-minibuffer "Folder/tags to insert part to: "
>> + notmuch-show-part-notmuch-insert-folder)))
>> +    (mm-with-unibyte-buffer
>> +     (mm-insert-part handle)
>> +     (notmuch-maildir-fcc-with-notmuch-insert folder nil "Folder/tags to insert part to")
>> +     (message nil))))
>
> Why this? It would be nice to have a comment explaining it.

Assuming you mean the message nil bit, This is actually me being dim. I
want to remove things like the retry message. But it would be much better
to make the insert-part function return something saying whether it
succeeded or not, and then give a useful message.

Best wishes

Mark

_______________________________________________
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 1/2] emacs: maildir fcc make insert more flexible

In reply to this post by Mark Walters
On Monday, 2017-08-28 at 12:27:03 +0100, Mark Walters wrote:

>>>  The fcc-header should be of the form \"folder +tag1 -tag2\" where
>>
>> I realise that this patch set didn't add this string, but it is mildly
>> ridiculous. There's no reason that we couldn't use a list, where a
>> leading “+” or “-” indicates a tag and anything else is a folder.
>>
>> Even two variables (one for folder and another for tags) would be an
>> improvement
>
> The reason for this choice is that, when writing the postpone code, I
> wanted to keep within the message mode compose world, which has the fcc
> header as a string.

You could add whatever headers you like.

> I think I would also only like to be queried once when inserting. Or are
> you suggesting that the user types in a lisp list?

If we prompt for it then we could do multiple prompts - we already have
a completion-capable reader for tags.

dme.
--
I'm catching up with myself!
_______________________________________________
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 1/2] emacs: maildir fcc make insert more flexible

David Edmondson <[hidden email]> writes:

> On Monday, 2017-08-28 at 12:27:03 +0100, Mark Walters wrote:
>
>>>>  The fcc-header should be of the form \"folder +tag1 -tag2\" where
>>>
>>> I realise that this patch set didn't add this string, but it is mildly
>>> ridiculous. There's no reason that we couldn't use a list, where a
>>> leading “+” or “-” indicates a tag and anything else is a folder.
>>>
>>> Even two variables (one for folder and another for tags) would be an
>>> improvement
>>
>> The reason for this choice is that, when writing the postpone code, I
>> wanted to keep within the message mode compose world, which has the fcc
>> header as a string.
>
> You could add whatever headers you like.
>
>> I think I would also only like to be queried once when inserting. Or are
>> you suggesting that the user types in a lisp list?
>
> If we prompt for it then we could do multiple prompts - we already have
> a completion-capable reader for tags.
>

There was in fact a request for this feature in
id:87shgtgiux.fsf@len. OTOH, it seems like a lot of this discussion
talks about enhancing or re-factoring the existing draft/fcc
handling. Would it be possible to seperate that out, even if it means a
list of pre-requisite changes before this feature is added?

d
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch