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

Display attachment size for decrypted parts

This commit is contained in:
cketti 2015-02-01 05:41:40 +01:00
parent 19db6c703b
commit 0241001c63
2 changed files with 22 additions and 9 deletions

View File

@ -26,7 +26,6 @@ import android.content.ContentValues;
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;
@ -66,7 +65,6 @@ 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 static final int MAX_BODY_SIZE_FOR_DATABASE = 16 * 1024;
private static final long INVALID_MESSAGE_PART_ID = -1;
@ -1405,7 +1403,7 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
}
private void missingPartToContentValues(ContentValues cv, Part part) throws MessagingException {
AttachmentViewInfo attachment = LocalMessageExtractor.extractAttachmentInfo(part, PLACEHOLDER_URI);
AttachmentViewInfo attachment = LocalMessageExtractor.extractAttachmentInfo(part);
cv.put("display_name", attachment.displayName);
cv.put("data_location", DataLocation.MISSING);
cv.put("decoded_body_size", attachment.size);
@ -1413,7 +1411,7 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
private File leafPartToContentValues(ContentValues cv, Part part, Body body)
throws MessagingException, IOException {
AttachmentViewInfo attachment = LocalMessageExtractor.extractAttachmentInfo(part, PLACEHOLDER_URI);
AttachmentViewInfo attachment = LocalMessageExtractor.extractAttachmentInfo(part);
cv.put("display_name", attachment.displayName);
String encoding = getTransferEncoding(part);

View File

@ -536,14 +536,19 @@ public class LocalMessageExtractor {
DecryptedTempFileBody decryptedTempFileBody = (DecryptedTempFileBody) body;
File file = decryptedTempFileBody.getFile();
Uri uri = K9FileProvider.getUriForFile(context, file, part.getMimeType());
return extractAttachmentInfo(part, uri);
long size = file.length();
return extractAttachmentInfo(part, uri, size);
} else {
throw new RuntimeException("Not supported");
}
}
}
public static AttachmentViewInfo extractAttachmentInfo(Part part, Uri uri) throws MessagingException {
public static AttachmentViewInfo extractAttachmentInfo(Part part) throws MessagingException {
return extractAttachmentInfo(part, Uri.EMPTY, AttachmentViewInfo.UNKNOWN_SIZE);
}
private static AttachmentViewInfo extractAttachmentInfo(Part part, Uri uri, long size) throws MessagingException {
boolean firstClassAttachment = true;
String mimeType = part.getMimeType();
@ -570,14 +575,24 @@ public class LocalMessageExtractor {
firstClassAttachment = false;
}
long size = AttachmentViewInfo.UNKNOWN_SIZE;
long attachmentSize = extractAttachmentSize(contentDisposition, size);
return new AttachmentViewInfo(mimeType, name, attachmentSize, uri, firstClassAttachment, part);
}
private static long extractAttachmentSize(String contentDisposition, long size) {
if (size != AttachmentViewInfo.UNKNOWN_SIZE) {
return size;
}
long result = AttachmentViewInfo.UNKNOWN_SIZE;
String sizeParam = MimeUtility.getHeaderParameter(contentDisposition, "size");
if (sizeParam != null) {
try {
size = Integer.parseInt(sizeParam);
result = Integer.parseInt(sizeParam);
} catch (NumberFormatException e) { /* ignore */ }
}
return new AttachmentViewInfo(mimeType, name, size, uri, firstClassAttachment, part);
return result;
}
}