Hi Robert,

On 2026-07-01T15:46:03+0200, Robert Jäschke via Mutt-dev wrote:
> Hello,
> 
> with respect to my post "get id of key used for s/mime signature" on the
> mutt-users list, I have written a brief patch to show the key id. To
> reduce code duplication, I added a function mutt_align to curs_lib.c,
> but I am not sure whether that's the best place to go. I hope my aged C
> skills have not introduced too many errors, so feedback is very welcome.
> 
> Best regards,
> Robert
> 
> 
> -- >8 --
> ---
>  crypt-gpgme.c | 21 +++++++--------------
>  curs_lib.c    | 12 ++++++++++++
>  protos.h      |  1 +
>  3 files changed, 20 insertions(+), 14 deletions(-)
> 
> diff --git a/crypt-gpgme.c b/crypt-gpgme.c
> index ccae5503..e42be23d 100644
> --- a/crypt-gpgme.c
> +++ b/crypt-gpgme.c
> @@ -1619,9 +1619,8 @@ static void show_one_sig_validity(gpgme_ctx_t ctx, int 
> idx, STATE *s)
>  static void print_smime_keyinfo(const char *msg, gpgme_signature_t sig,
>                                  gpgme_key_t key, STATE *s)
>  {
> -  int msgwid;
>    gpgme_user_id_t uids = NULL;
> -  int i, aka = 0;
> +  int aka = 0;
>  
>    state_puts(msg, s);
>    state_puts(" ", s);
> @@ -1634,18 +1633,17 @@ static void print_smime_keyinfo(const char *msg, 
> gpgme_signature_t sig,
>          continue;
>        if (aka)
>        {
> -        msgwid = mutt_strwidth(msg) - mutt_strwidth(_("aka: ")) + 1;
> -        if (msgwid < 0)
> -          msgwid = 0;
> -        for (i = 0; i < msgwid; i++)
> -          state_puts(" ", s);
> -        state_puts(_("aka: "), s);
> +        mutt_align(msg, _("aka: "), s);
>        }

The braces from above should be removed, since now it becomes
a single-line block.

>        state_puts(uids->uid, s);
>        state_puts("\n", s);
>  
>        aka = 1;
>      }
> +
> +    mutt_align(msg, _("KeyId: "), s);
> +    state_puts(key->fpr, s);
> +    state_puts("\n", s);
>    }
>    else
>    {
> @@ -1666,12 +1664,7 @@ static void print_smime_keyinfo(const char *msg, 
> gpgme_signature_t sig,
>       "Jan 1 1970" is not the created date. */
>    if (sig->timestamp)
>    {
> -    msgwid = mutt_strwidth(msg) - mutt_strwidth(_("created: ")) + 1;
> -    if (msgwid < 0)
> -      msgwid = 0;
> -    for (i = 0; i < msgwid; i++)
> -      state_puts(" ", s);
> -    state_puts(_("created: "), s);
> +    mutt_align(msg, _("created: "), s);
>      print_time(sig->timestamp, s);
>      state_puts("\n", s);
>    }
> diff --git a/curs_lib.c b/curs_lib.c
> index 5c93cbb0..e6d1f7d5 100644
> --- a/curs_lib.c
> +++ b/curs_lib.c
> @@ -1654,3 +1654,15 @@ int mutt_strwidth(const char *s)
>    }
>    return w;
>  }
> +
> +void mutt_align(const char *msg, const char *key, STATE *s)
> +{
> +  int msgwid = mutt_strwidth(msg) - mutt_strwidth(_(key)) + 1;
> +  int i;
> +
> +  if (msgwid < 0)
> +    msgwid = 0;
> +  for (i = 0; i < msgwid; i++)

I suggest declaring 'int i' within the loop while doing the refactor.
That's C99, but we already require C99 in mutt(1).

        for (int i = 0; i < msgwid; i++)

> +    state_puts(" ", s);
> +  state_puts(key, s);
> +}

I would suggest doing the refactor in a separate patch, so that the diff
of the actual feature is minimal.  That would make it easier to review.


Have a lovely day!
Alex

> diff --git a/protos.h b/protos.h
> index 4958aa0e..407f4859 100644
> --- a/protos.h
> +++ b/protos.h
> @@ -407,6 +407,7 @@ int mutt_smtp_send(const ADDRESS *, const ADDRESS *, 
> const ADDRESS *,
>  size_t mutt_wstr_trunc(const char *, size_t, size_t, size_t *);
>  int mutt_charlen(const char *s, int *);
>  int mutt_strwidth(const char *);
> +void mutt_align(const char *msg, const char *key, STATE *s);
>  int mutt_compose_menu(SEND_CONTEXT *);
>  int mutt_thread_set_flag(HEADER *, int, int, int);
>  int mutt_user_is_recipient(HEADER *);
> -- 
> 2.47.3
> 
> 



-- 
<https://www.alejandro-colomar.es>

Attachment: signature.asc
Description: PGP signature

Reply via email to