X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Fencode_rfc2047.c;h=72d27ce5f084b7142983a33fe64db17a66ecafa3;hp=852c26135ad275d24748e4179d5234fd30994d53;hb=f78e7c6e6e616cc4ff2bee8a726365fafef2d8ce;hpb=5d690daafbcd4ed26d19610fcc017999ee5af892 diff --git a/sbr/encode_rfc2047.c b/sbr/encode_rfc2047.c index 852c261..72d27ce 100644 --- a/sbr/encode_rfc2047.c +++ b/sbr/encode_rfc2047.c @@ -48,9 +48,6 @@ static char *address_headers[] = { c == '/' || c == '=' || c == '_') #define qpspecial(c) (c < ' ' || c == '=' || c == '?' || c == '_') -#define base64len(n) ((((n) + 2) / 3) * 4) /* String len to base64 len */ -#define strbase64(n) ((n) / 4 * 3) /* Chars that fit in base64 */ - #define ENCODELINELIMIT 76 static void unfold_header(char **, int); @@ -59,7 +56,6 @@ static int field_encode_quoted(const char *, char **, const char *, int, int, int); static int scanstring(const char *, int *, int *, int *); static int utf8len(const char *); -/*static int pref_encoding(int, int, int);*/ /* ** Encode a message header using RFC 2047 encoding. We make the assumption @@ -204,7 +200,7 @@ field_encode_quoted(const char *name, char **value, const char *charset, ** least one) until we get to the actual ** text. Copy until we get to a non-space. */ - output = mh_xmalloc(outlen); + output = mh_xcalloc(outlen, sizeof(char)); q = output; while (is_fws(*p)) { *q++ = *p++; @@ -299,7 +295,7 @@ field_encode_quoted(const char *name, char **value, const char *charset, } *q = '\0'; - free(*value); + mh_free0(value); *value = output; return 0; @@ -340,7 +336,7 @@ utf8len(const char *p) static void unfold_header(char **value, int len) { - char *str = mh_xmalloc(len + 1); + char *str = mh_xcalloc(len + 1, sizeof(char)); char *p = str, *q = *value; while (*q != '\0') { @@ -367,7 +363,7 @@ unfold_header(char **value, int len) } *p = '\0'; - free(*value); + mh_free0(value); *value = str; } @@ -574,8 +570,7 @@ do_reformat: output = add(cp, output); column += len; - free(cp); - cp = NULL; + mh_free0(&cp); } /* @@ -588,17 +583,17 @@ do_reformat: output = add("\n", output); - free(*value); + mh_free0(value); *value = output; output = NULL; out: if (tmpbuf) { - free(tmpbuf); + mh_free0(&tmpbuf); } if (output) { - free(output); + mh_free0(&output); } return errflag > 0; @@ -635,38 +630,3 @@ scanstring(const char *string, int *asciilen, int *eightbitchars, return *eightbitchars > 0; } - -#if 0 - -/* -** This function is to be used to decide which encoding algorithm we should -** use if one is not given. Basically, we pick whichever one is the shorter -** of the two. -** -** Arguments are: -** -** ascii - Number of ASCII characters in to-be-encoded string. -** specials - Number of ASCII characters in to-be-encoded string that -** still require encoding under quoted-printable. Note that -** these are included in the "ascii" total. -** eightbit - Eight-bit characters in the to-be-encoded string. -** -** Returns one of CE_BASE64 or CE_QUOTED. -**/ -static int -pref_encoding(int ascii, int specials, int eightbits) -{ - /* - ** The length of the q-p encoding is: - ** - ** ascii - specials + (specials + eightbits) * 3. - ** - ** The length of the base64 encoding is: - ** - ** base64len(ascii + eightbits) (See macro for details) - */ - return base64len(ascii + eightbits) < (ascii - specials + - (specials + eightbits) * 3) ? CE_BASE64 : CE_QUOTED; -} - -#endif