0

I have a web-service provider(Java), which imports a .doc file to the NotesDocument. The problem occurs with files with Russian characters in their names - they aren't correctly transferred. For example, if the filename will be equal to Безымянный.doc, it will be transferred as Áåçûìÿííûé.doc.

File directory = new File("C:\\Attachments 1C");
String filename = "Безымянный.doc"
String path = directory + "\\" + filename;
Stream outStream = sess.createStream();
sess.setConvertMIME(true);
MIMEEntity body = newDoc.createMIMEEntity("rtBody");

Stream inStream = sess.createStream();
if (inStream.open(path, "binary")) {
    if (inStream.getBytes() > 0) {
        do {
            byte[] buffer = inStream.read(32767);
            outStream.write(buffer);
        } while (!inStream.isEOS());
        inStream.close();

        MIMEEntity child = body.createChildEntity();

        String fileSuffix = path.substring(path.lastIndexOf(".")+1);

        child.setContentFromBytes(outStream, fileSuffix, MIMEEntity.ENC_IDENTITY_BINARY);

        MIMEHeader header = child.createHeader("Content-Disposition");
        header.setHeaderVal("attachment; filename=\"" + filename + "\"");
        header = child.createHeader("Content-ID");
        header.setHeaderVal(path);
        outStream.truncate();
    }else 
        return "empty file";
}else 
    return "couldn't open the file";

How to fix this?

klendathu
  • 11
  • 2

2 Answers2

0

The standards for this are not quite final and the behavior will depend on what browser is being used. See the question and answers to this previous question on StackOverflow for a detailed explanation and for information about what works with various browsers.

Richard Schwartz
  • 14,463
  • 2
  • 23
  • 41
0

The problem is solved by encoding the filename using MimeUtility(others don't work):

String filenameEndoded = MimeUtility.encodeText(filename,"Cp1251","B");
klendathu
  • 11
  • 2