X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=rfc2047.c;h=596b32747c2baafb6384f43373dd7f87f3a35bbd;hp=9ab46e766a9cf80532d111261c5278554836789b;hb=34a88259726b0a7dacc3affe6f37214f893c9ce3;hpb=df70e07e24add1869bcc9b7af2277d9d0c09a281 diff --git a/rfc2047.c b/rfc2047.c index 9ab46e7..596b327 100644 --- a/rfc2047.c +++ b/rfc2047.c @@ -1,20 +1,11 @@ /* + * Copyright notice from original mutt: * Copyright (C) 1996-2000 Michael R. Elkins * Copyright (C) 2000-2001 Edmund Grimley Evans - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * + * This file is part of mutt-ng, see http://www.muttng.org/. + * It's licensed under the GNU General Public License, + * please see the file GPL in the top level source directory. */ #if HAVE_CONFIG_H @@ -26,6 +17,9 @@ #include "charset.h" #include "rfc2047.h" +#include "lib/mem.h" +#include "lib/str.h" + #include #include #include @@ -42,7 +36,7 @@ #endif #define ENCWORD_LEN_MAX 75 -#define ENCWORD_LEN_MIN 9 /* strlen ("=?.?.?.?=") */ +#define ENCWORD_LEN_MIN 9 /* safe_strlen ("=?.?.?.?=") */ #define HSPACE(x) ((x) == '\0' || (x) == ' ' || (x) == '\t') @@ -100,7 +94,7 @@ char *mutt_choose_charset (const char *fromcode, const char *charsets, q = strchr (p, ':'); - n = q ? q - p : strlen (p); + n = q ? q - p : safe_strlen (p); if (!n || /* Assume that we never need more than 12 characters of @@ -142,7 +136,7 @@ char *mutt_choose_charset (const char *fromcode, const char *charsets, *dlen = elen; mutt_canonical_charset (canonical_buff, sizeof (canonical_buff), tocode); - mutt_str_replace (&tocode, canonical_buff); + str_replace (&tocode, canonical_buff); } return tocode; } @@ -153,7 +147,7 @@ static size_t b_encoder (char *s, ICONV_CONST char *d, size_t dlen, char *s0 = s; memcpy (s, "=?", 2), s += 2; - memcpy (s, tocode, strlen (tocode)), s += strlen (tocode); + memcpy (s, tocode, safe_strlen (tocode)), s += safe_strlen (tocode); memcpy (s, "?B?", 3), s += 3; for (;;) { if (!dlen) @@ -191,7 +185,7 @@ static size_t q_encoder (char *s, ICONV_CONST char *d, size_t dlen, char *s0 = s; memcpy (s, "=?", 2), s += 2; - memcpy (s, tocode, strlen (tocode)), s += strlen (tocode); + memcpy (s, tocode, safe_strlen (tocode)), s += safe_strlen (tocode); memcpy (s, "?Q?", 3), s += 3; while (dlen--) { unsigned char c = *d++; @@ -233,7 +227,7 @@ static size_t try_block (ICONV_CONST char *d, size_t dlen, if (fromcode) { cd = mutt_iconv_open (tocode, fromcode, 0); assert (cd != (iconv_t) (-1)); - ib = d, ibl = dlen, ob = buf1, obl = sizeof (buf1) - strlen (tocode); + ib = d, ibl = dlen, ob = buf1, obl = sizeof (buf1) - safe_strlen (tocode); if (iconv (cd, &ib, &ibl, &ob, &obl) == (size_t) (-1) || iconv (cd, 0, 0, &ob, &obl) == (size_t) (-1)) { assert (errno == E2BIG); @@ -244,8 +238,8 @@ static size_t try_block (ICONV_CONST char *d, size_t dlen, iconv_close (cd); } else { - if (dlen > sizeof (buf1) - strlen (tocode)) - return sizeof (buf1) - strlen (tocode) + 1; + if (dlen > sizeof (buf1) - safe_strlen (tocode)) + return sizeof (buf1) - safe_strlen (tocode) + 1; memcpy (buf1, d, dlen); ob = buf1 + dlen; } @@ -260,7 +254,7 @@ static size_t try_block (ICONV_CONST char *d, size_t dlen, ++count; } - len = ENCWORD_LEN_MIN - 2 + strlen (tocode); + len = ENCWORD_LEN_MIN - 2 + safe_strlen (tocode); len_b = len + (((ob - buf1) + 2) / 3) * 4; len_q = len + (ob - buf1) + 2 * count; @@ -299,7 +293,7 @@ static size_t encode_block (char *s, char *d, size_t dlen, if (fromcode) { cd = mutt_iconv_open (tocode, fromcode, 0); assert (cd != (iconv_t) (-1)); - ib = d, ibl = dlen, ob = buf1, obl = sizeof (buf1) - strlen (tocode); + ib = d, ibl = dlen, ob = buf1, obl = sizeof (buf1) - safe_strlen (tocode); n1 = iconv (cd, &ib, &ibl, &ob, &obl); n2 = iconv (cd, 0, 0, &ob, &obl); assert (n1 != (size_t) (-1) && n2 != (size_t) (-1)); @@ -486,15 +480,15 @@ static int rfc2047_encode (ICONV_CONST char *d, size_t dlen, int col, /* Add to output buffer. */ #define LINEBREAK "\n\t" - if (bufpos + wlen + strlen (LINEBREAK) > buflen) { - buflen = bufpos + wlen + strlen (LINEBREAK); + if (bufpos + wlen + safe_strlen (LINEBREAK) > buflen) { + buflen = bufpos + wlen + safe_strlen (LINEBREAK); safe_realloc (&buf, buflen); } r = encode_block (buf + bufpos, t, n, icode, tocode, encoder); assert (r == wlen); bufpos += wlen; - memcpy (buf + bufpos, LINEBREAK, strlen (LINEBREAK)); - bufpos += strlen (LINEBREAK); + memcpy (buf + bufpos, LINEBREAK, safe_strlen (LINEBREAK)); + bufpos += safe_strlen (LINEBREAK); #undef LINEBREAK col = 1; @@ -533,7 +527,7 @@ void _rfc2047_encode_string (char **pd, int encode_specials, int col) if (!charsets || !*charsets) charsets = "UTF-8"; - rfc2047_encode (*pd, strlen (*pd), col, + rfc2047_encode (*pd, safe_strlen (*pd), col, Charset, charsets, &e, &elen, encode_specials ? RFC822Specials : NULL); @@ -544,7 +538,7 @@ void _rfc2047_encode_string (char **pd, int encode_specials, int col) void rfc2047_encode_adrlist (ADDRESS * addr, const char *tag) { ADDRESS *ptr = addr; - int col = tag ? strlen (tag) + 2 : 32; + int col = tag ? safe_strlen (tag) + 2 : 32; while (ptr) { if (ptr->personal) @@ -565,7 +559,7 @@ static int rfc2047_decode_word (char *d, const char *s, size_t len) int enc = 0, count = 0; char *charset = NULL; - pd = d0 = safe_malloc (strlen (s)); + pd = d0 = safe_malloc (safe_strlen (s)); for (pp = s; (pp1 = strchr (pp, '?')); pp = pp1 + 1) { count++; @@ -721,14 +715,14 @@ void rfc2047_decode (char **pd) if (!s || !*s) return; - dlen = 4 * strlen (s); /* should be enough */ + dlen = 4 * safe_strlen (s); /* should be enough */ d = d0 = safe_malloc (dlen + 1); while (*s && dlen > 0) { if (!(p = find_encoded_word (s, &q))) { /* no encoded words */ if (!option (OPTSTRICTMIME)) { - n = mutt_strlen (s); + n = safe_strlen (s); if (found_encoded && (m = lwslen (s, n)) != 0) { if (m != n) *d = ' ', d++, dlen--; @@ -741,7 +735,7 @@ void rfc2047_decode (char **pd) t = safe_malloc (n + 1); strfcpy (t, s, n + 1); if (mutt_convert_nonmime_string (&t) == 0) { - tlen = mutt_strlen (t); + tlen = safe_strlen (t); strncpy (d, t, tlen); d += tlen; } @@ -791,7 +785,7 @@ void rfc2047_decode (char **pd) rfc2047_decode_word (d, p, dlen); found_encoded = 1; s = q; - n = mutt_strlen (d); + n = safe_strlen (d); dlen -= n; d += n; } @@ -799,7 +793,7 @@ void rfc2047_decode (char **pd) FREE (pd); *pd = d0; - mutt_str_adjust (pd); + str_adjust (pd); } void rfc2047_decode_adrlist (ADDRESS * a)