[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Nmh-workers] scan or show of UTF-encoded headers?
From: |
Paul Fox |
Subject: |
Re: [Nmh-workers] scan or show of UTF-encoded headers? |
Date: |
Mon, 14 Feb 2005 17:11:32 -0500 |
it seems that this patch relies on other local changes you've
made to your tree -- i went searching for "get_charset" with google,
and came up with a message you sent to this list on january 24
which contained such a routine, in different mime-related patch. :-)
paul
> > i guess i was thinking of a wrapper for scan or show that took care
> > of setting up the locale and charset, either via argument for manually
> > choosing, or maybe even by examining the message and then figuring out
> > what locale/charset it should probably use, this time.
>
> It's probably easier to hack the C code. I've had a quick go at
> producing something which uses iconv to convert stuff to the native
> character set (patch is below). Would be good if you could try this out
> and look for ways to improve it.
>
> I've not thought through what the between_encodings stuff is doing and
> if that is affected at all. If this is going to be turned into something
> we can commit to CVS, we also need to work out the necessary configure
> stuff for iconv. As it is, you may need to fiddle the Makefile to get
> this to compile.
>
> Oliver
>
> Index: h/prototypes.h
> ===================================================================
> RCS file: /cvsroot/nmh/nmh/h/prototypes.h,v
> retrieving revision 1.9
> diff -u -r1.9 prototypes.h
> --- h/prototypes.h 27 Jan 2005 16:26:24 -0000 1.9
> +++ h/prototypes.h 14 Feb 2005 18:18:38 -0000
> @@ -61,6 +61,7 @@
> char **getans (char *, struct swit *);
> int getanswer (char *);
> char **getarguments (char *, int, char **, int);
> +char *get_charset();
> char *getcpy (char *);
> char *getfolder(int);
> int lkclose(int, char*);
> Index: sbr/fmt_rfc2047.c
> ===================================================================
> RCS file: /cvsroot/nmh/nmh/sbr/fmt_rfc2047.c,v
> retrieving revision 1.2
> diff -u -r1.2 fmt_rfc2047.c
> --- sbr/fmt_rfc2047.c 2 Jul 2002 22:09:14 -0000 1.2
> +++ sbr/fmt_rfc2047.c 14 Feb 2005 18:18:38 -0000
> @@ -10,6 +10,7 @@
> */
>
> #include <h/mh.h>
> +#include <iconv.h>
>
> static signed char hexindex[] = {
> -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
> @@ -97,6 +98,10 @@
>
> /* Check for initial =? */
> if (*p == '=' && p[1] && p[1] == '?' && p[2]) {
> + int use_iconv = 0;
> + iconv_t cd;
> + char *saveq, *convbuf;
> +
> startofmime = p + 2;
>
> /* Scan ahead for the next '?' character */
> @@ -106,9 +111,14 @@
> if (!*pp)
> continue;
>
> - /* Check if character set is OK */
> - if (!check_charset(startofmime, pp - startofmime))
> - continue;
> + /* Check if character set can be handled natively */
> + if (!check_charset(startofmime, pp - startofmime)) {
> + use_iconv = 1;
> + *pp = '\0';
> + cd = iconv_open(get_charset(), startofmime);
> + *pp = '?';
> + if (cd == (iconv_t)-1) continue;
> + }
>
> startofmime = pp + 1;
>
> @@ -159,6 +169,12 @@
> if (between_encodings)
> q -= whitespace;
>
> + if (use_iconv) {
> + saveq = q;
> + if (!(q = convbuf = (char *)malloc(endofmime - startofmime)))
> + continue;
> + }
> +
> /* Now decode the text */
> if (quoted_printable) {
> for (pp = startofmime; pp < endofmime; pp++) {
> @@ -218,6 +234,15 @@
> }
> }
>
> + if (use_iconv) {
> + size_t inbytes = q - convbuf, outbytes = BUFSIZ;
> + char *start = convbuf;
> + iconv(cd, &start, &inbytes, &saveq, &outbytes);
> + q = saveq;
> + iconv_close(cd);
> + free(convbuf);
> + }
> +
> /*
> * Now that we are done decoding this particular
> * encoded word, advance string to trailing '='.
>
>
> _______________________________________________
> Nmh-workers mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/nmh-workers
=---------------------
paul fox, address@hidden (arlington, ma, where it's 31.3 degrees)
- [Nmh-workers] scan or show of UTF-encoded headers?, Paul Fox, 2005/02/13
- Re: [Nmh-workers] scan or show of UTF-encoded headers?, Oliver Kiddle, 2005/02/14
- Re: [Nmh-workers] scan or show of UTF-encoded headers?, Harald Geyer, 2005/02/14
- Re: [Nmh-workers] scan or show of UTF-encoded headers?, Valdis . Kletnieks, 2005/02/14
- Re: [Nmh-workers] scan or show of UTF-encoded headers?, Harald Geyer, 2005/02/14
- Re: [Nmh-workers] scan or show of UTF-encoded headers?, Oliver Kiddle, 2005/02/15