1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

Correct encoding and decoding for the filename parameter in the Content-Disposition.

This commit is contained in:
Koji Arai 2011-04-07 00:18:14 +09:00
parent 2cadff74b1
commit 79a96952f2
2 changed files with 12 additions and 5 deletions

View File

@ -1121,7 +1121,9 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
*/
bp.addHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, String.format(
"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);
}

View File

@ -16,6 +16,7 @@ import java.util.UUID;
import com.fsck.k9.helper.HtmlConverter;
import org.apache.commons.io.IOUtils;
import org.apache.james.mime4j.codec.EncoderUtil;
import android.app.Application;
import android.content.ContentValues;
@ -1671,16 +1672,20 @@ public class LocalStore extends Store implements Serializable {
if (contentUri != null) {
body = new LocalAttachmentBody(Uri.parse(contentUri), mApplication);
}
String encoded_name = EncoderUtil.encodeIfNecessary(name,
EncoderUtil.Usage.WORD_ENTITY, 7);
MimeBodyPart bp = new LocalAttachmentBodyPart(body, id);
bp.setHeader(MimeHeader.HEADER_CONTENT_TYPE,
String.format("%s;\n name=\"%s\"",
type,
name));
encoded_name));
bp.setHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING, "base64");
bp.setHeader(MimeHeader.HEADER_CONTENT_DISPOSITION,
String.format("%s;\n filename=\"%s\";\n size=%d",
contentDisposition,
name,
encoded_name, // TODO: Should use encoded word defined in RFC 2231.
size));
bp.setHeader(MimeHeader.HEADER_CONTENT_ID, contentId);
@ -2364,7 +2369,7 @@ public class LocalStore extends Store implements Serializable {
Utility.combine(attachment.getHeader(
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 contentDisposition = MimeUtility.unfoldAndDecode(attachment.getDisposition());
@ -2377,7 +2382,7 @@ public class LocalStore extends Store implements Serializable {
}
if (name == null && contentDisposition != null) {
name = MimeUtility.getHeaderParameter(contentDisposition, "filename");
name = MimeUtility.unfoldAndDecode(MimeUtility.getHeaderParameter(contentDisposition, "filename"));
}
if (attachmentId == -1) {
ContentValues cv = new ContentValues();