Am Fri, Mar 04, 2022 at 06:16:28PM -0800 schrieb Kevin J. McCarthy:
> A slightly more intrusive patch using strchr() might be better (untested,
> just below).  This also removes '\n' from the delim list, since that's a
> remnant from when fgets() was used.

Thanks, that works better!

> except the query feature is very old

FYI I am only using it because mutt's current alias implementation does
not have all the features I need. I am using query as a drop-in
replacement for local alias support, and use e.g. the <more info> field
to provide the Subject of the last mail that I wrote to that "alias"
(which I generate a cache for with a weekly timer).
I know this is not the way that the query feature was intended, but
mutt's alias implementation is not powerful enough unfortunately as it
does not have support for <more info> and it only searches for matches
in the alias nickname.

> diff --git a/query.c b/query.c
> index 5a5c07b0..d0617c23 100644
> --- a/query.c
> +++ b/query.c
> @@ -106,7 +106,7 @@ static QUERY *run_query (char *s, int quiet)
>    int dummy = 0;
>    char *msg = NULL;
>    size_t msglen;
> -  char *p;
> +  char *tok, *nexttok;
>    pid_t thepid;
>    cmd = mutt_buffer_pool_get ();
> @@ -128,27 +128,35 @@ static QUERY *run_query (char *s, int quiet)
>    msg = mutt_read_line (msg, &msglen, fp, &dummy, 0);
>    while ((buf = mutt_read_line (buf, &buflen, fp, &dummy, 0)) != NULL)
>    {
> -    if ((p = strtok(buf, "\t\n")))
> +    tok = buf;
> +    if ((nexttok = strchr (tok, '\t')))
> +      *nexttok++ = 0;
> +
> +    if (first == NULL)
>      {
> -      if (first == NULL)
> -      {
> -     first = (QUERY *) safe_calloc (1, sizeof (QUERY));
> -     cur = first;
> -      }
> -      else
> -      {
> -     cur->next = (QUERY *) safe_calloc (1, sizeof (QUERY));
> -     cur = cur->next;
> -      }
> +      first = (QUERY *) safe_calloc (1, sizeof (QUERY));
> +      cur = first;
> +    }
> +    else
> +    {
> +      cur->next = (QUERY *) safe_calloc (1, sizeof (QUERY));
> +      cur = cur->next;
> +    }
> +
> +    cur->addr = rfc822_parse_adrlist (cur->addr, tok);
> +    if (nexttok)
> +    {
> +      tok = nexttok;
> +      if ((nexttok = strchr (tok, '\t')))
> +        *nexttok++ = 0;
> +      cur->name = safe_strdup (tok);
> -      cur->addr = rfc822_parse_adrlist (cur->addr, p);
> -      p = strtok(NULL, "\t\n");
> -      if (p)
> +      if (nexttok)
>        {
> -     cur->name = safe_strdup (p);
> -     p = strtok(NULL, "\t\n");
> -     if (p)
> -       cur->other = safe_strdup (p);
> +        tok = nexttok;
> +        if ((nexttok = strchr (tok, '\t')))
> +          *nexttok++ = 0;
> +        cur->other = safe_strdup (tok);
>        }
>      }
>    }
> 
> 
> -- 
> Kevin J. McCarthy
> GPG Fingerprint: 8975 A9B3 3AA3 7910 385C  5308 ADEF 7684 8031 6BDA

Tested-by: Magnus Groß <magnus.gr...@rwth-aachen.de>

Reply via email to