Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

make muttrc invoke script for changing my_hdr

12 views
Skip to first unread message

Mike Hunter

unread,
May 31, 2007, 5:59:19 PM5/31/07
to
Hey everybody,

I'm playing with a custom my_hdr. I had success doing

send-hook '(~t addr...@alice.com | ~t addr...@bob.com)' "my_hdr X-foo: <`/home/mhunter/bin/myfoo.pl`>"

And X-foo: <...> shows up with the correct results. But I realized that
it's only being run once per execution of mutt, which I need mutt to
invoke myfoo.pl every time it does the send-hook. Is that doable? It
must be but I can't figure it out off the top of my head. (The results
of myfoo.pl depend on the system time, etc.)

Thanks!

Mike

Gary Johnson

unread,
May 31, 2007, 8:47:30 PM5/31/07
to

All I can think of is something like this (untested),

send-hook '(~t addr...@alice.com | ~t addr...@bob.com)' 'source "/home/mhunter/bin/myfoo.pl|"'

where your myfoo.pl script would need to be modified to output the
entire

my_hdr X-foo: <your_foo_string_here>

command.

HTH,
Gary

Rado S

unread,
Jun 1, 2007, 12:51:07 PM6/1/07
to
Mike Hunter <mhu...@lusars.net> wrote:
> I'm playing with a custom my_hdr. I had success doing
>
> send-hook '(~t addr...@alice.com | ~t addr...@bob.com)' "my_hdr X-foo: <`/home/mhunter/bin/myfoo.pl`>"
>
> But I realized that it's only being run once per execution of
> mutt, which I need mutt to invoke myfoo.pl every time it does the
> send-hook.

Quote the `` to make them count only when the hooks is executed, not
when it is defined (read, parsed).

--
© Rado S. -- You must provide YOUR effort for your goal!
EVERY effort counts: at least to show your attitude.
You're responsible for ALL you do: you get what you give.

Mike Hunter

unread,
Jun 1, 2007, 3:51:02 PM6/1/07
to

Thanks to both you and Rado for the great suggestions, it's now working!

I've gotten a bit more ambitious and now I'd like to have myfoo.pl take
%T as an argument, but I'm running into trouble passing it to the
script. `` ends up with no such file or directory, and source ...
doesn't like what it sees as multiple arguments...any suggestions?

Thanks again,

Mike

Mike Hunter

unread,
Jun 6, 2007, 4:38:12 PM6/6/07
to

The only thing I've been able to think of is to call scripts with a
suffix, like ~/my-foo.%T.pl and have a separate script for each %T, but
I really don't want to have to maintain all that...if anybody has any
suggestions I'd greatly appreciate it :)

Mike

Gary Johnson

unread,
Jun 6, 2007, 9:43:51 PM6/6/07
to

I don't know how or when %T is expanded, so I haven't tested this
with %T, but 'source' should handle a command with arguments if you
surround the entire argument to 'source' with quotes, e.g.,

source "command arg |"

If any of the quoting prevents %T from being expanded, you might try
putting %T outside the quotes like this,

send-hook ... 'source "myfoo.pl "'%T'" |"'

or maybe this,

send-hook ... 'source "myfoo.pl "%T" |"'

or this,

send-hook ... 'source "myfoo.pl '%T' |"'

Which of those, if any, works will depend on when and how %T is
expanded, and as I said, I haven't played with that myself. I hope
that gives you some ideas, anyway.

Regards,
Gary

Mike Hunter

unread,
Jun 7, 2007, 5:55:37 PM6/7/07
to

Thanks very much for the suggestions. Unfortunately I tried them and
all the variations I could think of but nothing worked. I can either
get to "no such file or directory" or I can get to my script being
called with a literal "%T". I'm poking around the source code but it's
slow going so far.

Mike

Mike Hunter

unread,
Jun 13, 2007, 9:34:49 PM6/13/07
to
[snip]

I posted this to the mutt developers mailing list, but I thought I'd
also post it here in case it makes some neurons fire somewhere :)

Mike

------------------ ------------------ ------------------ ------------------
Hey everybody,

I'm floundering a bit in an attempt to add some functionality to the
"source" command and I'm hoping somebody can lend me a hand.

My end-goal is to be able to add some custom header lines based on who
the mail is addressed to. Unfortunately, this does NOT work:

send-hook '(~t al...@alice.com )' source "/Users/mhunter/bin/my_hdr-gen.pl %T |"

I get "source: too many arguments"

Clever quoting can get one a bit farther, but you end up with the
literal "%T" being passed to the script instead of the expanded value.

I've been trying to come up with a patch to enable this functionality,
but so far I'm not having success: In init.c, I tried allowing more
tokens in the case of "paths" ending with '|', but when thought I'd get
it to work, I discovered that the function that handles expanding %T
(FWICT) is a static function inside hdrline.c.

I must be going about this wrong, because obviously people use format
strings with "set", but I can't quite follow parse_set to see how it's
doing it.

I've been chatting about this already on usenet:

http://groups.google.com/group/comp.mail.mutt/browse_thread/thread/a5592b5a3e3472e7/3c0a4560597524f3#3c0a4560597524f3

And, for your ridicule, here's my non-working parse_source function that
I'm working on. It's trying to expand out the string and pass it along
to source_rc (which seems well-prepared to deal with it via eventually
fork/exec'ing).

Any help would be greatly appreciated!

Mike

static int parse_source (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
{
char path[_POSIX_PATH_MAX];
char formatbuf[SHORT_STRING];

/*we do a first pass with with path expansion for the root */
if (mutt_extract_token (tmp, s, 0) != 0)
{
snprintf (err->data, err->dsize, _("source: error at %s"), s->dptr);
return (-1);
}
strfcpy (path, tmp->data, sizeof (path));
mutt_expand_path (path, sizeof (path));

while (MoreArgs(s))
{
if (mutt_extract_token (tmp, s, 0) != 0)
{
snprintf (err->data, err->dsize, _("source: error at %s"), s->dptr);
return (-1);
}
if (tmp->data[0] == '%')
{
mutt_FormatString(formatbuf, sizeof(formatbuf), tmp->data, hdr_format_str, data, 0);
safe_strncat(path, sizeof(path), " ", 1);
safe_strncat(path, sizeof(path), formatbuff, sizeof(formatbuf));
}
else
{
safe_strncat(path, sizeof(path), " ", 1);
safe_strncat(path, sizeof(path), tmp->data, tmp->dsize);
}
}

if (path[mutt_strnlen(path, sizeof(path))-2] != '|')
{
snprintf (err->data, err->dsize,
_("source: multiple arguments not ending in '|'"), s->dptr);
return (-1);
}

return (source_rc (path, err));
}


--
"As soon as we started programming, we found to our surprise that it wasn't as
easy to get programs right as we had thought....I can remember the exact
instant when I realized that a large part of my life from then on was going to
be spent in finding mistakes in my own programs." --Maurice Wilkes, 1949

0 new messages