contrib to select mail server based on From: in draft

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

contrib to select mail server based on From: in draft

David Levine-3
I added a program, docs/contrib/sendfrom.c, that selects the SMTP server based on the draft's From: address.

The source code can be viewed at

    http://git.savannah.gnu.org/cgit/nmh.git/tree/docs/contrib/sendfrom.c

An excerpt from the usage notes is below.

It can take full advantage of nmh's OAuth support, but that support is currently only available on the xoauth branch.

It'd be nice if send read the draft and added the switches for post.  It'd be easy to merge that code from sendfrom into send, and I'd be glad to do it if there's interest.

David


 * This program fits between send(1) and post(1), as a postproc.  It makes up for the facts that send doesn't parse the message draft and post doesn't load the profile.
 *
 * To use:
 *
 * 1) Add profile entries of the form:
 *
 *        sendfrom-<email address or domain name>:  <post(1) switches>
 *
 *    The email address is extracted from the From: header line of the message draft.  Multiple profile entries, with different email addresses or domain names, are supported.  This allows different switches to post(1), such as -user, to be associated with different email addresses.  If a domain name is used, it matches all users in that domain.
 *
 *    Example profile entry using OAuth for account hosted by gmail:
 *
 *       [hidden email]: -saslmech xoauth2 -authservice gmail -tls -server smtp.gmail.com -user [hidden email]
 *
 *    Example profile entries that use an nmh credentials file:
 *
 *       credentials: file:nmhcreds
 *       [hidden email]: -sasl -tls -server smtp.sendgrid.net
 *       sendfrom-outbound.att.net: -sasl -initialtls -server outbound.att.net -port 465
 *       sendfrom-fastmail.com: -initialtls -sasl -saslmech LOGIN -server smtps-proxy.messagingengine.com -port 80
 *
 *    where nmhcreds is in the user's nmh directory (from the Path profile component) and contains:
 *
 *       machine smtp.sendgrid.net
 *           login [hidden email]
 *           password ********
 *       machine outbound.att.net
 *           login [hidden email]
 *           password ********
 *       machine smtps-proxy.messagingengine.com
 *           login [hidden email]
 *           password ********
 *
 * 2) To enable, add a line like this to your profile:
 *
 *        postproc: <docdir>/contrib/sendfrom
 *
 *    with <docdir> expanded.

_______________________________________________
Nmh-workers mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/nmh-workers
Reply | Threaded
Open this post in threaded view
|

Re: contrib to select mail server based on From: in draft

Conrad Hughes
David> I added a program, docs/contrib/sendfrom.c, that selects the SMTP
David> server based on the draft's From: address.

There have been times I'd've found this incredibly useful, though not so
much right at the moment unfortunately.  +1!

Do you have anything set up to automatically alter From addresses when
replying?  I've a hacked-up editor script that alters them according to
various things, such as the originator or recipient address.  Maybe
there's a more nmh-y way to do that nowadays though..?

C.

_______________________________________________
Nmh-workers mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/nmh-workers
Reply | Threaded
Open this post in threaded view
|

Re: contrib to select mail server based on From: in draft

Ken Hornstein-2
In reply to this post by David Levine-3
>I added a program, docs/contrib/sendfrom.c, that selects the SMTP
>server based on the draft's From: address.
>
>The source code can be viewed at
>
>    http://git.savannah.gnu.org/cgit/nmh.git/tree/docs/contrib/sendfrom.c

I think this is great.  My only quibble is perhaps that the implementation
is a bit inelegant but on further reflection it's probably the best
that can be done given the current API.  I say it should go into the
tree as part of send(1).

--Ken

_______________________________________________
Nmh-workers mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/nmh-workers
Reply | Threaded
Open this post in threaded view
|

Re: contrib to select mail server based on From: in draft

Ken Hornstein-2
In reply to this post by Conrad Hughes
>Do you have anything set up to automatically alter From addresses when
>replying?  I've a hacked-up editor script that alters them according to
>various things, such as the originator or recipient address.  Maybe
>there's a more nmh-y way to do that nowadays though..?

We've discussed this on the mailing list in the past, although I guess
we never sat down and spelled out the steps.  But yes, I do this.

The magic is all in replcomps; basically, that needs to be modified so
the "right" header is chosen based on some criteria in the original message.
Here's part of what I use, to give you an idea:

%<{delivered-to}%<(match [hidden email])\
From: Ken Hornstein <[hidden email]>
%|\
From: Ken Hornstein <[hidden email]>
%>\

That means, "If the Delivered-To header matches "[hidden email]", put
a From header of [hidden email], otherwise use my work address.  This
assumes you have some mechanism to decide on the From header based on
the message headers, and that the mh-profile language is powerful enough
to make use of it.

--Ken

_______________________________________________
Nmh-workers mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/nmh-workers
Reply | Threaded
Open this post in threaded view
|

Re: contrib to select mail server based on From: in draft

bergman-5
In the message dated: Tue, 31 May 2016 13:11:33 -0400,
The pithy ruminations from Ken Hornstein on
<Re: [Nmh-workers] contrib to select mail server based on From: in draft> were:
=> >Do you have anything set up to automatically alter From addresses when
=> >replying?  I've a hacked-up editor script that alters them according to
=> >various things, such as the originator or recipient address.  Maybe
=> >there's a more nmh-y way to do that nowadays though..?
=>
=> We've discussed this on the mailing list in the past, although I guess
=> we never sat down and spelled out the steps.  But yes, I do this.

I do this as well, since ~2007.

=>
=> The magic is all in replcomps; basically, that needs to be modified so

Same here, plus a customized "repl" wrapper script that sets the Fcc:,
Reply-To:, and signature based on the "From" address.

I'd be glad to share my perl wrapper script again, but I'm sure that there are
more integrated, cleaner solutions, such as replyfilter.

Mark

=> the "right" header is chosen based on some criteria in the original message.
=> Here's part of what I use, to give you an idea:
=>
=> %<{delivered-to}%<(match [hidden email])\
=> From: Ken Hornstein <[hidden email]>
=> %|\
=> From: Ken Hornstein <[hidden email]>
=> %>\
=>
=> That means, "If the Delivered-To header matches "[hidden email]", put
=> a From header of [hidden email], otherwise use my work address.  This
=> assumes you have some mechanism to decide on the From header based on
=> the message headers, and that the mh-profile language is powerful enough
=> to make use of it.
=>
=> --Ken
=>
=> _______________________________________________
=> Nmh-workers mailing list
=> [hidden email]
=> https://lists.nongnu.org/mailman/listinfo/nmh-workers
=>
--
Mark Bergman    Biker, Rock Climber, SCUBA Diver, Unix mechanic, IATSE #1 Stagehand
'94 Yamaha GTS1000A^2
[hidden email] https://www.flickr.com/photos/rmsppu

http://wwwkeys.pgp.net:11371/pks/lookup?op=get&search=bergman%40panix.com

I want a newsgroup with a infinite S/N ratio! Now taking CFV on:
rec.motorcycles.stagehands.pet-bird-owners.pinballers.unix-supporters
15+ So Far--Want to join? Check out: http://www.panix.com/~bergman 

_______________________________________________
Nmh-workers mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/nmh-workers
Reply | Threaded
Open this post in threaded view
|

Re: contrib to select mail server based on From: in draft

Ken Hornstein-2
>I'd be glad to share my perl wrapper script again, but I'm sure that there are
>more integrated, cleaner solutions, such as replyfilter.

For various dumb reasons, replyfilter really only has access to (and can only
provide) the message body.  If you want to modify the message headers, your
only choice is replcomps (well, that's the native solution; since we are
talking about text files, you can do whatever you want).

--Ken

_______________________________________________
Nmh-workers mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/nmh-workers
Reply | Threaded
Open this post in threaded view
|

Re: contrib to select mail server based on From: in draft

David Levine-3
In reply to this post by Conrad Hughes
Conrad wrote:

> Do you have anything set up to automatically alter From addresses when
> replying?

Here's the relevant part of my replcomps:

%<(nonnull(getmyaddr{to}))From: %(myname) <%(getmyaddr{to})>\
%?(nonnull(getmyaddr{cc}))From: %(myname) <%(getmyaddr{cc})>%>

If one of my addresses isn't in the To: or Cc:, it puts a blank line in the draft.
I fill that in manually (using an editor macro).

This comes in handy for show what that will do:

$ fmttest -format "$(grep From: $(mhpath +)/replcomps)" -message +inbox last

David

_______________________________________________
Nmh-workers mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/nmh-workers
Reply | Threaded
Open this post in threaded view
|

Re: contrib to select mail server based on From: in draft

David Levine-3
In reply to this post by Ken Hornstein-2
Ken wrote:

> My only quibble is perhaps that the implementation
> is a bit inelegant but on further reflection it's probably the best
> that can be done given the current API.

If you're referring to the special handling for whom, that doesn't need to migrate to send.  A lot of the other code doesn't, either.

I'm so not a fan of m_getfld, but it gets the job done.

David

_______________________________________________
Nmh-workers mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/nmh-workers
Reply | Threaded
Open this post in threaded view
|

Re: contrib to select mail server based on From: in draft

David Levine-3
In reply to this post by Ken Hornstein-2
Ken wrote:

> >[David:]
> >I added a program, docs/contrib/sendfrom.c, that selects the SMTP
> >server based on the draft's From: address.
> >
> >The source code can be viewed at
> >
> >    http://git.savannah.gnu.org/cgit/nmh.git/tree/docs/contrib/sendfrom.c
>
> I think this is great.  My only quibble is perhaps that the implementation
> is a bit inelegant but on further reflection it's probably the best
> that can be done given the current API.  I say it should go into the
> tree as part of send(1).

Done.  It's on both master and the xoauth branch.  docs/contrib/sendfrom.c
has been removed.

David

_______________________________________________
Nmh-workers mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/nmh-workers