diff options
author | bertrand <Bertrand.Guiheneuf@aful.org> | 1999-08-05 01:42:02 +0800 |
---|---|---|
committer | Bertrand Guiheneuf <bertrand@src.gnome.org> | 1999-08-05 01:42:02 +0800 |
commit | 7e2281704d4da682c013ec04e63adbaa69c49ac6 (patch) | |
tree | 5d19f1ea59f2669a2d7d0516255d12c6bb3c7ee2 /camel | |
parent | e77e777a5701b825eb16f434d7497471635e3bc3 (diff) | |
download | gsoc2013-evolution-7e2281704d4da682c013ec04e63adbaa69c49ac6.tar.gz gsoc2013-evolution-7e2281704d4da682c013ec04e63adbaa69c49ac6.tar.zst gsoc2013-evolution-7e2281704d4da682c013ec04e63adbaa69c49ac6.zip |
indentation and cosmetic changes.
1999-08-04 bertrand <Bertrand.Guiheneuf@aful.org>
* camel/gmime-rfc2047.c:
* camel/gmime-rfc2047.h:
indentation and cosmetic changes.
svn path=/trunk/; revision=1079
Diffstat (limited to 'camel')
-rw-r--r-- | camel/gmime-rfc2047.c | 316 | ||||
-rw-r--r-- | camel/gmime-rfc2047.h | 13 |
2 files changed, 169 insertions, 160 deletions
diff --git a/camel/gmime-rfc2047.c b/camel/gmime-rfc2047.c index 5f68dec92d..e5f48ccbd8 100644 --- a/camel/gmime-rfc2047.c +++ b/camel/gmime-rfc2047.c @@ -1,6 +1,7 @@ -/* - * gmime-rfc2047.c: implemention of RFC2047 - * +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* gmime-rfc2047.c: implemention of RFC2047 */ + +/* * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@inria.fr> . * * This program is free software; you can redistribute it and/or @@ -38,63 +39,64 @@ static int base64_rank_table_built; static void build_base64_rank_table (void); static int hexval(gchar c) { - if (isdigit(c)) return c-'0'; - c = tolower(c); - return c - 'a' + 10; + if (isdigit(c)) return c-'0'; + c = tolower(c); + return c - 'a' + 10; } static void decode_quoted(const gchar *text, gchar *to) { - while (*text) { - if (*text == '=') { - gchar a = hexval(text[1]); - gchar b = hexval(text[2]); - int c = (a << 4) + b; - *to = c; - to++; - text+=3; - } else if (*text == '_') { - *to = ' '; - to++; - text++; - } else { - *to = *text; - to++; - text++; - } - } - *to = 0; + while (*text) { + if (*text == '=') { + gchar a = hexval(text[1]); + gchar b = hexval(text[2]); + int c = (a << 4) + b; + *to = c; + to++; + text+=3; + } else if (*text == '_') { + *to = ' '; + to++; + text++; + } else { + *to = *text; + to++; + text++; + } + } + *to = 0; } -static void decode_base64(const gchar *what, gchar *where) { - unsigned short pattern = 0; - int bits = 0; - int delimiter = '='; - gchar x; - gchar *t = where; - int Q = 0; - while (*what != delimiter) { - x = base64_rank[(unsigned char)(*what++)]; - if (x == NOT_RANKED) - continue; - pattern <<= 6; - pattern |= x; - bits += 6; - if (bits >= 8) { - x = (pattern >> (bits - 8)) & 0xff; - *t++ = x; - Q++; - bits -= 8; - } - } - *t = 0; +static +void decode_base64 (const gchar *what, gchar *where) +{ + unsigned short pattern = 0; + int bits = 0; + int delimiter = '='; + gchar x; + gchar *t = where; + int Q = 0; + while (*what != delimiter) { + x = base64_rank[(unsigned char)(*what++)]; + if (x == NOT_RANKED) + continue; + pattern <<= 6; + pattern |= x; + bits += 6; + if (bits >= 8) { + x = (pattern >> (bits - 8)) & 0xff; + *t++ = x; + Q++; + bits -= 8; + } + } + *t = 0; } static void -build_base64_rank_table ( - void) +build_base64_rank_table (void) { int i; - + if (!base64_rank_table_built) { for (i = 0; i < 256; i++) base64_rank[i] = NOT_RANKED; @@ -104,113 +106,117 @@ build_base64_rank_table ( } } -gchar *gmime_rfc2047_decode(const gchar *data, const gchar *into_what) { - gchar buffer[4096] /* FIXME : constant sized buffer */, *b = buffer; - - build_base64_rank_table(); - - while (*data) { - - /* If we encounter an error we just break out of the loop and copy the rest - * of the text as-is */ - - if (*data=='=') { - data++; - if (*data=='?') { - gchar *charset, *encoding, *text, *end; - gchar dc[4096]; - charset = data+1; - encoding = strchr(charset, '?'); - - if (!encoding) break; - encoding++; - text = strchr(encoding, '?'); - if (!text) break; - text++; - end = strstr(text, "?="); - if (!end) break; - end++; - - *(encoding-1)=0; - *(text-1)=0; - *(end-1)=0; - - if (strcasecmp(encoding, "q")==0) { - decode_quoted(text, dc); - } else if (strcasecmp(encoding, "b")==0) { - decode_base64(text, dc); - } else { - /* What to do here? */ - break; +gchar +*gmime_rfc2047_decode (const gchar *data, const gchar *into_what) +{ + gchar buffer[4096] /* FIXME : constant sized buffer */, *b = buffer; + + build_base64_rank_table(); + + while (*data) { + + /* If we encounter an error we just break out of the loop and copy the rest + * of the text as-is */ + + if (*data=='=') { + data++; + if (*data=='?') { + gchar *charset, *encoding, *text, *end; + gchar dc[4096]; + charset = data+1; + encoding = strchr(charset, '?'); + + if (!encoding) break; + encoding++; + text = strchr(encoding, '?'); + if (!text) break; + text++; + end = strstr(text, "?="); + if (!end) break; + end++; + + *(encoding-1)=0; + *(text-1)=0; + *(end-1)=0; + + if (strcasecmp(encoding, "q")==0) { + decode_quoted(text, dc); + } else if (strcasecmp(encoding, "b")==0) { + decode_base64(text, dc); + } else { + /* What to do here? */ + break; + } + + { + int f; + iconv_t i; + const gchar *d2 = dc; + int l = strlen(d2), l2 = 4000; + + i = unicode_iconv_open(into_what, charset); + if (!i) + break; + + unicode_iconv(i, &d2, &l, &b, &l2); + + unicode_iconv_close(i); + data = end; + } + } + } + else { + *b = *data; + b++; + } + + data++; + } - - { - int f; - iconv_t i; - const gchar *d2 = dc; - int l = strlen(d2), l2 = 4000; - - i = unicode_iconv_open(into_what, charset); - if (!i) - break; - - unicode_iconv(i, &d2, &l, &b, &l2); - - unicode_iconv_close(i); - data = end; + + while (*data) { + *b = *data; + b++; + data++; } - } - } - else { - *b = *data; - b++; - } - - data++; - - } - - while (*data) { - *b = *data; - b++; - data++; - } - - *b = 0; - - return g_strdup(buffer); + + *b = 0; + + return g_strdup(buffer); } -gchar *rfc2047_encode(const gchar *string, const gchar *charset) { - gchar buffer[4096] /* FIXME : constant sized buffer */; - gchar *b = buffer; - const gchar *s = string; - int not_ascii = 0, not_latin1 = 0; - while (*s) { - if (*s <= 20 || *s >= 0x7f || *s == '=') { not_ascii = 1; } - s++; - } - - if (!not_ascii) { - b += sprintf(b, "%s", string); - } - - else { - b += sprintf(b, "=?%s?Q?", charset); - s = string; - while (*s) { - if (*s == ' ') b += sprintf(b, "_"); - else if (*s < 0x20 || *s >= 0x7f || *s == '=' || *s == '?' || *s == '_') { - b += sprintf(b, "=%2x", *s); - } else { - b += sprintf(b, "%c", *s); - } - s++; - } - b += sprintf(b, "?="); - } - - *b = 0; - - return g_strdup(buffer); +gchar +*rfc2047_encode (const gchar *string, const gchar *charset) +{ + gchar buffer[4096] /* FIXME : constant sized buffer */; + gchar *b = buffer; + const gchar *s = string; + int not_ascii = 0, not_latin1 = 0; + while (*s) { + if (*s <= 20 || *s >= 0x7f || *s == '=') { not_ascii = 1; } + s++; + } + + if (!not_ascii) { + b += sprintf(b, "%s", string); + } + + else { + b += sprintf(b, "=?%s?Q?", charset); + s = string; + while (*s) { + if (*s == ' ') b += sprintf(b, "_"); + else if (*s < 0x20 || *s >= 0x7f || *s == '=' || *s == '?' || *s == '_') { + b += sprintf(b, "=%2x", *s); + } else { + b += sprintf(b, "%c", *s); + } + s++; + } + b += sprintf(b, "?="); + } + + *b = 0; + + return g_strdup(buffer); } diff --git a/camel/gmime-rfc2047.h b/camel/gmime-rfc2047.h index 78c463639d..f833b653f4 100644 --- a/camel/gmime-rfc2047.h +++ b/camel/gmime-rfc2047.h @@ -1,6 +1,7 @@ -#ifndef GMIME_RFC2047_H +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* gmime-rfc2047.c: implemention of RFC2047 */ -/* +/* * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@inria.fr> . * * This program is free software; you can redistribute it and/or @@ -20,10 +21,12 @@ * */ +#ifndef GMIME_RFC2047_H +#define GMIME_RFC2047_H 1 #include <glib.h> -gchar *gmime_rfc2047_decode(const gchar *text, const gchar* charset); -gchar *gmime_rfc2047_encode(const gchar *text, const gchar* charset); +gchar *gmime_rfc2047_decode (const gchar *text, const gchar* charset); +gchar *gmime_rfc2047_encode (const gchar *text, const gchar* charset); /* * pass text and charset, (e.g. "UTF-8", or "ISO-8859-1"), and @@ -39,4 +42,4 @@ gchar *gmime_rfc2047_encode(const gchar *text, const gchar* charset); * The caller will need to free the memory for the string. */ -#endif +#endif /* GMIME_RFC2047_H */ |