Search in sources :

Example 1 with AttachmentInfo

use of com.fsck.k9.mailstore.LocalStore.AttachmentInfo in project k-9 by k9mail.

the class AttachmentResolver method buildCidToAttachmentUriMap.

@VisibleForTesting
static Map<String, Uri> buildCidToAttachmentUriMap(AttachmentInfoExtractor attachmentInfoExtractor, Part rootPart) {
    HashMap<String, Uri> result = new HashMap<>();
    Stack<Part> partsToCheck = new Stack<>();
    partsToCheck.push(rootPart);
    while (!partsToCheck.isEmpty()) {
        Part part = partsToCheck.pop();
        Body body = part.getBody();
        if (body instanceof Multipart) {
            Multipart multipart = (Multipart) body;
            for (Part bodyPart : multipart.getBodyParts()) {
                partsToCheck.push(bodyPart);
            }
        } else {
            try {
                String contentId = part.getContentId();
                if (contentId != null) {
                    AttachmentViewInfo attachmentInfo = attachmentInfoExtractor.extractAttachmentInfo(part);
                    result.put(contentId, attachmentInfo.internalUri);
                }
            } catch (MessagingException e) {
                Timber.e(e, "Error extracting attachment info");
            }
        }
    }
    return Collections.unmodifiableMap(result);
}
Also used : Multipart(com.fsck.k9.mail.Multipart) HashMap(java.util.HashMap) MessagingException(com.fsck.k9.mail.MessagingException) Part(com.fsck.k9.mail.Part) Uri(android.net.Uri) Body(com.fsck.k9.mail.Body) Stack(java.util.Stack) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 2 with AttachmentInfo

use of com.fsck.k9.mailstore.LocalStore.AttachmentInfo in project k-9 by k9mail.

the class AttachmentProvider method query.

@Override
public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    String[] columnNames = (projection == null) ? DEFAULT_PROJECTION : projection;
    List<String> segments = uri.getPathSegments();
    String accountUuid = segments.get(0);
    String id = segments.get(1);
    final AttachmentInfo attachmentInfo;
    try {
        final Account account = Preferences.getPreferences(getContext()).getAccount(accountUuid);
        attachmentInfo = LocalStore.getInstance(account, getContext()).getAttachmentInfo(id);
    } catch (MessagingException e) {
        Timber.e(e, "Unable to retrieve attachment info from local store for ID: %s", id);
        return null;
    }
    if (attachmentInfo == null) {
        Timber.d("No attachment info for ID: %s", id);
        return null;
    }
    MatrixCursor ret = new MatrixCursor(columnNames);
    Object[] values = new Object[columnNames.length];
    for (int i = 0, count = columnNames.length; i < count; i++) {
        String column = columnNames[i];
        if (AttachmentProviderColumns._ID.equals(column)) {
            values[i] = id;
        } else if (AttachmentProviderColumns.DATA.equals(column)) {
            values[i] = uri.toString();
        } else if (AttachmentProviderColumns.DISPLAY_NAME.equals(column)) {
            values[i] = attachmentInfo.name;
        } else if (AttachmentProviderColumns.SIZE.equals(column)) {
            values[i] = attachmentInfo.size;
        }
    }
    ret.addRow(values);
    return ret;
}
Also used : Account(com.fsck.k9.Account) MessagingException(com.fsck.k9.mail.MessagingException) AttachmentInfo(com.fsck.k9.mailstore.LocalStore.AttachmentInfo) MatrixCursor(android.database.MatrixCursor)

Example 3 with AttachmentInfo

use of com.fsck.k9.mailstore.LocalStore.AttachmentInfo in project k-9 by k9mail.

the class AttachmentProvider method getType.

private String getType(String accountUuid, String id, String mimeType) {
    String type;
    final Account account = Preferences.getPreferences(getContext()).getAccount(accountUuid);
    try {
        final LocalStore localStore = LocalStore.getInstance(account, getContext());
        AttachmentInfo attachmentInfo = localStore.getAttachmentInfo(id);
        if (mimeType != null) {
            type = mimeType;
        } else {
            type = attachmentInfo.type;
        }
    } catch (MessagingException e) {
        Timber.e(e, "Unable to retrieve LocalStore for %s", account);
        type = MimeUtility.DEFAULT_ATTACHMENT_MIME_TYPE;
    }
    return type;
}
Also used : Account(com.fsck.k9.Account) MessagingException(com.fsck.k9.mail.MessagingException) AttachmentInfo(com.fsck.k9.mailstore.LocalStore.AttachmentInfo) LocalStore(com.fsck.k9.mailstore.LocalStore)

Aggregations

MessagingException (com.fsck.k9.mail.MessagingException)3 Account (com.fsck.k9.Account)2 AttachmentInfo (com.fsck.k9.mailstore.LocalStore.AttachmentInfo)2 MatrixCursor (android.database.MatrixCursor)1 Uri (android.net.Uri)1 VisibleForTesting (android.support.annotation.VisibleForTesting)1 Body (com.fsck.k9.mail.Body)1 Multipart (com.fsck.k9.mail.Multipart)1 Part (com.fsck.k9.mail.Part)1 LocalStore (com.fsck.k9.mailstore.LocalStore)1 HashMap (java.util.HashMap)1 Stack (java.util.Stack)1