hi,

I've made a change to EmailHandler.java. With this change it will use the correct encoding most of the time to load the email body if it is specified as an url. (The loading of the url used to be done in the encoding the JVM was using, but that is not always correct)

This change assumes the default encoding for http is iso-8859-1 (that's in the spec), if the Content-Type header is set it uses that one to determine the encoding: defaults for mimetypes text/plain, text/html and text/xml and if a charset is specified that one is used.

The ony thing that is not taken into account is the setting of the encoding in the document itself (the first line of the xml file, or a META tag in html).

This diff is made against the HEAD, not the 1.7 stable branch, I can provide one for that as well if it's needed.

I hope you agree this is a useful fix and that someone wants to put it in CVS.

Simon
RCS file: 
/usr/local/cvs/applications/email/src/org/mmbase/applications/email/EmailHandler.java,v
retrieving revision 1.11
diff -r1.11 EmailHandler.java
194c194,223
<             BufferedReader in = new BufferedReader(new InputStreamReader 
(connection.getInputStream()));
---
>             String contentType = connection.getContentType();
>             
>             // Default encoding for http transport is iso-8859-1
>             encoding = "ISO-8859-1";
>             
>             // If a Content-Type header is present: get the encoding from there
>             if (contentType != null) {
> 
>                StringTokenizer tokenizer = new StringTokenizer(contentType, "; ");
>                while (tokenizer.hasMoreTokens()) {
>                   String value = tokenizer.nextToken();
>                   if (value.startsWith("charset=")) {
>                       // charset overrides the defaults for the mimetypes
>                       encoding = value.substring(8);
>                   }
>                   if (value.equals("text/xml")) {
>                       // default encoding for text/xml
>                       encoding = "utf-8";
>                   }
>                   if (value.equals("text/html")) {
>                       // default encoding for text/html
>                       encoding = "ISO-8859-1";
>                   }
>                   if (value.equals("text/plain")) {
>                       // default encoding for text/plain
>                       encoding = "ISO-8859-1";
>                   }
>                }
>             }
>             BufferedReader in = new BufferedReader(new InputStreamReader 
> (connection.getInputStream(), encoding));

Reply via email to