make muttrc invoke script for changing my_hdr

This is a discussion on make muttrc invoke script for changing my_hdr within the Mutt forums in Other Technologies category; Hey everybody, I'm playing with a custom my_hdr. I had success doing send-hook '(~t address1@alice.com | ~t address2@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...

Go Back   Application Development Forum > Other Technologies > Mutt

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 05-31-2007, 05:59 PM
Mike Hunter
Guest
 
Default make muttrc invoke script for changing my_hdr

Hey everybody,

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

send-hook '(~t address1@alice.com | ~t address2@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
Reply With Quote
  #2  
Old 05-31-2007, 08:47 PM
Gary Johnson
Guest
 
Default Re: make muttrc invoke script for changing my_hdr

Mike Hunter <mhunter@lusars.net> wrote:
> Hey everybody,
>
> I'm playing with a custom my_hdr. I had success doing
>
> send-hook '(~t address1@alice.com | ~t address2@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.)


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

send-hook '(~t address1@alice.com | ~t address2@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
Reply With Quote
  #3  
Old 06-01-2007, 12:51 PM
Rado S
Guest
 
Default Re: make muttrc invoke script for changing my_hdr

Mike Hunter <mhunter@lusars.net> wrote:
> I'm playing with a custom my_hdr. I had success doing
>
> send-hook '(~t address1@alice.com | ~t address2@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.
Reply With Quote
  #4  
Old 06-01-2007, 03:51 PM
Mike Hunter
Guest
 
Default Re: make muttrc invoke script for changing my_hdr

On Fri, 1 Jun 2007 00:47:30 +0000 (UTC), Gary Johnson wrote:
> Mike Hunter <mhunter@lusars.net> wrote:
> > Hey everybody,
> >
> > I'm playing with a custom my_hdr. I had success doing
> >
> > send-hook '(~t address1@alice.com | ~t address2@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.)

>
> All I can think of is something like this (untested),
>
> send-hook '(~t address1@alice.com | ~t address2@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.


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
Reply With Quote
  #5  
Old 06-06-2007, 04:38 PM
Mike Hunter
Guest
 
Default Re: make muttrc invoke script for changing my_hdr

On Fri, 01 Jun 2007 15:51:02 -0400, Mike Hunter wrote:
> On Fri, 1 Jun 2007 00:47:30 +0000 (UTC), Gary Johnson wrote:


> > All I can think of is something like this (untested),
> >
> > send-hook '(~t address1@alice.com | ~t address2@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.

>
> 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?


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
Reply With Quote
  #6  
Old 06-06-2007, 09:43 PM
Gary Johnson
Guest
 
Default Re: make muttrc invoke script for changing my_hdr

Mike Hunter <mhunter@lusars.net> wrote:
> On Fri, 01 Jun 2007 15:51:02 -0400, Mike Hunter wrote:
>> On Fri, 1 Jun 2007 00:47:30 +0000 (UTC), Gary Johnson wrote:

>
>> > All I can think of is something like this (untested),
>> >
>> > send-hook '(~t address1@alice.com | ~t address2@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.

>>
>> 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?

>
> 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


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
Reply With Quote
  #7  
Old 06-07-2007, 05:55 PM
Mike Hunter
Guest
 
Default Re: make muttrc invoke script for changing my_hdr

On Thu, 7 Jun 2007 01:43:51 +0000 (UTC), Gary Johnson wrote:
> Mike Hunter <mhunter@lusars.net> wrote:
> > On Fri, 01 Jun 2007 15:51:02 -0400, Mike Hunter wrote:
> >>
> >> 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?

> >
> > 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

>
> 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.


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
Reply With Quote
  #8  
Old 06-13-2007, 09:34 PM
Mike Hunter
Guest
 
Default Re: make muttrc invoke script for changing my_hdr

[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 alice@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....0a4560597524f3

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

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 06:06 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.