We have an issue w/ character encoding that we’re hoping someone can help us with!
The issue is w/ the character encoding that Notes uses when it gets the content from a MIME entity. Some data comes in corrupted since we think we aren’t correctly handling encoding. So for example, here’s some text w/ high-register chars (e.g., “smart quotes”):
‘using the “File Manager” application’
While after we programmatically get this data using MIME, this gets corrupted to:
‘using the “File Manager” application.’
There’s little doc on this and we’ve tried different combinations of methods and parameters.
Here’s a code snippet to help explain the issue:
1 Stream stream = null;
2 try {
3 stream = session.createStream();
4 }
5 catch (NotesException ex1) {
6 // logs an error
7 return;
8 }
9 File file = new File(dirDoc, strFileName);
10 String strPath = file.getAbsolutePath();
11 try {
12 String strContentSubTypeChild = mimeChild.getContentSubType();
13 String strCharset = mimeChild.getCharset();
14 if(strContentSubTypeChild.equals(strCONTENTSUBTYPE_HTML)) {
15 if (stream.open(strPath, strCharset)) {
16 mimeChild.getContentAsBytes(stream, false);
17 stream.close();
18 }
19 }
20 else {
21 if (stream.open(strPath, “binary”)) {
22 mimeChild.getContentAsBytes(stream);
23 stream.close();
24 }
25 }
26 }
On lines 16 and 22 we’re getting the content as bytes from the MIMEEntity object. Line 15 opens the file using a specific character set, the stream.open method has the signature:
public boolean open(String pathname, String charset)
throws NotesException
We’ve tried different character sets and using the MIMEEntity method getContentAsText. Both getContentAsBytes() and getContentAsText() have the signature:
public void getContentAsText(Stream stream, boolean decoded)
throws NotesException
where decoded is specified as: Specify true (default) to decode the content, false to leave any encoding in place.
We get the MIMEEntity object using NotesItem.getMIMEEntity() and then loop through the children using MIMEEntity.getFirstChildEntity() and getNextMIMEEntity(). None of these methods allow specifying a charset. However, I just saw the method MIMEEntity.getEncoding(). But I dunno how would I use this encoding info. Is it useful when specifying the charset of the file when calling Stream.open(strFilePath, strCharSet)?
Any light on this would be greatly appreciated.
Thanks for your help!
-Pete