From: Richard Russon Date: Sat, 14 Jul 2018 16:22:36 +0000 (+0100) Subject: tidy rfc2047 X-Git-Tag: 2019-10-25~755^2~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=66e7cf4a30ee8b5e9709a2d1a881d830c3bde0b8;p=neomutt tidy rfc2047 --- diff --git a/email/rfc2047.c b/email/rfc2047.c index ff8c89641..6ff6a56db 100644 --- a/email/rfc2047.c +++ b/email/rfc2047.c @@ -319,7 +319,7 @@ static size_t encode_block(char *str, char *buf, size_t buflen, const char *from static size_t choose_block(char *d, size_t dlen, int col, const char *fromcode, const char *tocode, encoder_t *encoder, size_t *wlen) { - const int utf8 = fromcode && (mutt_str_strcasecmp(fromcode, "utf-8") == 0); + const bool utf8 = fromcode && (mutt_str_strcasecmp(fromcode, "utf-8") == 0); size_t n = dlen; while (true) @@ -359,7 +359,7 @@ static void finalize_chunk(struct Buffer *res, struct Buffer *buf, char *charset } /** - * rfc2047_decode_word - Decode an RFC2047-encoded string + * decode_word - Decode an RFC2047-encoded string * @param s String to decode * @param len Length of the string * @param enc Encoding type @@ -367,7 +367,7 @@ static void finalize_chunk(struct Buffer *res, struct Buffer *buf, char *charset * * @note The caller must free the returned string */ -static char *rfc2047_decode_word(const char *s, size_t len, enum ContentEncoding enc) +static char *decode_word(const char *s, size_t len, enum ContentEncoding enc) { const char *it = s; const char *end = s + len; @@ -414,7 +414,7 @@ static char *rfc2047_decode_word(const char *s, size_t len, enum ContentEncoding } /** - * rfc2047_encode2 - RFC2047-encode a string + * encode - RFC2047-encode a string * @param d String to convert * @param dlen Length of string * @param col Starting column to convert @@ -425,7 +425,7 @@ static char *rfc2047_decode_word(const char *s, size_t len, enum ContentEncoding * @param specials Special characters to be encoded * @retval 0 Success */ -static int rfc2047_encode2(const char *d, size_t dlen, int col, +static int encode(const char *d, size_t dlen, int col, const char *fromcode, const char *charsets, char **e, size_t *elen, const char *specials) { @@ -562,13 +562,13 @@ static int rfc2047_encode2(const char *d, size_t dlen, int col, if (icode) while (CONTINUATION_BYTE(t[n])) n--; - if (!n) + if (n == 0) { /* This should only happen in the really stupid case where the - only word that needs encoding is one character long, but - there is too much us-ascii stuff after it to use a single - encoded word. We add the next word to the encoded region - and try again. */ + * only word that needs encoding is one character long, but + * there is too much us-ascii stuff after it to use a single + * encoded word. We add the next word to the encoded region + * and try again. */ assert(t1 < (u + ulen)); for (t1++; (t1 < (u + ulen)) && !HSPACE(*t1); t1++) ; @@ -624,16 +624,15 @@ static int rfc2047_encode2(const char *d, size_t dlen, int col, */ void rfc2047_encode(char **pd, const char *specials, int col, const char *charsets) { - char *e = NULL; - size_t elen; - if (!Charset || !*pd) return; if (!charsets || !*charsets) charsets = "utf-8"; - rfc2047_encode2(*pd, strlen(*pd), col, Charset, charsets, &e, &elen, specials); + char *e = NULL; + size_t elen = 0; + encode(*pd, strlen(*pd), col, Charset, charsets, &e, &elen, specials); FREE(pd); *pd = e; @@ -710,7 +709,7 @@ void rfc2047_decode(char **pd) { /* Some encoded text was found */ text[textlen] = '\0'; - char *decoded = rfc2047_decode_word(text, textlen, enc); + char *decoded = decode_word(text, textlen, enc); if (!decoded) { return; @@ -774,7 +773,7 @@ void rfc2047_decode_addrlist(struct Address *a) { rfc2047_decode(&a->personal); } - else if (a->group && a->mailbox && (strstr(a->mailbox, "=?") != NULL)) + else if (a->group && a->mailbox && strstr(a->mailbox, "=?")) rfc2047_decode(&a->mailbox); a = a->next; }