mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 11:42:16 -05:00
Store attachment information in LocalBodyPart
This commit is contained in:
parent
ac365567ee
commit
cb94b5b192
@ -7,6 +7,8 @@ import com.fsck.k9.mail.Part;
|
||||
|
||||
|
||||
public class AttachmentViewInfo {
|
||||
public static final long UNKNOWN_SIZE = -1;
|
||||
|
||||
public final String mimeType;
|
||||
public final String displayName;
|
||||
public final long size;
|
||||
|
@ -8,11 +8,18 @@ import com.fsck.k9.mail.internet.MimeBodyPart;
|
||||
public class LocalBodyPart extends MimeBodyPart implements LocalPart {
|
||||
private final String accountUuid;
|
||||
private final long messagePartId;
|
||||
private final String displayName;
|
||||
private final long size;
|
||||
private final boolean firstClassAttachment;
|
||||
|
||||
public LocalBodyPart(String accountUuid, long messagePartId) throws MessagingException {
|
||||
public LocalBodyPart(String accountUuid, long messagePartId, String displayName, long size,
|
||||
boolean firstClassAttachment) throws MessagingException {
|
||||
super();
|
||||
this.accountUuid = accountUuid;
|
||||
this.messagePartId = messagePartId;
|
||||
this.displayName = displayName;
|
||||
this.size = size;
|
||||
this.firstClassAttachment = firstClassAttachment;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -24,4 +31,19 @@ public class LocalBodyPart extends MimeBodyPart implements LocalPart {
|
||||
public long getId() {
|
||||
return messagePartId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFirstClassAttachment() {
|
||||
return firstClassAttachment;
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import com.fsck.k9.Account;
|
||||
@ -42,7 +43,6 @@ import com.fsck.k9.mail.MessageRetrievalListener;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.Multipart;
|
||||
import com.fsck.k9.mail.Part;
|
||||
import com.fsck.k9.mail.internet.MimeBodyPart;
|
||||
import com.fsck.k9.mail.internet.MimeHeader;
|
||||
import com.fsck.k9.mail.internet.MimeMessage;
|
||||
import com.fsck.k9.mail.internet.MimeMultipart;
|
||||
@ -61,6 +61,7 @@ import org.apache.james.mime4j.util.MimeUtil;
|
||||
public class LocalFolder extends Folder<LocalMessage> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -1973296520918624767L;
|
||||
private static final Uri PLACEHOLDER_URI = Uri.EMPTY;
|
||||
|
||||
private final LocalStore localStore;
|
||||
|
||||
@ -669,11 +670,15 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
|
||||
throws MessagingException {
|
||||
|
||||
long id = cursor.getLong(0);
|
||||
int type = cursor.getInt(1);
|
||||
long parentId = cursor.getLong(2);
|
||||
String mimeType = cursor.getString(3);
|
||||
long size = cursor.getLong(4);
|
||||
String displayName = cursor.getString(5);
|
||||
byte[] header = cursor.getBlob(6);
|
||||
int dataLocation = cursor.getInt(9);
|
||||
String serverExtra = cursor.getString(15);
|
||||
boolean firstClassAttachment = (type != MessagePartType.HIDDEN_ATTACHMENT);
|
||||
|
||||
final Part part;
|
||||
if (id == message.getMessagePartId()) {
|
||||
@ -686,7 +691,7 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
|
||||
|
||||
String parentMimeType = parentPart.getMimeType();
|
||||
if (parentMimeType.startsWith("multipart/")) {
|
||||
BodyPart bodyPart = new LocalBodyPart(getAccountUuid(), id);
|
||||
BodyPart bodyPart = new LocalBodyPart(getAccountUuid(), id, displayName, size, firstClassAttachment);
|
||||
((Multipart) parentPart.getBody()).addBodyPart(bodyPart);
|
||||
part = bodyPart;
|
||||
} else if (parentMimeType.startsWith("message/")) {
|
||||
@ -1353,20 +1358,34 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
|
||||
cv.put("preamble", multipart.getPreamble());
|
||||
cv.put("epilogue", multipart.getEpilogue());
|
||||
cv.put("boundary", multipart.getBoundary());
|
||||
} else if (body == null) {
|
||||
} else {
|
||||
AttachmentViewInfo attachment = LocalMessageExtractor.extractAttachmentInfo(part, PLACEHOLDER_URI);
|
||||
|
||||
cv.put("display_name", attachment.displayName);
|
||||
|
||||
if (body == null) {
|
||||
//TODO: deal with missing parts
|
||||
cv.put("data_location", DataLocation.MISSING);
|
||||
cv.put("decoded_body_size", attachment.size);
|
||||
} else {
|
||||
cv.put("data_location", DataLocation.IN_DATABASE);
|
||||
|
||||
byte[] bodyData = getBodyBytes(body);
|
||||
String encoding = getTransferEncoding(part);
|
||||
|
||||
if (attachment.size == AttachmentViewInfo.UNKNOWN_SIZE) {
|
||||
//FIXME: Use size of content when transfer encoding is stripped
|
||||
cv.put("decoded_body_size", bodyData.length);
|
||||
} else {
|
||||
cv.put("decoded_body_size", attachment.size);
|
||||
}
|
||||
|
||||
cv.put("encoding", encoding);
|
||||
cv.put("data", bodyData);
|
||||
cv.put("content_id", part.getContentId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] getHeaderBytes(Part part) throws IOException, MessagingException {
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
@ -1941,6 +1960,7 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
|
||||
static final int TEXT = 3;
|
||||
static final int RELATED = 4;
|
||||
static final int ATTACHMENT = 5;
|
||||
static final int HIDDEN_ATTACHMENT = 6;
|
||||
}
|
||||
|
||||
// Note: The contents of the 'message_parts' table depend on these values.
|
||||
|
@ -462,6 +462,23 @@ public class LocalMessageExtractor {
|
||||
}
|
||||
|
||||
private static AttachmentViewInfo extractAttachmentInfo(Part part) throws MessagingException {
|
||||
if (part instanceof LocalPart) {
|
||||
LocalPart localPart = (LocalPart) part;
|
||||
String accountUuid = localPart.getAccountUuid();
|
||||
long messagePartId = localPart.getId();
|
||||
String mimeType = part.getMimeType();
|
||||
String displayName = localPart.getDisplayName();
|
||||
long size = localPart.getSize();
|
||||
boolean firstClassAttachment = localPart.isFirstClassAttachment();
|
||||
Uri uri = AttachmentProvider.getAttachmentUri(accountUuid, messagePartId);
|
||||
|
||||
return new AttachmentViewInfo(mimeType, displayName, size, uri, firstClassAttachment, part);
|
||||
} else {
|
||||
throw new IllegalStateException("Not supported yet");
|
||||
}
|
||||
}
|
||||
|
||||
public static AttachmentViewInfo extractAttachmentInfo(Part part, Uri uri) throws MessagingException {
|
||||
boolean firstClassAttachment = true;
|
||||
|
||||
String mimeType = part.getMimeType();
|
||||
@ -488,7 +505,7 @@ public class LocalMessageExtractor {
|
||||
firstClassAttachment = false;
|
||||
}
|
||||
|
||||
long size = 0;
|
||||
long size = AttachmentViewInfo.UNKNOWN_SIZE;
|
||||
String sizeParam = MimeUtility.getHeaderParameter(contentDisposition, "size");
|
||||
if (sizeParam != null) {
|
||||
try {
|
||||
@ -496,11 +513,6 @@ public class LocalMessageExtractor {
|
||||
} catch (NumberFormatException e) { /* ignore */ }
|
||||
}
|
||||
|
||||
LocalPart localPart = (LocalPart) part;
|
||||
String accountUuid = localPart.getAccountUuid();
|
||||
long messagePartId = localPart.getId();
|
||||
Uri uri = AttachmentProvider.getAttachmentUri(accountUuid, messagePartId);
|
||||
|
||||
return new AttachmentViewInfo(mimeType, name, size, uri, firstClassAttachment, part);
|
||||
}
|
||||
}
|
||||
|
@ -4,4 +4,7 @@ package com.fsck.k9.mailstore;
|
||||
public interface LocalPart {
|
||||
String getAccountUuid();
|
||||
long getId();
|
||||
String getDisplayName();
|
||||
long getSize();
|
||||
boolean isFirstClassAttachment();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user