unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* Modify message after send...?
@ 2015-07-19  4:59 mailinglists
  2015-07-19  7:59 ` David Bremner
  2015-07-22  0:21 ` David Mazieres
  0 siblings, 2 replies; 5+ messages in thread
From: mailinglists @ 2015-07-19  4:59 UTC (permalink / raw)
  To: notmuch

Hi,

I use notmuch via Emacs.

Here's what I want:

When I hit C-c C-c to send a message, I'd like it to be passed to a
script (likely a Python one, although I may consider an Elisp function
if an external script is not possible) for modification of headers,
before it is sent to the MTA (Postfix in my case). A bonus would be to
have the modified message stored in the FCC location, instead of the
original one.

Is this possible? An alternative may be to modify the message /before/
it goes to message-send-and-exit. I'm inexperienced in Elisp - would
this be via what's called "advising"?

BTW, all I really want to do is modify the From: field based on the
recipients (for every email, with no default From). I'll welcome
suggestions for existing ways to do that. I Googled a little, but didn't
find a clear good solution. Furthermore, I expect over time the rules by
which I pick the From: field will get more complex than my knowledge of
Elisp.

Thanks.

-- 
My sister opened a computer store in Hawaii. She sells C shells down by
the seashore.


                    /\  /\               /\  /
                   /  \/  \ u e e n     /  \/  a w a z
                       >>>>>>mueen@nawaz.org<<<<<<
                                   anl

 

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

* Re: Modify message after send...?
  2015-07-19  4:59 Modify message after send...? mailinglists
@ 2015-07-19  7:59 ` David Bremner
  2015-07-19  8:22   ` Mark Walters
  2015-07-19 16:57   ` MN
  2015-07-22  0:21 ` David Mazieres
  1 sibling, 2 replies; 5+ messages in thread
From: David Bremner @ 2015-07-19  7:59 UTC (permalink / raw)
  To: mailinglists, notmuch

mailinglists@nawaz.org writes:

> BTW, all I really want to do is modify the From: field based on the
> recipients (for every email, with no default From). I'll welcome
> suggestions for existing ways to do that. I Googled a little, but didn't
> find a clear good solution. Furthermore, I expect over time the rules by
> which I pick the From: field will get more complex than my knowledge of
> Elisp.

I'm afraid it's a bit "some-assembly-required", but let me mention one
possible solution.

At least if you just want to have a regular expression match on the
recipient, then the example configuration in message-templ [1] may be
enough to get you started. You'd have to either call
message-templ-config-exec in a hook, or bind it to a key and call it
manually to set up the headers before sending.

[1]: http://pivot.cs.unb.ca/git?p=message-templ.git;a=tree

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

* Re: Modify message after send...?
  2015-07-19  7:59 ` David Bremner
@ 2015-07-19  8:22   ` Mark Walters
  2015-07-19 16:57   ` MN
  1 sibling, 0 replies; 5+ messages in thread
From: Mark Walters @ 2015-07-19  8:22 UTC (permalink / raw)
  To: David Bremner, mailinglists, notmuch


>> BTW, all I really want to do is modify the From: field based on the
>> recipients (for every email, with no default From). I'll welcome
>> suggestions for existing ways to do that. I Googled a little, but didn't
>> find a clear good solution. Furthermore, I expect over time the rules by
>> which I pick the From: field will get more complex than my knowledge of
>> Elisp.

I don't know how practical the following is but an alternative which
would keep you entirely outside lisp would be to configure
sendmail-program to be your python script and let it modify the message
and then send it on to whatever sendmail program you use.

Getting everything right with command line arguments and the message on
stdin (I guess) and keeping any sane form of error handling may be difficult 

Also, note that sendmail-program is not notmuch specific so if you
configure it might affect other emacs mail stuff like gnus.

Best wishes

Mark

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

* Re: Modify message after send...?
  2015-07-19  7:59 ` David Bremner
  2015-07-19  8:22   ` Mark Walters
@ 2015-07-19 16:57   ` MN
  1 sibling, 0 replies; 5+ messages in thread
From: MN @ 2015-07-19 16:57 UTC (permalink / raw)
  To: David Bremner; +Cc: notmuch

On 2015-07-19 00:59, David Bremner wrote:
> mailinglists@nawaz.org writes:
>
>> BTW, all I really want to do is modify the From: field based on the
>> recipients (for every email, with no default From). I'll welcome
>> suggestions for existing ways to do that. I Googled a little, but 
>> didn't
>> find a clear good solution. Furthermore, I expect over time the 
>> rules by
>> which I pick the From: field will get more complex than my knowledge 
>> of
>> Elisp.
>
> I'm afraid it's a bit "some-assembly-required", but let me mention 
> one
> possible solution.
>
> At least if you just want to have a regular expression match on the
> recipient, then the example configuration in message-templ [1] may be
> enough to get you started. You'd have to either call
> message-templ-config-exec in a hook, or bind it to a key and call it
> manually to set up the headers before sending.
>
> [1]: http://pivot.cs.unb.ca/git?p=message-templ.git;a=tree

Thanks for this. I'll see if I can follow the Elisp code.

After sending my email, it occurred to me that message handling is not 
notmuch's job - that's passed on to message-mode. I figured message-mode 
must have some kind of hook before sending the email, and sure enough, 
it does have message-send-hook. The example at 
www.gnu.org/software/emacs/manual/html_mono/message.html shows how one 
can add headers before sending. There's also message-alternative-emails, 
although that likely works only if you're replying to an email.

A little frustrating: They have a number of functions to modify/read 
fields like Subject, or To - but none for From! So I'll still have to do 
some surgery. I'll likely use the send-message-hook to:

1. Read the "To" & "cc" values.
2. Pass them to an external Python script.
3. Get the appropriate "From" field from the Python script.
4. Insert it into the From: field.

How does one do steps 2 & 3 in Elisp? I just need a pointer. (Just 
Googled and saw this: 
http://stackoverflow.com/questions/5014246/how-to-capture-standard-output-of-a-shell-command-in-elisp)

Thanks,

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

* Re: Modify message after send...?
  2015-07-19  4:59 Modify message after send...? mailinglists
  2015-07-19  7:59 ` David Bremner
@ 2015-07-22  0:21 ` David Mazieres
  1 sibling, 0 replies; 5+ messages in thread
From: David Mazieres @ 2015-07-22  0:21 UTC (permalink / raw)
  To: mailinglists, notmuch

mailinglists@nawaz.org writes:

> Hi,
>
> I use notmuch via Emacs.
>
> Here's what I want:
>
> When I hit C-c C-c to send a message, I'd like it to be passed to a
> script (likely a Python one, although I may consider an Elisp function
> if an external script is not possible) for modification of headers,
> before it is sent to the MTA (Postfix in my case). A bonus would be to
> have the modified message stored in the FCC location, instead of the
> original one.
>
> Is this possible? An alternative may be to modify the message /before/
> it goes to message-send-and-exit. I'm inexperienced in Elisp - would
> this be via what's called "advising"?
>
> BTW, all I really want to do is modify the From: field based on the
> recipients (for every email, with no default From). I'll welcome
> suggestions for existing ways to do that. I Googled a little, but didn't
> find a clear good solution. Furthermore, I expect over time the rules by
> which I pick the From: field will get more complex than my knowledge of
> Elisp.

For modifying the From field, I recommend doing it before you send the
message, as this gives you an opportunity to see what you are about to
send and possibly edit it by hand.

I do something like this using defadvice around notmuch-mua-mail, do
adjust things about my messages.  I also put a defadvice around
notmuch-call-notmuch-sexp to filter the To and Cc headers I get from
"notmuch reply" (because notmuch won't let me put wildcards in my
.notmuch-config file).

Finally, and possibly most relevant to you, I use a message-send-hook to
insert the Return-Path address and make a few more modifications before
sending a message.  Note that I only do this if there isn't already a
Return-Path header.  That way, if I type C-c C-c and don't like what I
see, I edit the result and send again, leaving the generated Return-Path
header, and this time it goes through unmodified.

David

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

end of thread, other threads:[~2015-07-22  0:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-19  4:59 Modify message after send...? mailinglists
2015-07-19  7:59 ` David Bremner
2015-07-19  8:22   ` Mark Walters
2015-07-19 16:57   ` MN
2015-07-22  0:21 ` David Mazieres

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

	https://yhetil.org/notmuch.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).