james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sharma, Ashish" <ashish.shar...@hp.com>
Subject Mime word not getting decoded using mime4j
Date Tue, 02 Aug 2011 09:12:09 GMT

I am trying to decode mime words (the original string is in Chinese characters) using DecoderUtil.decodeEncodedWords().

Following is the sample code :

	public void testEncoding() throws UnsupportedEncodingException, IOException{		
		String str = "=?gb2312?B?ztKyu8rH1tCH+LmyrmEudHh0?=";
		str = str + "\r\n ";
		str = str + "=?gb2312?B?ztLKx9bQufrIyy50eHQ=?=";
		str = DecoderUtil.decodeEncodedWords(str);		
		File file = new File("C://chinese2.txt");		
		FileOutputStream fileOut = new FileOutputStream(file);

In above code the characters would seem to be corrupted.

Here the problem is with the character set, most of the mail clients set the char sets to
be GB2312, but actually to decode the chars correctly I had to use GB18030 in the above code.
(Refer this for more info: http://stackoverflow.com/questions/3856920/character-corruption-for-chinese-simple-and-traditional-and-korean-texts)

Following is the generalization that I had made to replace character sets sent by mail clients
for correct decoding of characters :

1. For any of following Chinese char set:


	replace it with : GB18030

2. For any of the following Korean char set:


	replace it with :EUC-KR

3. for any of the following Taiwanese char set:


	replace it with : TIS-620

I suggest that in the "DecoderUtil.decodeEncodedWords()" method itself charset fallback should
be provided.

For more info, refer http://wiki.whatwg.org/wiki/Web_Encodings also.

Please reply your comments.

Ashish Sharma

View raw message