[API] Fix downloading attachments with different name. Handle UTF encoded download names.

This commit is contained in:
Kuba Szczodrzyński
2020-04-07 13:57:12 +02:00
parent d56afb034b
commit 00a90a14dc
3 changed files with 24 additions and 4 deletions

View File

@ -6,6 +6,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLDecoder;
import im.wangchao.mhttp.AbsCallbackHandler;
import im.wangchao.mhttp.Accept;
@ -69,7 +70,11 @@ public class FileCallbackHandler extends AbsCallbackHandler<File> {
if (this.file.isDirectory()) {
String contentDisposition = response.header("content-disposition");
if (contentDisposition != null) {
String filename = contentDisposition.substring(contentDisposition.indexOf("\"")+1, contentDisposition.lastIndexOf("\""));
if (contentDisposition.contains("*=UTF-8")) {
contentDisposition = contentDisposition.replace("*=UTF-8''", "\"") + "\"";
contentDisposition = URLDecoder.decode(contentDisposition, "UTF-8");
}
String filename = contentDisposition.substring(contentDisposition.indexOf("\"") + 1, contentDisposition.lastIndexOf("\""));
this.file = new File(file, filename);
file = this.file;
}