mirror of
https://github.com/moparisthebest/k-9
synced 2025-02-25 07:01:50 -05:00
Correct encoding and decoding for the filename parameter in the Content-Disposition.
This commit is contained in:
parent
2cadff74b1
commit
79a96952f2
@ -1121,7 +1121,9 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
|||||||
*/
|
*/
|
||||||
bp.addHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, String.format(
|
bp.addHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, String.format(
|
||||||
"attachment;\n filename=\"%s\";\n size=%d",
|
"attachment;\n filename=\"%s\";\n size=%d",
|
||||||
attachment.name, attachment.size));
|
EncoderUtil.encodeIfNecessary(attachment.name,
|
||||||
|
EncoderUtil.Usage.WORD_ENTITY, 7),
|
||||||
|
attachment.size));
|
||||||
|
|
||||||
mp.addBodyPart(bp);
|
mp.addBodyPart(bp);
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import com.fsck.k9.helper.HtmlConverter;
|
import com.fsck.k9.helper.HtmlConverter;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.james.mime4j.codec.EncoderUtil;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
@ -1671,16 +1672,20 @@ public class LocalStore extends Store implements Serializable {
|
|||||||
if (contentUri != null) {
|
if (contentUri != null) {
|
||||||
body = new LocalAttachmentBody(Uri.parse(contentUri), mApplication);
|
body = new LocalAttachmentBody(Uri.parse(contentUri), mApplication);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String encoded_name = EncoderUtil.encodeIfNecessary(name,
|
||||||
|
EncoderUtil.Usage.WORD_ENTITY, 7);
|
||||||
|
|
||||||
MimeBodyPart bp = new LocalAttachmentBodyPart(body, id);
|
MimeBodyPart bp = new LocalAttachmentBodyPart(body, id);
|
||||||
bp.setHeader(MimeHeader.HEADER_CONTENT_TYPE,
|
bp.setHeader(MimeHeader.HEADER_CONTENT_TYPE,
|
||||||
String.format("%s;\n name=\"%s\"",
|
String.format("%s;\n name=\"%s\"",
|
||||||
type,
|
type,
|
||||||
name));
|
encoded_name));
|
||||||
bp.setHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING, "base64");
|
bp.setHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING, "base64");
|
||||||
bp.setHeader(MimeHeader.HEADER_CONTENT_DISPOSITION,
|
bp.setHeader(MimeHeader.HEADER_CONTENT_DISPOSITION,
|
||||||
String.format("%s;\n filename=\"%s\";\n size=%d",
|
String.format("%s;\n filename=\"%s\";\n size=%d",
|
||||||
contentDisposition,
|
contentDisposition,
|
||||||
name,
|
encoded_name, // TODO: Should use encoded word defined in RFC 2231.
|
||||||
size));
|
size));
|
||||||
|
|
||||||
bp.setHeader(MimeHeader.HEADER_CONTENT_ID, contentId);
|
bp.setHeader(MimeHeader.HEADER_CONTENT_ID, contentId);
|
||||||
@ -2364,7 +2369,7 @@ public class LocalStore extends Store implements Serializable {
|
|||||||
Utility.combine(attachment.getHeader(
|
Utility.combine(attachment.getHeader(
|
||||||
MimeHeader.HEADER_ANDROID_ATTACHMENT_STORE_DATA), ',');
|
MimeHeader.HEADER_ANDROID_ATTACHMENT_STORE_DATA), ',');
|
||||||
|
|
||||||
String name = MimeUtility.getHeaderParameter(attachment.getContentType(), "name");
|
String name = MimeUtility.unfoldAndDecode(MimeUtility.getHeaderParameter(attachment.getContentType(), "name"));
|
||||||
String contentId = MimeUtility.getHeaderParameter(attachment.getContentId(), null);
|
String contentId = MimeUtility.getHeaderParameter(attachment.getContentId(), null);
|
||||||
|
|
||||||
String contentDisposition = MimeUtility.unfoldAndDecode(attachment.getDisposition());
|
String contentDisposition = MimeUtility.unfoldAndDecode(attachment.getDisposition());
|
||||||
@ -2377,7 +2382,7 @@ public class LocalStore extends Store implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (name == null && contentDisposition != null) {
|
if (name == null && contentDisposition != null) {
|
||||||
name = MimeUtility.getHeaderParameter(contentDisposition, "filename");
|
name = MimeUtility.unfoldAndDecode(MimeUtility.getHeaderParameter(contentDisposition, "filename"));
|
||||||
}
|
}
|
||||||
if (attachmentId == -1) {
|
if (attachmentId == -1) {
|
||||||
ContentValues cv = new ContentValues();
|
ContentValues cv = new ContentValues();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user