Re: [DRAFT PATCH] modified notmuch-emacs-mua

Subject: Re: [DRAFT PATCH] modified notmuch-emacs-mua

Date: Wed, 29 Oct 2014 19:09:36 +0200

To: notmuch@notmuchmail.org

Cc:

From: Tomi Ollila


This mail id:1405026779-29966-1-git-send-email-tomi.ollila@iki.fi
has not got much attention, probably due it is marked as 'draft'
and as it was not marked 'needs-review' in nmbug (this is now changed).

As the script is IMO in good condition (is IMO feature-complete and robust)
the draftness comes from the commit message being blunt and the namual .rst
not (yet updated).

I've been using this version like 3-10 times per week for quite a long time
now. I normaly use the -nw, --to, --subject and --body options to send
work-related mail. Just yesterday I was planning to also use the --from
option to send email on (mutually agreed) behalf of a colleaque...

This is somewhat more complex than the older alternative at
id:1404244957-3671-1-git-send-email-david@tethera.net, but addresses
the comments I sent in id:m2k37thvq1.fsf@guru.guru-group.fi .

I think the script is straightforward enough for anyone who knows 
shell scripts a bit more than just the shiny surface ;)

This script also handles mailto: urls -- I just set firefox to run
this script on mailto: links and (in my case) emacs in my X desktop
appears with Message buffer filled with initial contents as expected.
If mailto: link had body content, then Message buffer was in modified
state (otherwise not!), which is a bit PITA to exit in case of accidental
clicks. I have a potential "fix" for that in a diff that otherwise contains
comment changes below -- whether the fix should be applied is a bit
controversial -- is there a chance that some other buffer is set to
non-modified state; I tried with emacsclient(1) interface (too) and
right buffer was set to non-modified state in this case too...

If users are interested to have this version of notmuch-emacs-mua
available in future notmuch versions I'll update the manual .rst,
pick David's manual building change and write suitable commit message to 
the forthcoming patch email.

Tomi

First the "commit message" from previous mail and then diff of further
changes after that:

> Highlights:
>
> * notmuch-emacs-mua without arguments runs (notmuch-hello)
>
> * runs emacs(1) in case emacsclient(1) fails to connect to running emacs
>
> * takes -nw option
>
> * handles mailto:
>
> * --from option when sending non-mailto: way
>
> * -i includes file --body[= ]string inserts string
> ---

diff --git a/notmuch-emacs-mua b/notmuch-emacs-mua
index b1696f7..2dfd160 100755
--- a/notmuch-emacs-mua
+++ b/notmuch-emacs-mua
@@ -24,14 +24,14 @@
 
 set -eu
 
-# "expand" '\' to '\\' & '"' to '\"'
+# "expand" '\' to '\\' and '"' to '\"'
 escape_optarg ()
 {
     OPTARG=${OPTARG//\\/\\\\}; OPTARG=${OPTARG//\"/\\\"}
 }
 
-# ditto, in case there is '\n' sequence in the source, otherwise
-# "expand" only trailing '\'s to '\\'s
+# ditto, in case there is '\"' sequence in the source,
+# otherwise "expand" only trailing '\'s to '\\'s
 escape_body_optarg ()
 {
     case ${OPTARG} in
@@ -54,6 +54,7 @@ exec_mua ()
     fi
     ${X:-exec} "$emacs" $W --eval "$*"
     exit
+    # unused alternative to the above
     ${X:-exec "$emacs" $W --eval} "$*"
 }
 
@@ -71,9 +72,11 @@ while
 	    continue
 	    ;;
 	mailto:*)
+	    # concatenate all args to one string, using ';' as a separator
 	    oIFS=$IFS; IFS=; OPTARG="$*" IFS=$oIFS
 	    escape_optarg
-	    exec_mua "(progn (require 'notmuch) (browse-url-mail \"$OPTARG\"))"
+	    exec_mua "(progn (require 'notmuch) (browse-url-mail \"$OPTARG\")
+		(set-buffer (window-buffer)) (set-buffer-modified-p nil))"
 	    exit
     esac
 
@@ -176,6 +179,7 @@ done
 
 # Positional parameters.
 for arg; do
+    # like escape_optarg, but for 'arg' variable
     arg=${arg//\\/\\\\}; arg=${arg//\"/\\\"}
     TO=${TO:+$TO, }${arg}
 done



Thread: