actually this isn't right either, since it will un-escape quoted-pairs
outside comments as well, but I don't care anymore.
Jeff
On Wed, 2004-08-11 at 12:49 -0400, Jeffrey Stedfast wrote:
> On Wed, 2004-08-11 at 12:09 -0400, Jeffrey Stedfast wrote:
> > On Wed, 2004-08-11 at 11:06 +0800, Not Zed wrote:
> > >
> > > Don't like this, it just duplicates a bunch of code. See attached
> > > (totally untested but i think the logic is right).
> > >
> > > I don't really like it as a ctext decoder anyway, it isn't actually
> > > decoding to the rfc, it is just a simplistic scanner which will
> > > 'probably work in most cases'. e.g. it doesn't handle \ properly in
> > > comments. Then again, this is hardly a major issue.
> > >
> > > The other problem is that it is necessarily a one-way conversion (you
> > > will have to lose the comment structure), perhaps it should be called
> > > _format rather than _decode, to match the rest of the api (i put this
> > > in the patch).
> > >
> >
> > yea, I apparently overlooked 'quoted-pair', but I'm thinking we should
> > handle it before committing a fix. if we're gonna do it, might as well
> > do it right, etc.
> >
> > I do agree that _format() might be a better name and as I mentioned in
> > my original patch mail, I figured we should merge it into
> > header_decode_text() as well.
> >
> > I'll send an updated patch when I finish it.
> >
> > Jeff
> >
> > >
> > > Plain text document attachment (62771.b.diff)
> > > Index: camel/camel-mime-utils.c
> > > ===================================================================
> > > RCS file: /cvs/gnome/evolution/camel/camel-mime-utils.c,v
> > > retrieving revision 1.212
> > > diff -u -3 -r1.212 camel-mime-utils.c
> > > --- camel/camel-mime-utils.c 30 Jul 2004 15:30:38 -0000 1.212
> > > +++ camel/camel-mime-utils.c 11 Aug 2004 03:03:33 -0000
> > > @@ -57,6 +57,9 @@
> > > #include "broken-date-parser.h"
> > > #endif
> > >
> > > +/* syntactic helper for more direct table lookups */
> > > +#define cm_is_mask(x, m) ((camel_mime_special_table[(unsigned char)(x)] & (m)) == 0)
> > > +
> > > #if 0
> > > int strdup_count = 0;
> > > int malloc_count = 0;
> > > @@ -1119,13 +1122,15 @@
> > > }
> > >
> > > /* decodes a simple text, rfc822 + rfc2047 */
> > > +/* If ctext is set, look for rfc2047 encoded words not separated by whitespace */
> > > static char *
> > > -header_decode_text (const char *in, size_t inlen, const char *default_charset)
> > > +header_decode_text (const char *in, size_t inlen, const char *default_charset, int ctext)
> > > {
> > > GString *out;
> > > const char *inptr, *inend, *start, *chunk, *locale_charset;
> > > char *dword = NULL;
> > > -
> > > + int mask;
> > > +
> > > locale_charset = e_iconv_locale_charset ();
> > >
> > > out = g_string_new ("");
> > > @@ -1133,9 +1138,14 @@
> > > inend = inptr + inlen;
> > > chunk = NULL;
> > >
> > > + if (ctext)
> > > + mask = (CAMEL_MIME_IS_SPECIAL|CAMEL_MIME_IS_SPACE|CAMEL_MIME_IS_CTRL);
> > > + else
> > > + mask = (CAMEL_MIME_IS_LWSP);
> > > +
> > > while (inptr < inend) {
> > > start = inptr;
> > > - while (inptr < inend && camel_mime_is_lwsp(*inptr))
> > > + while (inptr < inend && !cm_is_mask(*inptr, mask))
> > > inptr++;
> > >
> > > if (inptr == inend) {
> > > @@ -1148,7 +1158,7 @@
> > > }
> > >
> > > start = inptr;
> > > - while (inptr < inend && !camel_mime_is_lwsp(*inptr))
> > > + while (inptr < inend && cm_is_mask(*inptr, mask))
> > > inptr++;
> > >
> > > dword = rfc2047_decode_word(start, inptr-start);
> > > @@ -1178,7 +1188,15 @@
> > > {
> > > if (in == NULL)
> > > return NULL;
> > > - return header_decode_text (in, strlen (in), default_charset);
> > > + return header_decode_text (in, strlen (in), default_charset, FALSE);
> > > +}
> > > +
> > > +char *
> > > +camel_header_format_ctext(const char *in, const char *default_charset)
> > > +{
> > > + if (in == NULL)
> > > + return NULL;
> > > + return header_decode_text (in, strlen (in), default_charset, TRUE);
> > > }
> > >
> > > /* how long a sequence of pre-encoded words should be less than, to attempt to
> > > @@ -2830,7 +2848,7 @@
> > > node->next = NULL;
> > > node->name = name;
> > > if (strncmp(value, "=?", 2) == 0
> > > - && (node->value = header_decode_text(value, strlen(value), NULL))) {
> > > + && (node->value = header_decode_text(value, strlen(value), NULL, FALSE))) {
> > > g_free(value);
> > > } else if (!g_utf8_validate(value, -1, NULL)) {
> > > const char * charset = e_iconv_locale_charset();
> > > Index: camel/camel-mime-utils.h
> > > ===================================================================
> > > RCS file: /cvs/gnome/evolution/camel/camel-mime-utils.h,v
> > > retrieving revision 1.56
> > > diff -u -3 -r1.56 camel-mime-utils.h
> > > --- camel/camel-mime-utils.h 18 Jun 2004 20:07:09 -0000 1.56
> > > +++ camel/camel-mime-utils.h 11 Aug 2004 03:03:33 -0000
> > > @@ -193,6 +193,8 @@
> > > /* decode/encode a string type, like a subject line */
> > > char *camel_header_decode_string (const char *in, const char *default_charset);
> > > char *camel_header_encode_string (const unsigned char *in);
> > > +/* decode ( text | comment ), this is a one-way op */
> > > +char *camel_header_format_ctext(const char *in, const char *default_charset);
> > >
> > > /* encode a phrase, like the real name of an address */
> > > char *camel_header_encode_phrase (const unsigned char *in);
> Plain text document attachment (62771-mailer.patch)
> ? 55303-2.patch
> ? 55303.patch
> ? 62377.patch
> ? 62771-mailer.patch
> ? mail-session.diff
> ? ms.c
> Index: ChangeLog
> ===================================================================
> RCS file: /cvs/gnome/evolution/mail/ChangeLog,v
> retrieving revision 1.3430
> diff -u -r1.3430 ChangeLog
> --- ChangeLog 10 Aug 2004 19:10:06 -0000 1.3430
> +++ ChangeLog 11 Aug 2004 16:48:52 -0000
> @@ -1,3 +1,12 @@
> +2004-08-10 Jeffrey Stedfast <fejj novell com>
> +
> + Partial fix for bug #62771
> +
> + * em-format-quote.c (emfq_format_header): Same.
> +
> + * em-format-html.c (efh_format_header): Decode the
> + X-Mailer/User-Agent headers.
> +
> 2004-08-06 Jeffrey Stedfast <fejj novell com>
>
> * em-folder-tree-model.c (em_folder_tree_model_get_selected):
> Index: em-format-html.c
> ===================================================================
> RCS file: /cvs/gnome/evolution/mail/em-format-html.c,v
> retrieving revision 1.62
> diff -u -r1.62 em-format-html.c
> --- em-format-html.c 10 Jul 2004 01:31:04 -0000 1.62
> +++ em-format-html.c 11 Aug 2004 16:48:53 -0000
> @@ -1552,7 +1552,7 @@
> } else if (!strcmp(name, "x-evolution-mailer")) {
> /* pseudo-header */
> label = _("Mailer");
> - txt = header->value;
> + txt = value = camel_header_format_ctext (header->value, charset);
> flags |= EM_FORMAT_HEADER_BOLD;
> } else if (!strcmp(name, "date") || !strcmp(name, "resent-date")) {
> int msg_offset, local_tz;
> Index: em-format-quote.c
> ===================================================================
> RCS file: /cvs/gnome/evolution/mail/em-format-quote.c,v
> retrieving revision 1.12
> diff -u -r1.12 em-format-quote.c
> --- em-format-quote.c 10 Jul 2004 01:31:04 -0000 1.12
> +++ em-format-quote.c 11 Aug 2004 16:48:53 -0000
> @@ -309,6 +309,8 @@
> if (!(txt = camel_medium_get_header (part, "user-agent")))
> return;
>
> + txt = value = camel_header_format_ctext (txt, charset);
> +
> label = _("Mailer");
> flags |= EM_FORMAT_HEADER_BOLD;
> } else if (!strcmp (name, "date") || !strcmp (name, "resent-date")) {
> Plain text document attachment (62771-camel.patch)
> ? 24026.patch
> ? 62136.patch
> ? 62771-camel.patch
> ? body
> ? body.c
> ? body.txt
> ? body2.txt
> ? build.patch
> ? charset-map.c
> ? charset-map.diff
> ? class.sh
> ? cmsutil.c
> ? date.patch
> ? flags
> ? foo
> ? foo.txt
> ? foo2.txt
> ? gw-body.txt
> ? iso
> ? iso.c
> ? lang.patch
> ? namespace.sh
> ? smime
> ? providers/imap4/reconnect.patch
> ? tests/data/camel-mime-tests.tar.gz
> Index: ChangeLog
> ===================================================================
> RCS file: /cvs/gnome/evolution/camel/ChangeLog,v
> retrieving revision 1.2237
> diff -u -r1.2237 ChangeLog
> --- ChangeLog 6 Aug 2004 19:24:03 -0000 1.2237
> +++ ChangeLog 11 Aug 2004 16:45:26 -0000
> @@ -1,3 +1,15 @@
> +2004-08-11 Jeffrey Stedfast <fejj novell com>
> +
> + Fix for bug #62771
> +
> + * camel-mime-utils.c (string_append_quoted_pair): New function to
> + append a string of text that may contain quoted-pairs.
> + (header_decode_text): Now takes a ctext argument specifying
> + whether or not to expect comments and to handle them.
> + (camel_header_decode_string): Pass FALSE as ctext argument.
> + (camel_header_format_ctext): New function to format text|comment
> + header field bodies.
> +
> 2004-08-06 Jeffrey Stedfast <fejj novell com>
>
> * providers/imap4/camel-imap4-summary.c (untagged_fetch_all): Call
> Index: camel-mime-utils.c
> ===================================================================
> RCS file: /cvs/gnome/evolution/camel/camel-mime-utils.c,v
> retrieving revision 1.212
> diff -u -r1.212 camel-mime-utils.c
> --- camel-mime-utils.c 30 Jul 2004 15:30:38 -0000 1.212
> +++ camel-mime-utils.c 11 Aug 2004 16:45:26 -0000
> @@ -1118,39 +1118,71 @@
>
> }
>
> +static void
> +string_append_quoted_pair (GString *str, const char *in, int inlen)
> +{
> + register const char *inptr = in;
> + const char *inend = in + inlen;
> + const char *start;
> +
> + while (inptr < inend) {
> + start = inptr;
> + while (inptr < inend && *inptr != '\\')
> + inptr++;
> +
> + g_string_append_len (str, start, inptr - start);
> + inptr++;
> +
> + if (inptr < inend)
> + g_string_append_c (str, *inptr++);
> + }
> +}
> +
> /* decodes a simple text, rfc822 + rfc2047 */
> static char *
> -header_decode_text (const char *in, size_t inlen, const char *default_charset)
> +header_decode_text (const char *in, size_t inlen, int ctext, const char *default_charset)
> {
> GString *out;
> const char *inptr, *inend, *start, *chunk, *locale_charset;
> char *dword = NULL;
> + guint32 mask;
>
> locale_charset = e_iconv_locale_charset ();
>
> + if (ctext)
> + mask = (CAMEL_MIME_IS_SPECIAL | CAMEL_MIME_IS_SPACE | CAMEL_MIME_IS_CTRL);
> + else
> + mask = (CAMEL_MIME_IS_LWSP);
> +
> out = g_string_new ("");
> inptr = in;
> inend = inptr + inlen;
> chunk = NULL;
> -
> +
> while (inptr < inend) {
> start = inptr;
> - while (inptr < inend && camel_mime_is_lwsp(*inptr))
> + while (inptr < inend && camel_mime_is_type (*inptr, mask))
> inptr++;
> -
> +
> if (inptr == inend) {
> - g_string_append_len(out, start, inptr-start);
> + if (ctext)
> + string_append_quoted_pair (out, start, inptr - start);
> + else
> + g_string_append_len (out, start, inptr - start);
> break;
> } else if (dword == NULL) {
> - g_string_append_len(out, start, inptr-start);
> + if (ctext)
> + string_append_quoted_pair (out, start, inptr - start);
> + else
> + g_string_append_len (out, start, inptr - start);
> } else {
> chunk = start;
> }
> -
> +
> start = inptr;
> - while (inptr < inend && !camel_mime_is_lwsp(*inptr))
> + while (inptr < inend && !camel_mime_is_type (*inptr, mask))
> inptr++;
> -
> +
> dword = rfc2047_decode_word(start, inptr-start);
> if (dword) {
> g_string_append(out, dword);
> @@ -1178,7 +1210,15 @@
> {
> if (in == NULL)
> return NULL;
> - return header_decode_text (in, strlen (in), default_charset);
> + return header_decode_text (in, strlen (in), FALSE, default_charset);
> +}
> +
> +char *
> +camel_header_format_ctext (const char *in, const char *default_charset)
> +{
> + if (in == NULL)
> + return NULL;
> + return header_decode_text (in, strlen (in), TRUE, default_charset);
> }
>
> /* how long a sequence of pre-encoded words should be less than, to attempt to
> @@ -2830,7 +2870,7 @@
> node->next = NULL;
> node->name = name;
> if (strncmp(value, "=?", 2) == 0
> - && (node->value = header_decode_text(value, strlen(value), NULL))) {
> + && (node->value = header_decode_text(value, strlen(value), FALSE, NULL))) {
> g_free(value);
> } else if (!g_utf8_validate(value, -1, NULL)) {
> const char * charset = e_iconv_locale_charset();
> Index: camel-mime-utils.h
> ===================================================================
> RCS file: /cvs/gnome/evolution/camel/camel-mime-utils.h,v
> retrieving revision 1.56
> diff -u -r1.56 camel-mime-utils.h
> --- camel-mime-utils.h 18 Jun 2004 20:07:09 -0000 1.56
> +++ camel-mime-utils.h 11 Aug 2004 16:45:26 -0000
> @@ -194,6 +194,9 @@
> char *camel_header_decode_string (const char *in, const char *default_charset);
> char *camel_header_encode_string (const unsigned char *in);
>
> +/* decode (text | comment) - a one-way op */
> +char *camel_header_format_ctext (const char *in, const char *default_charset);
> +
> /* encode a phrase, like the real name of an address */
> char *camel_header_encode_phrase (const unsigned char *in);
>
--
Jeffrey Stedfast
Evolution Hacker - Novell, Inc.
fejj ximian com - www.novell.com
Attachment:
smime.p7s
Description: S/MIME cryptographic signature