From 4d8a9df7629569a99f0dd590e66f6dbd3c03ed04 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Sat, 23 Jun 2018 01:23:52 +0100 Subject: [PATCH] mutt_get_body_charset --- ncrypt/crypt_gpgme.c | 2 +- ncrypt/pgp.c | 4 ++-- protos.h | 2 +- recvattach.c | 4 ++-- sendlib.c | 24 ++++++++++++------------ 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ncrypt/crypt_gpgme.c b/ncrypt/crypt_gpgme.c index e0bd561a9..1435f18cb 100644 --- a/ncrypt/crypt_gpgme.c +++ b/ncrypt/crypt_gpgme.c @@ -2460,7 +2460,7 @@ int pgp_gpgme_application_handler(struct Body *m, struct State *s) /* For clearsigned messages we won't be able to get a character set but we know that this may only be text thus we assume Latin-1 here. */ - if (!mutt_get_body_charset(body_charset, sizeof(body_charset), m)) + if (!mutt_body_get_charset(m, body_charset, sizeof(body_charset))) mutt_str_strfcpy(body_charset, "iso-8859-1", sizeof(body_charset)); fseeko(s->fpin, m->offset, SEEK_SET); diff --git a/ncrypt/pgp.c b/ncrypt/pgp.c index 01850f775..487818f13 100644 --- a/ncrypt/pgp.c +++ b/ncrypt/pgp.c @@ -417,7 +417,7 @@ int pgp_class_application_handler(struct Body *m, struct State *s) char *gpgcharset = NULL; char body_charset[STRING]; - mutt_get_body_charset(body_charset, sizeof(body_charset), m); + mutt_body_get_charset(m, body_charset, sizeof(body_charset)); rc = 0; /* silence false compiler warning if (s->flags & MUTT_DISPLAY) */ @@ -1609,7 +1609,7 @@ struct Body *pgp_class_traditional_encryptsign(struct Body *a, int flags, char * * we have to convert from $charset to utf-8. */ - mutt_get_body_charset(body_charset, sizeof(body_charset), a); + mutt_body_get_charset(a, body_charset, sizeof(body_charset)); if (a->noconv) from_charset = body_charset; else diff --git a/protos.h b/protos.h index 53b0c127b..a6f9e0bd0 100644 --- a/protos.h +++ b/protos.h @@ -129,7 +129,7 @@ char *mutt_expand_path(char *s, size_t slen); char *mutt_expand_path_regex(char *s, size_t slen, bool regex); char *mutt_find_hook(int type, const char *pat); char *mutt_gecos_name(char *dest, size_t destlen, struct passwd *pw); -char *mutt_get_body_charset(char *d, size_t dlen, struct Body *b); +char *mutt_body_get_charset(struct Body *b, char *buf, size_t buflen); void mutt_crypt_hook(struct ListHead *list, struct Address *addr); void mutt_timeout_hook(void); void mutt_startup_shutdown_hook(int type); diff --git a/recvattach.c b/recvattach.c index 795d6dead..717eee85b 100644 --- a/recvattach.c +++ b/recvattach.c @@ -211,7 +211,7 @@ const char *attach_format_str(char *buf, size_t buflen, size_t col, int cols, if (!optional) { if (mutt_is_text_part(aptr->content) && - mutt_get_body_charset(charset, sizeof(charset), aptr->content)) + mutt_body_get_charset(aptr->content, charset, sizeof(charset))) { mutt_format_s(buf, buflen, prec, charset); } @@ -219,7 +219,7 @@ const char *attach_format_str(char *buf, size_t buflen, size_t col, int cols, mutt_format_s(buf, buflen, prec, ""); } else if (!mutt_is_text_part(aptr->content) || - !mutt_get_body_charset(charset, sizeof(charset), aptr->content)) + !mutt_body_get_charset(aptr->content, charset, sizeof(charset))) { optional = 0; } diff --git a/sendlib.c b/sendlib.c index 6171c5d73..afa5f037b 100644 --- a/sendlib.c +++ b/sendlib.c @@ -507,7 +507,7 @@ int mutt_write_mime_body(struct Body *a, FILE *f) { char send_charset[SHORT_STRING]; fc = mutt_ch_fgetconv_open( - fpin, a->charset, mutt_get_body_charset(send_charset, sizeof(send_charset), a), 0); + fpin, a->charset, mutt_body_get_charset(a, send_charset, sizeof(send_charset)), 0); } else fc = mutt_ch_fgetconv_open(fpin, 0, 0, 0); @@ -1291,7 +1291,7 @@ static void set_encoding(struct Body *b, struct Content *info) if (b->type == TYPETEXT) { char send_charset[SHORT_STRING]; - char *chsname = mutt_get_body_charset(send_charset, sizeof(send_charset), b); + char *chsname = mutt_body_get_charset(b, send_charset, sizeof(send_charset)); if ((info->lobin && (mutt_str_strncasecmp(chsname, "iso-2022", 8) != 0)) || info->linemax > 990 || (info->from && EncodeFrom)) { @@ -1348,29 +1348,29 @@ void mutt_stamp_attachment(struct Body *a) } /** - * mutt_get_body_charset - Get a body's character set - * @param d Buffer for the result - * @param dlen Length of the buffer - * @param b Body to examine + * mutt_body_get_charset - Get a body's character set + * @param b Body to examine + * @param buf Buffer for the result + * @param buflen Length of the buffer * @retval ptr Buffer containing character set * @retval NULL On error, or if not a text type */ -char *mutt_get_body_charset(char *d, size_t dlen, struct Body *b) +char *mutt_body_get_charset(struct Body *b, char *buf, size_t buflen) { char *p = NULL; - if (b && b->type != TYPETEXT) + if (b && (b->type != TYPETEXT)) return NULL; if (b) p = mutt_param_get(&b->parameter, "charset"); if (p) - mutt_ch_canonical_charset(d, dlen, p); + mutt_ch_canonical_charset(buf, buflen, p); else - mutt_str_strfcpy(d, "us-ascii", dlen); + mutt_str_strfcpy(buf, "us-ascii", buflen); - return d; + return buf; } /** @@ -1385,7 +1385,7 @@ void mutt_update_encoding(struct Body *a) char chsbuf[STRING]; /* override noconv when it's us-ascii */ - if (mutt_ch_is_us_ascii(mutt_get_body_charset(chsbuf, sizeof(chsbuf), a))) + if (mutt_ch_is_us_ascii(mutt_body_get_charset(a, chsbuf, sizeof(chsbuf)))) a->noconv = false; if (!a->force_charset && !a->noconv) -- 2.40.0