You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2007/04/23 14:11:28 UTC
svn commit: r531444 -
/james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
Author: norman
Date: Mon Apr 23 05:11:16 2007
New Revision: 531444
URL: http://svn.apache.org/viewvc?view=rev&rev=531444
Log:
Use default charset of ISO8859-1 if charset could not retrived. Thx to GX; -)
Modified:
james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
Modified: james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java?view=diff&rev=531444&r1=531443&r2=531444
==============================================================================
--- james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java (original)
+++ james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java Mon Apr 23 05:11:16 2007
@@ -1119,10 +1119,11 @@
}
public static java.nio.charset.Charset getCharset(String charsetName) {
+ if(charsetName == null) charsetName = "ISO8859-1";
+
java.nio.charset.Charset c = java.nio.charset.Charset.forName(charsetName);
if (c == null) {
- //TODO: Check what touse as default
c = java.nio.charset.Charset.forName("ISO8859-1");
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
Re: svn commit: r531444 - /james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
Posted by Bernd Fondermann <be...@googlemail.com>.
On 4/23/07, Norman Maurer <no...@apache.org> wrote:
> You are right , but do you mean "ISO-8859-1" ?
exactly, you are right :-)
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
Re: svn commit: r531444 - /james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
Posted by Norman Maurer <no...@apache.org>.
You are right , but do you mean "ISO-8859-1" ?
bye
Norman
Bernd Fondermann schrieb:
> The second "if" should not be needed anymore.
>
> The javadoc suggests that the charset name is not "ISO8851-1" but
> "ISO-8851-1" (which is also required to be supported by every
> platform)
>
> FWIW, J1.5 has Charset.defaultCharset() which is not applicable for 1.4.
>
> Bernd
>
> On 4/23/07, norman@apache.org <no...@apache.org> wrote:
>> Author: norman
>> Date: Mon Apr 23 05:11:16 2007
>> New Revision: 531444
>>
>> URL: http://svn.apache.org/viewvc?view=rev&rev=531444
>> Log:
>> Use default charset of ISO8859-1 if charset could not retrived. Thx
>> to GX; -)
>>
>> Modified:
>> james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>>
>> Modified:
>> james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>> URL:
>> http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java?view=diff&rev=531444&r1=531443&r2=531444
>>
>> ==============================================================================
>>
>> --- james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>> (original)
>> +++ james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>> Mon Apr 23 05:11:16 2007
>> @@ -1119,10 +1119,11 @@
>> }
>>
>> public static java.nio.charset.Charset getCharset(String
>> charsetName) {
>> + if(charsetName == null) charsetName = "ISO8859-1";
>> +
>> java.nio.charset.Charset c =
>> java.nio.charset.Charset.forName(charsetName);
>>
>> if (c == null) {
>> - //TODO: Check what touse as default
>> c = java.nio.charset.Charset.forName("ISO8859-1");
>>
>> }
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-dev-help@james.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>
>
> !DSPAM:1,462ca7aa324327258322836!
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
Re: svn commit: r531444 - /james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
Posted by Bernd Fondermann <bf...@brainlounge.de>.
Stefano Bagnara wrote:
> Bernd Fondermann ha scritto:
>> The second "if" should not be needed anymore.
>>
>> The javadoc suggests that the charset name is not "ISO8851-1" but
>> "ISO-8851-1" (which is also required to be supported by every
>> platform)
>>
>> FWIW, J1.5 has Charset.defaultCharset() which is not applicable for 1.4.
>
> The "new InputStreamReader(new ByteArrayInputStream(new
> byte[0]).getEncoding()" I referred in the other reply should be the
> workaround to get the same result.
>
> Btw, do you think this is appropriate as the default charset to use to
> decode messages encoded with an unknown format?
>
> Your sentence "the second if should not be needed" made me think that an
> empty charset should be treated as an unknown charset.
> So if on unknown charset we simply let the runtime exceptions (
> IllegalCharsetNameException/UnsupportedCharsetException to be raised why
> don't we do the same on null/empty/wrong charset ?
>
> Please note that I don't know who calls this CharsetUtil method, and how
> they handle runtime exceptions (no time to check this now).
But that would be crucial for deciding if the method should fast-fail or
use a proper default. It's all about the method contract. The original
TODO comment suggests it's ok to have a default.
Bernd
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
Re: svn commit: r531444 - /james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
Posted by Stefano Bagnara <ap...@bago.org>.
Bernd Fondermann ha scritto:
> The second "if" should not be needed anymore.
>
> The javadoc suggests that the charset name is not "ISO8851-1" but
> "ISO-8851-1" (which is also required to be supported by every
> platform)
>
> FWIW, J1.5 has Charset.defaultCharset() which is not applicable for 1.4.
The "new InputStreamReader(new ByteArrayInputStream(new
byte[0]).getEncoding()" I referred in the other reply should be the
workaround to get the same result.
Btw, do you think this is appropriate as the default charset to use to
decode messages encoded with an unknown format?
Your sentence "the second if should not be needed" made me think that an
empty charset should be treated as an unknown charset.
So if on unknown charset we simply let the runtime exceptions (
IllegalCharsetNameException/UnsupportedCharsetException to be raised why
don't we do the same on null/empty/wrong charset ?
Please note that I don't know who calls this CharsetUtil method, and how
they handle runtime exceptions (no time to check this now).
Stefano
> Bernd
>
> On 4/23/07, norman@apache.org <no...@apache.org> wrote:
>> Author: norman
>> Date: Mon Apr 23 05:11:16 2007
>> New Revision: 531444
>>
>> URL: http://svn.apache.org/viewvc?view=rev&rev=531444
>> Log:
>> Use default charset of ISO8859-1 if charset could not retrived. Thx to
>> GX; -)
>>
>> Modified:
>> james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>>
>> Modified:
>> james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>> URL:
>> http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java?view=diff&rev=531444&r1=531443&r2=531444
>>
>> ==============================================================================
>>
>> --- james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>> (original)
>> +++ james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>> Mon Apr 23 05:11:16 2007
>> @@ -1119,10 +1119,11 @@
>> }
>>
>> public static java.nio.charset.Charset getCharset(String
>> charsetName) {
>> + if(charsetName == null) charsetName = "ISO8859-1";
>> +
>> java.nio.charset.Charset c =
>> java.nio.charset.Charset.forName(charsetName);
>>
>> if (c == null) {
>> - //TODO: Check what touse as default
>> c = java.nio.charset.Charset.forName("ISO8859-1");
>>
>> }
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-dev-help@james.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
Re: svn commit: r531444 - /james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
Posted by Bernd Fondermann <be...@googlemail.com>.
The second "if" should not be needed anymore.
The javadoc suggests that the charset name is not "ISO8851-1" but
"ISO-8851-1" (which is also required to be supported by every
platform)
FWIW, J1.5 has Charset.defaultCharset() which is not applicable for 1.4.
Bernd
On 4/23/07, norman@apache.org <no...@apache.org> wrote:
> Author: norman
> Date: Mon Apr 23 05:11:16 2007
> New Revision: 531444
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=531444
> Log:
> Use default charset of ISO8859-1 if charset could not retrived. Thx to GX; -)
>
> Modified:
> james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>
> Modified: james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
> URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java?view=diff&rev=531444&r1=531443&r2=531444
> ==============================================================================
> --- james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java (original)
> +++ james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java Mon Apr 23 05:11:16 2007
> @@ -1119,10 +1119,11 @@
> }
>
> public static java.nio.charset.Charset getCharset(String charsetName) {
> + if(charsetName == null) charsetName = "ISO8859-1";
> +
> java.nio.charset.Charset c = java.nio.charset.Charset.forName(charsetName);
>
> if (c == null) {
> - //TODO: Check what touse as default
> c = java.nio.charset.Charset.forName("ISO8859-1");
>
> }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
Re: svn commit: r531444 - /james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
Posted by Niklas Therning <ni...@trillian.se>.
Stefano Bagnara wrote:
> Are you sure the problem is that charsetName is null?
> Isn't instead this method called with "anychar" ?
>
> Wouldn't it be better to catch UnsupportedCharsetException and
> IllegalCharsetNameException around Charset.forName and simply leave c
> as null so that the following if will simply use the already present
> default?
>
> And, at the moment, I would leave the TODO there, because maybe
> ISO8859-1 is not the best default for everyone.
>
> I thought about using:
> new InputStreamReader(new ByteArrayInputStream(new byte[0]).getEncoding()
> But this would return UTF8 on system having a default file encoding
> set to UTF8 and maybe it is not good to parse email as UTF8 when
> unspecified.
>
> Any hint?
>
> Stefano
CharsetUtil.getCharset() is only used when writing a Message using
Message.writeTo(). When parsing to a Message object the default is to
use ISO8859-1 if the charset specified in the message is unknown or not
specified.
--
Niklas Therning
www.spamdrain.net
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
Re: svn commit: r531444 - /james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
Posted by Norman Maurer <no...@apache.org>.
Bernd Fondermann schrieb:
> On 4/23/07, Stefano Bagnara <ap...@bago.org> wrote:
>> Niklas Therning ha scritto:
>> > Yes, US-ASCII is the default if nothing is specified when parsing to a
>> > Message object. That's why MessageBuilder uses ISO8859-1 as default
>> > since it's a 8-bit superset of US-ASCII. If we use US-ASCII it will
>> > probably break some messages since sometimes 8-bit charsets are used
>> > even if no charset is specified. Using ISO8859-1 (or some other 8-bit
>> > encoding) will break those messages less than using US-ASCII in
>> those cases.
>>
>> Good point.
>> I'm fine with ISO-8859-1 too (Why not ISO-8859-15, then, so we have euro
>> working? )
>
> euro is cool, but only ISO-8859-1 is required to be supported in every
> Java impl.
>
> Bernd
I just checked in some new code which should handle all kind of problems ..
bye
Norman
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
Re: svn commit: r531444 - /james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
Posted by Bernd Fondermann <be...@googlemail.com>.
On 4/23/07, Stefano Bagnara <ap...@bago.org> wrote:
> Niklas Therning ha scritto:
> > Yes, US-ASCII is the default if nothing is specified when parsing to a
> > Message object. That's why MessageBuilder uses ISO8859-1 as default
> > since it's a 8-bit superset of US-ASCII. If we use US-ASCII it will
> > probably break some messages since sometimes 8-bit charsets are used
> > even if no charset is specified. Using ISO8859-1 (or some other 8-bit
> > encoding) will break those messages less than using US-ASCII in those cases.
>
> Good point.
> I'm fine with ISO-8859-1 too (Why not ISO-8859-15, then, so we have euro
> working? )
euro is cool, but only ISO-8859-1 is required to be supported in every
Java impl.
Bernd
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
Re: svn commit: r531444 - /james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
Posted by Stefano Bagnara <ap...@bago.org>.
Niklas Therning ha scritto:
> Yes, US-ASCII is the default if nothing is specified when parsing to a
> Message object. That's why MessageBuilder uses ISO8859-1 as default
> since it's a 8-bit superset of US-ASCII. If we use US-ASCII it will
> probably break some messages since sometimes 8-bit charsets are used
> even if no charset is specified. Using ISO8859-1 (or some other 8-bit
> encoding) will break those messages less than using US-ASCII in those cases.
Good point.
I'm fine with ISO-8859-1 too (Why not ISO-8859-15, then, so we have euro
working? )
Stefano
> Norman Maurer wrote:
>> Hi Stefano,
>>
>> i reread the rfc and you are right. I think we should use US-ASCII:
>>
>> http://tools.ietf.org/html/rfc2046 :
>>
>>
>> 4.1.2. Charset Parameter
>>
>>
>>
>> A critical parameter that may be specified in the Content-Type field
>> for "text/plain" data is the character set. This is specified with a
>> "charset" parameter, as in:
>>
>> Content-type: text/plain; charset=iso-8859-1
>>
>> Unlike some other parameter values, the values of the charset
>> parameter are NOT case sensitive. The default character set, which
>> must be assumed in the absence of a charset parameter, is US-ASCII.
>>
>>
>> Any thoughts ?
>>
>>
>>
>>
>> Stefano Bagnara schrieb:
>>
>>> Are you sure the problem is that charsetName is null?
>>> Isn't instead this method called with "anychar" ?
>>>
>>> Wouldn't it be better to catch UnsupportedCharsetException and
>>> IllegalCharsetNameException around Charset.forName and simply leave c
>>> as null so that the following if will simply use the already present
>>> default?
>>>
>>> And, at the moment, I would leave the TODO there, because maybe
>>> ISO8859-1 is not the best default for everyone.
>>>
>>> I thought about using:
>>> new InputStreamReader(new ByteArrayInputStream(new byte[0]).getEncoding()
>>> But this would return UTF8 on system having a default file encoding
>>> set to UTF8 and maybe it is not good to parse email as UTF8 when
>>> unspecified.
>>>
>>> Any hint?
>>>
>>> Stefano
>>>
>>> norman@apache.org ha scritto:
>>>
>>>> Author: norman
>>>> Date: Mon Apr 23 05:11:16 2007
>>>> New Revision: 531444
>>>>
>>>> URL: http://svn.apache.org/viewvc?view=rev&rev=531444
>>>> Log:
>>>> Use default charset of ISO8859-1 if charset could not retrived. Thx
>>>> to GX; -)
>>>>
>>>> Modified:
>>>> james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>>>>
>>>> Modified:
>>>> james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>>>> URL:
>>>> http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java?view=diff&rev=531444&r1=531443&r2=531444
>>>>
>>>> ==============================================================================
>>>>
>>>> --- james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>>>> (original)
>>>> +++ james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>>>> Mon Apr 23 05:11:16 2007
>>>> @@ -1119,10 +1119,11 @@
>>>> }
>>>>
>>>> public static java.nio.charset.Charset getCharset(String
>>>> charsetName) {
>>>> + if(charsetName == null) charsetName = "ISO8859-1";
>>>> + java.nio.charset.Charset c =
>>>> java.nio.charset.Charset.forName(charsetName);
>>>> if (c == null) {
>>>> - //TODO: Check what touse as default
>>>> c = java.nio.charset.Charset.forName("ISO8859-1");
>>>> }
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>
>>>>
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>
>>>
>>> !DSPAM:1,462ca850324321917326525!
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-dev-help@james.apache.org
>>
>>
>>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
Re: svn commit: r531444 - /james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
Posted by Norman Maurer <no...@apache.org>.
Hi Niklas,
thx for the explanation :-)
bye
Norman
Niklas Therning schrieb:
> Yes, US-ASCII is the default if nothing is specified when parsing to a
> Message object. That's why MessageBuilder uses ISO8859-1 as default
> since it's a 8-bit superset of US-ASCII. If we use US-ASCII it will
> probably break some messages since sometimes 8-bit charsets are used
> even if no charset is specified. Using ISO8859-1 (or some other 8-bit
> encoding) will break those messages less than using US-ASCII in those cases.
>
> Norman Maurer wrote:
>
>> Hi Stefano,
>>
>> i reread the rfc and you are right. I think we should use US-ASCII:
>>
>> http://tools.ietf.org/html/rfc2046 :
>>
>>
>> 4.1.2. Charset Parameter
>>
>>
>>
>> A critical parameter that may be specified in the Content-Type field
>> for "text/plain" data is the character set. This is specified with a
>> "charset" parameter, as in:
>>
>> Content-type: text/plain; charset=iso-8859-1
>>
>> Unlike some other parameter values, the values of the charset
>> parameter are NOT case sensitive. The default character set, which
>> must be assumed in the absence of a charset parameter, is US-ASCII.
>>
>>
>> Any thoughts ?
>>
>>
>>
>>
>> Stefano Bagnara schrieb:
>>
>>
>>> Are you sure the problem is that charsetName is null?
>>> Isn't instead this method called with "anychar" ?
>>>
>>> Wouldn't it be better to catch UnsupportedCharsetException and
>>> IllegalCharsetNameException around Charset.forName and simply leave c
>>> as null so that the following if will simply use the already present
>>> default?
>>>
>>> And, at the moment, I would leave the TODO there, because maybe
>>> ISO8859-1 is not the best default for everyone.
>>>
>>> I thought about using:
>>> new InputStreamReader(new ByteArrayInputStream(new byte[0]).getEncoding()
>>> But this would return UTF8 on system having a default file encoding
>>> set to UTF8 and maybe it is not good to parse email as UTF8 when
>>> unspecified.
>>>
>>> Any hint?
>>>
>>> Stefano
>>>
>>> norman@apache.org ha scritto:
>>>
>>>
>>>> Author: norman
>>>> Date: Mon Apr 23 05:11:16 2007
>>>> New Revision: 531444
>>>>
>>>> URL: http://svn.apache.org/viewvc?view=rev&rev=531444
>>>> Log:
>>>> Use default charset of ISO8859-1 if charset could not retrived. Thx
>>>> to GX; -)
>>>>
>>>> Modified:
>>>> james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>>>>
>>>> Modified:
>>>> james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>>>> URL:
>>>> http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java?view=diff&rev=531444&r1=531443&r2=531444
>>>>
>>>> ==============================================================================
>>>>
>>>> --- james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>>>> (original)
>>>> +++ james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>>>> Mon Apr 23 05:11:16 2007
>>>> @@ -1119,10 +1119,11 @@
>>>> }
>>>>
>>>> public static java.nio.charset.Charset getCharset(String
>>>> charsetName) {
>>>> + if(charsetName == null) charsetName = "ISO8859-1";
>>>> + java.nio.charset.Charset c =
>>>> java.nio.charset.Charset.forName(charsetName);
>>>> if (c == null) {
>>>> - //TODO: Check what touse as default
>>>> c = java.nio.charset.Charset.forName("ISO8859-1");
>>>> }
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>
>>>>
>>>>
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-dev-help@james.apache.org
>>
>>
>>
>>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
Re: svn commit: r531444 - /james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
Posted by Niklas Therning <ni...@trillian.se>.
Yes, US-ASCII is the default if nothing is specified when parsing to a
Message object. That's why MessageBuilder uses ISO8859-1 as default
since it's a 8-bit superset of US-ASCII. If we use US-ASCII it will
probably break some messages since sometimes 8-bit charsets are used
even if no charset is specified. Using ISO8859-1 (or some other 8-bit
encoding) will break those messages less than using US-ASCII in those cases.
Norman Maurer wrote:
> Hi Stefano,
>
> i reread the rfc and you are right. I think we should use US-ASCII:
>
> http://tools.ietf.org/html/rfc2046 :
>
>
> 4.1.2. Charset Parameter
>
>
>
> A critical parameter that may be specified in the Content-Type field
> for "text/plain" data is the character set. This is specified with a
> "charset" parameter, as in:
>
> Content-type: text/plain; charset=iso-8859-1
>
> Unlike some other parameter values, the values of the charset
> parameter are NOT case sensitive. The default character set, which
> must be assumed in the absence of a charset parameter, is US-ASCII.
>
>
> Any thoughts ?
>
>
>
>
> Stefano Bagnara schrieb:
>
>> Are you sure the problem is that charsetName is null?
>> Isn't instead this method called with "anychar" ?
>>
>> Wouldn't it be better to catch UnsupportedCharsetException and
>> IllegalCharsetNameException around Charset.forName and simply leave c
>> as null so that the following if will simply use the already present
>> default?
>>
>> And, at the moment, I would leave the TODO there, because maybe
>> ISO8859-1 is not the best default for everyone.
>>
>> I thought about using:
>> new InputStreamReader(new ByteArrayInputStream(new byte[0]).getEncoding()
>> But this would return UTF8 on system having a default file encoding
>> set to UTF8 and maybe it is not good to parse email as UTF8 when
>> unspecified.
>>
>> Any hint?
>>
>> Stefano
>>
>> norman@apache.org ha scritto:
>>
>>> Author: norman
>>> Date: Mon Apr 23 05:11:16 2007
>>> New Revision: 531444
>>>
>>> URL: http://svn.apache.org/viewvc?view=rev&rev=531444
>>> Log:
>>> Use default charset of ISO8859-1 if charset could not retrived. Thx
>>> to GX; -)
>>>
>>> Modified:
>>> james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>>>
>>> Modified:
>>> james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>>> URL:
>>> http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java?view=diff&rev=531444&r1=531443&r2=531444
>>>
>>> ==============================================================================
>>>
>>> --- james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>>> (original)
>>> +++ james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>>> Mon Apr 23 05:11:16 2007
>>> @@ -1119,10 +1119,11 @@
>>> }
>>>
>>> public static java.nio.charset.Charset getCharset(String
>>> charsetName) {
>>> + if(charsetName == null) charsetName = "ISO8859-1";
>>> + java.nio.charset.Charset c =
>>> java.nio.charset.Charset.forName(charsetName);
>>> if (c == null) {
>>> - //TODO: Check what touse as default
>>> c = java.nio.charset.Charset.forName("ISO8859-1");
>>> }
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-dev-help@james.apache.org
>>
>>
>> !DSPAM:1,462ca850324321917326525!
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>
>
>
--
Niklas Therning
www.spamdrain.net
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
Re: svn commit: r531444 - /james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
Posted by Stefano Bagnara <ap...@bago.org>.
Norman Maurer ha scritto:
> Hi Stefano,
>
> i reread the rfc and you are right. I think we should use US-ASCII:
>
> http://tools.ietf.org/html/rfc2046 :
>
>
> 4.1.2. Charset Parameter
>
>
>
> A critical parameter that may be specified in the Content-Type field
> for "text/plain" data is the character set. This is specified with a
> "charset" parameter, as in:
>
> Content-type: text/plain; charset=iso-8859-1
>
> Unlike some other parameter values, the values of the charset
> parameter are NOT case sensitive. The default character set, which
> must be assumed in the absence of a charset parameter, is US-ASCII.
>
>
> Any thoughts ?
+1
Currently the callers of this method have NO special management for
IllegalCharsetNameException and UnsupportedCharsetException runtime
exceptions raised by the Charset forName call.
I would probably add a big try/catch for the 2 exceptions and default to
US-ASCII on any exception (or instead of null result).
Maybe logging a warning is also appropriate.
Stefano
> Stefano Bagnara schrieb:
>> Are you sure the problem is that charsetName is null?
>> Isn't instead this method called with "anychar" ?
>>
>> Wouldn't it be better to catch UnsupportedCharsetException and
>> IllegalCharsetNameException around Charset.forName and simply leave c
>> as null so that the following if will simply use the already present
>> default?
>>
>> And, at the moment, I would leave the TODO there, because maybe
>> ISO8859-1 is not the best default for everyone.
>>
>> I thought about using:
>> new InputStreamReader(new ByteArrayInputStream(new byte[0]).getEncoding()
>> But this would return UTF8 on system having a default file encoding
>> set to UTF8 and maybe it is not good to parse email as UTF8 when
>> unspecified.
>>
>> Any hint?
>>
>> Stefano
>>
>> norman@apache.org ha scritto:
>>> Author: norman
>>> Date: Mon Apr 23 05:11:16 2007
>>> New Revision: 531444
>>>
>>> URL: http://svn.apache.org/viewvc?view=rev&rev=531444
>>> Log:
>>> Use default charset of ISO8859-1 if charset could not retrived. Thx
>>> to GX; -)
>>>
>>> Modified:
>>> james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>>>
>>> Modified:
>>> james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>>> URL:
>>> http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java?view=diff&rev=531444&r1=531443&r2=531444
>>>
>>> ==============================================================================
>>>
>>> --- james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>>> (original)
>>> +++ james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>>> Mon Apr 23 05:11:16 2007
>>> @@ -1119,10 +1119,11 @@
>>> }
>>>
>>> public static java.nio.charset.Charset getCharset(String
>>> charsetName) {
>>> + if(charsetName == null) charsetName = "ISO8859-1";
>>> + java.nio.charset.Charset c =
>>> java.nio.charset.Charset.forName(charsetName);
>>> if (c == null) {
>>> - //TODO: Check what touse as default
>>> c = java.nio.charset.Charset.forName("ISO8859-1");
>>> }
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-dev-help@james.apache.org
>>
>>
>> !DSPAM:1,462ca850324321917326525!
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
Re: svn commit: r531444 - /james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
Posted by Norman Maurer <no...@apache.org>.
Hi Stefano,
i reread the rfc and you are right. I think we should use US-ASCII:
http://tools.ietf.org/html/rfc2046 :
4.1.2. Charset Parameter
A critical parameter that may be specified in the Content-Type field
for "text/plain" data is the character set. This is specified with a
"charset" parameter, as in:
Content-type: text/plain; charset=iso-8859-1
Unlike some other parameter values, the values of the charset
parameter are NOT case sensitive. The default character set, which
must be assumed in the absence of a charset parameter, is US-ASCII.
Any thoughts ?
Stefano Bagnara schrieb:
> Are you sure the problem is that charsetName is null?
> Isn't instead this method called with "anychar" ?
>
> Wouldn't it be better to catch UnsupportedCharsetException and
> IllegalCharsetNameException around Charset.forName and simply leave c
> as null so that the following if will simply use the already present
> default?
>
> And, at the moment, I would leave the TODO there, because maybe
> ISO8859-1 is not the best default for everyone.
>
> I thought about using:
> new InputStreamReader(new ByteArrayInputStream(new byte[0]).getEncoding()
> But this would return UTF8 on system having a default file encoding
> set to UTF8 and maybe it is not good to parse email as UTF8 when
> unspecified.
>
> Any hint?
>
> Stefano
>
> norman@apache.org ha scritto:
>> Author: norman
>> Date: Mon Apr 23 05:11:16 2007
>> New Revision: 531444
>>
>> URL: http://svn.apache.org/viewvc?view=rev&rev=531444
>> Log:
>> Use default charset of ISO8859-1 if charset could not retrived. Thx
>> to GX; -)
>>
>> Modified:
>> james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>>
>> Modified:
>> james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>> URL:
>> http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java?view=diff&rev=531444&r1=531443&r2=531444
>>
>> ==============================================================================
>>
>> --- james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>> (original)
>> +++ james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>> Mon Apr 23 05:11:16 2007
>> @@ -1119,10 +1119,11 @@
>> }
>>
>> public static java.nio.charset.Charset getCharset(String
>> charsetName) {
>> + if(charsetName == null) charsetName = "ISO8859-1";
>> + java.nio.charset.Charset c =
>> java.nio.charset.Charset.forName(charsetName);
>> if (c == null) {
>> - //TODO: Check what touse as default
>> c = java.nio.charset.Charset.forName("ISO8859-1");
>> }
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-dev-help@james.apache.org
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>
>
> !DSPAM:1,462ca850324321917326525!
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
Re: svn commit: r531444 - /james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
Posted by Stefano Bagnara <ap...@bago.org>.
Are you sure the problem is that charsetName is null?
Isn't instead this method called with "anychar" ?
Wouldn't it be better to catch UnsupportedCharsetException and
IllegalCharsetNameException around Charset.forName and simply leave c as
null so that the following if will simply use the already present default?
And, at the moment, I would leave the TODO there, because maybe
ISO8859-1 is not the best default for everyone.
I thought about using:
new InputStreamReader(new ByteArrayInputStream(new byte[0]).getEncoding()
But this would return UTF8 on system having a default file encoding set
to UTF8 and maybe it is not good to parse email as UTF8 when unspecified.
Any hint?
Stefano
norman@apache.org ha scritto:
> Author: norman
> Date: Mon Apr 23 05:11:16 2007
> New Revision: 531444
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=531444
> Log:
> Use default charset of ISO8859-1 if charset could not retrived. Thx to GX; -)
>
> Modified:
> james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
>
> Modified: james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java
> URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java?view=diff&rev=531444&r1=531443&r2=531444
> ==============================================================================
> --- james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java (original)
> +++ james/mime4j/trunk/src/main/java/org/mime4j/util/CharsetUtil.java Mon Apr 23 05:11:16 2007
> @@ -1119,10 +1119,11 @@
> }
>
> public static java.nio.charset.Charset getCharset(String charsetName) {
> + if(charsetName == null) charsetName = "ISO8859-1";
> +
> java.nio.charset.Charset c = java.nio.charset.Charset.forName(charsetName);
>
> if (c == null) {
> - //TODO: Check what touse as default
> c = java.nio.charset.Charset.forName("ISO8859-1");
>
> }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org