<<< Date Index >>>     <<< Thread Index >>>

help with trying to add format string parsing to "source" directive



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@xxxxxxxxx )' 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