[nmh-workers] 'dist' in "at" job or "1 line script"? [end-user ?]

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

[nmh-workers] 'dist' in "at" job or "1 line script"? [end-user ?]

nmh
Want to use dist in cron or 'at' to
programatically resend a msg in my sent folder (in below example msg 2022).
I do not want this script to be interactive.

Consider

    dist -from [hidden email] -to [hidden email] -cc [hidden email] -fcc +resent +sent 2022

Problems:

    When $EDITOR runs, the
        -from [hidden email] -to [hidden email] -cc [hidden email] -fcc +resent
    switches have not changed these headers:

        Resent-To:
        Resent-From:
        Resent-cc:
        Resent-Fcc: sent

    I'm not understanding what the dist switches: -from, -to, -cc, and -fcc are used for.

    ( I do not want to have to start $EDITOR interactively. )

    How might I automate the "whatnowproc" / send step?

My goal is a to make a wrapper script that calls 'dist' so I can automate the
resending of a msg along with the proper "Resent-*" headers non interactively.
I would then use 'at' to schedule a couple of 'resends'.

--
thanks!,
Tom
Milwaukee WI, USA

--
nmh-workers
https://lists.nongnu.org/mailman/listinfo/nmh-workers
nmh
Reply | Threaded
Open this post in threaded view
|

Re: 'dist' in "1 line noninteractive script"

nmh
On Fri 7/19/19 7:45 -0500 [hidden email] wrote:
>Want to use dist in cron or 'at' to
>programatically resend a msg in my sent folder (in below example msg 2022).
>I do not want this script to be interactive.
>
>Consider
dist -from [hidden email] -to [hidden email] -cc [hidden email] -fcc resent +sent 2022

>    I'm not understanding what the dist switches: -from, -to, -cc, and -fcc are used for.

After looking again at the 'dist' man page I have:

    $ head -5 ~/Mail/distcomps
    Resent-To: %<{nmh-to}%{nmh-to}%>
    Resent-From: %<{nmh-from}%{nmh-from}%>
    Resent-cc: %<{nmh-cc}%{nmh-cc}%>
    Resent-Fcc: %<{fcc}%{fcc}%>
    Resent-Comments:

Pls check above.

Now w/above distcomps, the -from, -to, -cc, and -fcc switches work.

Consider

    echo send| dist -noedit -from [hidden email] -to [hidden email] -cc [hidden email] -fcc resent +sent 2022

Is there a prefered way to the above approach for automating the send?

>My goal is a to make a wrapper script that calls 'dist' so I can automate the
>resending of a msg along with the proper "Resent-*" headers non interactively.
>I would then use 'at' to schedule a couple of 'resends'.

--
thanks,
Tom

--
nmh-workers
https://lists.nongnu.org/mailman/listinfo/nmh-workers
Reply | Threaded
Open this post in threaded view
|

Re: 'dist' in "1 line noninteractive script"

Ralph Corderoy
Hi Tom,

> After looking again at the 'dist' man page I have:
>
>     $ head -5 ~/Mail/distcomps
>     Resent-To: %<{nmh-to}%{nmh-to}%>
>     Resent-From: %<{nmh-from}%{nmh-from}%>
>     Resent-cc: %<{nmh-cc}%{nmh-cc}%>
>     Resent-Fcc: %<{fcc}%{fcc}%>
>     Resent-Comments:
>
> Pls check above.

http://git.savannah.nongnu.org/cgit/nmh.git/tree/etc/distcomps is the
stock one for comparison.

>     echo send |
>     dist -noedit \
>         -from [hidden email] -to [hidden email] -cc [hidden email] -fcc resent \
>         +sent 2022
>
> Is there a prefered way to the above approach for automating the send?

Another way is

    echo y | dist -whatnowproc send -to foo

The icky ‘y’ is needed to answer send(1)'s ‘Use ".../42"?’ message
stating the draft prepared by dist(1) and communicated with the mhdraft
environment variable.  send doesn't ask if its -draft is given, but
-whatnowproc doesn't accept ‘send -draft’ as it tries to exec a program
called that single word.

None of this fits together too well.

--
Cheers, Ralph.

--
nmh-workers
https://lists.nongnu.org/mailman/listinfo/nmh-workers
Reply | Threaded
Open this post in threaded view
|

Re: 'dist' in "1 line noninteractive script"

David Levine-3
Ralph writes:

> Hi Tom,

> http://git.savannah.nongnu.org/cgit/nmh.git/tree/etc/distcomps is the
> stock one for comparison.

Just to note that it works for me.

>
> >     echo send |
> >     dist -noedit \
> >         -from [hidden email] -to [hidden email] -cc [hidden email] -fcc resent \
> >         +sent 2022
> >
> > Is there a prefered way to the above approach for automating the send?
>
> Another way is
>
>     echo y | dist -whatnowproc send -to foo

Or, per the description of mhdraft in mh-profile(1):

    $ cat `mhparam path`/auto_send
    [ "$mhdraft" ] && send "$mhdraft"

    $ dist [...] -whatnowproc `mhparam path`/auto_send

With the -whatnowproc switch, the -noedit isn't necessary.

David

--
nmh-workers
https://lists.nongnu.org/mailman/listinfo/nmh-workers
nmh
Reply | Threaded
Open this post in threaded view
|

Re: 'dist' in "1 line noninteractive script"

nmh
In reply to this post by Ralph Corderoy
Hi Ralph:

On Sun 7/21/19 12:56 +0100 Ralph Corderoy wrote:
[...]
>http://git.savannah.nongnu.org/cgit/nmh.git/tree/etc/distcomps is the
>stock one for comparison.

Thanks Ralph, I have updated my personal distcomps per above.

>>     echo send |
>>     dist -noedit \
>>         -from [hidden email] -to [hidden email] -cc [hidden email] -fcc resent \
>>         +sent 2022
>>
>> Is there a prefered way to the above approach for automating the send?
>
>Another way is
>
>    echo y | dist -whatnowproc send -to foo
>
>The icky ‘y’ is needed to answer send(1)'s ‘Use ".../42"?’ message
>stating the draft prepared by dist(1) and communicated with the mhdraft
>environment variable.  send doesn't ask if its -draft is given, but
>-whatnowproc doesn't accept ‘send -draft’ as it tries to exec a program
>called that single word.

OK the whatnowproc must be a single word - good to know.
Thanks for the help.

David's follow up suggests that send uses a few
env variables to detect that 'dist' is calling it.

--
regards,
Tom

--
nmh-workers
https://lists.nongnu.org/mailman/listinfo/nmh-workers
nmh
Reply | Threaded
Open this post in threaded view
|

Re: 'dist' in "1 line noninteractive script"

nmh
In reply to this post by David Levine-3
Hi David:

On Mon 7/22/19 19:29 -0400 David Levine wrote:
[...]
>per the description of mhdraft in mh-profile(1):
>
>    $ cat `mhparam path`/auto_send
>    [ "$mhdraft" ] && send "$mhdraft"
>
>    $ dist [...] -whatnowproc `mhparam path`/auto_send
>
>With the -whatnowproc switch, the -noedit isn't necessary.

Thanks David.  I tried your auto_send 1 line script and it worked
with dist as you said.

Your tip and a dump of env  seen by .../auto_send
suggested this approach to mimic dist:

    mhannotate=Resent mhmessages=2022 mhatfile=1 mhfolder=~/Mail/sent mhuse=0 mhaltmsg=~/Mail/sent/2022  mhdraft=~/Mail/drafts/1007 mhinplace=1 mhdist=1 send  -verbose ~/Mail/drafts/1007

---
Changing topic a bit to "'dist' with msg as pathname ( not ending in an integer )"

Although above 'send' worked, it
would be nice to specify ~/Mail/sent/2022 as say ~/Mail/sent/bar, and
~/Mail/drafts/1007 as ~/Mail/drafts/foo so they won't be accidently renumbered
or deleted before my 'at' job, that may run the send perhaps a week later.  I would
probably hard link ~/Mail/sent/2022 to ~/Mail/sent/bar. ( I do not mind
manually making ~/Mail/drafts/foo. )

--- back to main topic
So, I think you and Ralph have answered my question - thanks!

--
thanks,
Tom

--
Below experiment, works except that ~/Mail/sent/bar is not annotated (for example - no
'Prev-Resent' headers):

   mhannotate=Resent    mhaltmsg=~/Mail/sent/bar    mhdist=1 send ~/Mail/drafts/foo

--
nmh-workers
https://lists.nongnu.org/mailman/listinfo/nmh-workers
Reply | Threaded
Open this post in threaded view
|

Re: 'dist' in "1 line noninteractive script"

Ken Hornstein-2
>   mhannotate=Resent mhaltmsg=~/Mail/sent/bar mhdist=1 send ~/Mail/drafts/foo

It wouldn't surprise me that the problem is that ~ in mhaltmsg.  Is that
actually being expanded?  If you run send with -debug, do you maybe
see a message saying "$mhaltmsg mismatch"?

How annotations work is a bit magical.  send sees that the 'mhannotate'
variable is set, opens a file descriptor and passes that descriptor down
to post(8) using the -idanno flag.  Post then writes the address information
to the anno descriptor (which is a tmp file which has been unlinked)
and then send(1) reads that file and uses it to construct the annotation.
But there's a check in sendsbr.c:anno() to make sure the stat() information
of the filename in mhaltmsg matches what is being passed in as the
original filename; that will fail silently without -debug if there
is a mismatch.

--Ken

--
nmh-workers
https://lists.nongnu.org/mailman/listinfo/nmh-workers
Reply | Threaded
Open this post in threaded view
|

Re: 'dist' in "1 line noninteractive script"

David Levine-3
In reply to this post by nmh
Tom writes:

> Changing topic a bit to "'dist' with msg as pathname ( not ending in an integer )"
>
> Although above 'send' worked, it
> would be nice to specify ~/Mail/sent/2022 as say ~/Mail/sent/bar,

send(1) doesn't care what the message file is named.  After successfully sending the message, it will rename the file to, in the case of your example above, ~/Mail/sent/,bar (with the default comma backup prefix).

dist(1) supports a -file switch, but it isn't documented.  We should consider fixing that.

David

--
nmh-workers
https://lists.nongnu.org/mailman/listinfo/nmh-workers
nmh
Reply | Threaded
Open this post in threaded view
|

Re: 'dist' in "1 line noninteractive script"

nmh
In reply to this post by Ken Hornstein-2
Hi Ken:

On Tue 7/23/19 21:44 -0400 Ken Hornstein wrote:
>>   mhannotate=Resent mhaltmsg=~/Mail/sent/bar mhdist=1 send ~/Mail/drafts/foo
>
>It wouldn't surprise me that the problem is that ~ in mhaltmsg.  Is that
>actually being expanded?  If you run send with -debug, do you maybe
>see a message saying "$mhaltmsg mismatch"?

$ ( set -x ; x=~ true )
+ x=/a/rodmant
+ true

So bash expands ~ before send sees it.

>How annotations work is a bit magical.  send sees that the 'mhannotate'
>variable is set, opens a file descriptor and passes that descriptor down
>to post(8) using the -idanno flag.  Post then writes the address information
>to the anno descriptor (which is a tmp file which has been unlinked)
>and then send(1) reads that file and uses it to construct the annotation.
>But there's a check in sendsbr.c:anno() to make sure the stat() information
>of the filename in mhaltmsg matches what is being passed in as the
>original filename; that will fail silently without -debug if there
>is a mismatch.

Interesting/thanks.

I can live without the -annotate working -- it works fine, but not with
David's undocumented -file MSG_PATH.

--
Tom

--
nmh-workers
https://lists.nongnu.org/mailman/listinfo/nmh-workers
Reply | Threaded
Open this post in threaded view
|

Re: 'dist' in "1 line noninteractive script"

Valdis Klētnieks
On Thu, 25 Jul 2019 11:09:38 -0500, [hidden email] said:

> On Tue 7/23/19 21:44 -0400 Ken Hornstein wrote:
> >>   mhannotate=Resent mhaltmsg=~/Mail/sent/bar mhdist=1 send ~/Mail/drafts/foo
> >
> >It wouldn't surprise me that the problem is that ~ in mhaltmsg.  Is that
> >actually being expanded?  If you run send with -debug, do you maybe
> >see a message saying "$mhaltmsg mismatch"?
>
> $ ( set -x ; x=~ true )
> + x=/a/rodmant
> + true
>
> So bash expands ~ before send sees it.
But that may not be true for something that invokes execve() rather than
system(), or a cronjob (which is what started this discussion).


--
nmh-workers
https://lists.nongnu.org/mailman/listinfo/nmh-workers

attachment0 (849 bytes) Download Attachment
nmh
Reply | Threaded
Open this post in threaded view
|

Re: 'dist' in "1 line noninteractive script"

nmh
In reply to this post by David Levine-3
Hi David:

On Tue 7/23/19 22:32 -0400 David Levine wrote:
>> Although above 'send' worked, it
>> would be nice to specify ~/Mail/sent/2022 as say ~/Mail/sent/bar,
>
>send(1) doesn't care what the message file is named.  After successfully
>sending the message, it will rename the file to, in the case of your example
>above, ~/Mail/sent/,bar (with the default comma backup prefix).

ok/thx

>dist(1) supports a -file switch, but it isn't documented.  We should consider fixing that.

Great / I'm using "-file" now.  

My 1 liner is back to to something like:

    dist -whatnowproc ~/Mail/auto_send  -from 'nym moob <[hidden email]>' -to '"nym moob" <[hidden email]>' -fcc resent -cc myaliasfoo -file ~/Mail/sent/bar
        # Adding -annotate does nothing, but I think that is by design / I am ok with that.  

Where:

    $ cat ~/Mail/auto_send
    #!/bin/bash
    if [ $mhdraft ] ; then
        # echo mhdraft: $mhdraft mhaltmsg: $mhaltmsg
        # cp "$mhdraft" /tmp/foo
        # env
        set -x
        send -verbose "$mhdraft"
    else
        echo $0: OOPS: mhdraft not set >&2
        exit 1
    fi

    $ head -8 /a/rodmant/Mail/distcomps
    %; http://git.savannah.nongnu.org/cgit/nmh.git/tree/etc/distcomps
    %;
    %<{nmh-from}%|%(void(localmbox))%>%(void(width))%(putaddr Resent-From: )
    %<{nmh-to}%(void(width))%(putaddr Resent-To: )%|Resent-To:%>
    %<{nmh-cc}%(void(width))%(putaddr Resent-cc: )%|Resent-cc:%>
    %<{fcc}%(void(width))%(putaddr Resent-fcc: )%|Resent-fcc:%>
    Resent-Comments:
    Resent-Comments:

--
Tom

--
nmh-workers
https://lists.nongnu.org/mailman/listinfo/nmh-workers
Reply | Threaded
Open this post in threaded view
|

Re: 'dist' in "1 line noninteractive script"

Ken Hornstein-2
In reply to this post by nmh
>Interesting/thanks.
>
>I can live without the -annotate working -- it works fine, but not with
>David's undocumented -file MSG_PATH.

Oh, huh, that's explicit:

    if (file) {
        /*
         * Dist a file
         */
        anot = false;   /* don't want to annotate a file */

I am neutral if that is a good idea or not.

In theory, though, you should be able to annotate anything when you
call send directly as long as the variables are set correctly.

Okay, I double-checked, and it turns out that's a lie.  For that all
to work you need to set mhfolder and mhmessages.

Huh, I wonder why?  It looks like mhmessages can actually be a LIST of
messages.  I guess you can use "forw" to generate more than one message
to be annotated.  So yeah, the annotations setup currently really is set
up to only work when they are normal messages in MH folders.  Sigh.
That's my "new nmh thing I just learned" for today, I guess.

--Ken

--
nmh-workers
https://lists.nongnu.org/mailman/listinfo/nmh-workers