Discussion:
Piping to a script and receiving commands/variables back
David Woodfall
2018-03-12 23:32:24 UTC
Permalink
Hello,

I've made a shell script that I pipe via a key bind. It parses for
email address and writes a new procmail rule based on that and the
name of a folder that I enter on the CLI.

It works OK, but I'd like to send the name of the folder back to mutt
and have it save the message there afterwards.

I've kind of got it working by echoing commands to a tmp file and then
have mutt source it:

echo "push <save-message>=$folder<return><sync-mailbox>" \
/tmp/newfolder
I'd much rather know if there's a better way of doing it.

Thanks
Cameron Simpson
2018-03-13 00:02:45 UTC
Permalink
Post by David Woodfall
I've made a shell script that I pipe via a key bind. It parses for
email address and writes a new procmail rule based on that and the
name of a folder that I enter on the CLI.
It works OK, but I'd like to send the name of the folder back to mutt
and have it save the message there afterwards.
I've kind of got it working by echoing commands to a tmp file and then
echo "push <save-message>=$folder<return><sync-mailbox>" \
/tmp/newfolder
I'd much rather know if there's a better way of doing it.
The other alternative is to source its output directly. So the raw command is:

`your-shell-script`

But you want the script to parse a mail message and emit mutt commands for
sourcing. Possibly you need to (a) save the message to a file (b) run:

`your-shell-script <the-file`

I'm not sure that is morally any better than your current approach (pipe to
script, source a file).

My own macro like yours goes:

folder-hook . 'macro index,pager A "<save-message>+spool-refile<enter><pipe-message>cs-aliases-add-email -quick known<enter>"'

which loads the author into a "known authors" list, which is sort of
whitelisted by my filtering.

Maybe the simplest approach is for your script to write the new procmail rule
and _also_ append something to a growing muttrc file. Which you then source at
the end of the macro?

Cheers,
Cameron Simpson <***@cskk.id.au> (formerly ***@zip.com.au)

Loading...