Search in sources :

Example 1 with Part

use of com.fsck.k9.mail.Part in project k-9 by k9mail.

the class MessageDecryptVerifier method getSignatureData.

public static byte[] getSignatureData(Part part) throws IOException, MessagingException {
    if (isPartMultipartSigned(part)) {
        Body body = part.getBody();
        if (body instanceof Multipart) {
            Multipart multi = (Multipart) body;
            BodyPart signatureBody = multi.getBodyPart(1);
            if (isSameMimeType(signatureBody.getMimeType(), APPLICATION_PGP_SIGNATURE)) {
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                signatureBody.getBody().writeTo(bos);
                return bos.toByteArray();
            }
        }
    }
    return null;
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Multipart(com.fsck.k9.mail.Multipart) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Body(com.fsck.k9.mail.Body)

Example 2 with Part

use of com.fsck.k9.mail.Part in project k-9 by k9mail.

the class MessageDecryptVerifier method findPgpInlineParts.

public static List<Part> findPgpInlineParts(Part startPart) {
    List<Part> inlineParts = new ArrayList<>();
    Stack<Part> partsToCheck = new Stack<>();
    partsToCheck.push(startPart);
    while (!partsToCheck.isEmpty()) {
        Part part = partsToCheck.pop();
        Body body = part.getBody();
        if (isPartPgpInlineEncryptedOrSigned(part)) {
            inlineParts.add(part);
            continue;
        }
        if (body instanceof Multipart) {
            Multipart multipart = (Multipart) body;
            for (int i = multipart.getCount() - 1; i >= 0; i--) {
                BodyPart bodyPart = multipart.getBodyPart(i);
                partsToCheck.push(bodyPart);
            }
        }
    }
    return inlineParts;
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Multipart(com.fsck.k9.mail.Multipart) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) ArrayList(java.util.ArrayList) Body(com.fsck.k9.mail.Body) Stack(java.util.Stack)

Example 3 with Part

use of com.fsck.k9.mail.Part in project k-9 by k9mail.

the class MessageDecryptVerifier method findPrimaryPartInAlternative.

private static Part findPrimaryPartInAlternative(Part part) {
    Body body = part.getBody();
    if (part.isMimeType("multipart/alternative") && body instanceof Multipart) {
        Multipart multipart = (Multipart) body;
        if (multipart.getCount() == 0) {
            return null;
        }
        BodyPart firstBodyPart = multipart.getBodyPart(0);
        if (isPartPgpInlineEncryptedOrSigned(firstBodyPart)) {
            return firstBodyPart;
        }
    }
    return null;
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Multipart(com.fsck.k9.mail.Multipart) Body(com.fsck.k9.mail.Body)

Example 4 with Part

use of com.fsck.k9.mail.Part in project k-9 by k9mail.

the class MessageListAdapter method newView.

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    View view = fragment.getLayoutInflater().inflate(R.layout.message_list_item, parent, false);
    MessageViewHolder holder = new MessageViewHolder(fragment);
    holder.date = (TextView) view.findViewById(R.id.date);
    holder.chip = view.findViewById(R.id.chip);
    if (fragment.previewLines == 0 && fragment.contactsPictureLoader == null) {
        view.findViewById(R.id.preview).setVisibility(View.GONE);
        holder.preview = (TextView) view.findViewById(R.id.sender_compact);
        holder.flagged = (CheckBox) view.findViewById(R.id.flagged_center_right);
        view.findViewById(R.id.flagged_bottom_right).setVisibility(View.GONE);
    } else {
        view.findViewById(R.id.sender_compact).setVisibility(View.GONE);
        holder.preview = (TextView) view.findViewById(R.id.preview);
        holder.flagged = (CheckBox) view.findViewById(R.id.flagged_bottom_right);
        view.findViewById(R.id.flagged_center_right).setVisibility(View.GONE);
    }
    ContactBadge contactBadge = (ContactBadge) view.findViewById(R.id.contact_badge);
    if (fragment.contactsPictureLoader != null) {
        holder.contactBadge = contactBadge;
    } else {
        contactBadge.setVisibility(View.GONE);
    }
    if (fragment.senderAboveSubject) {
        holder.from = (TextView) view.findViewById(R.id.subject);
        fontSizes.setViewTextSize(holder.from, fontSizes.getMessageListSender());
    } else {
        holder.subject = (TextView) view.findViewById(R.id.subject);
        fontSizes.setViewTextSize(holder.subject, fontSizes.getMessageListSubject());
    }
    fontSizes.setViewTextSize(holder.date, fontSizes.getMessageListDate());
    // 1 preview line is needed even if it is set to 0, because subject is part of the same text view
    holder.preview.setLines(Math.max(fragment.previewLines, 1));
    fontSizes.setViewTextSize(holder.preview, fontSizes.getMessageListPreview());
    holder.threadCount = (TextView) view.findViewById(R.id.thread_count);
    // thread count is next to subject
    fontSizes.setViewTextSize(holder.threadCount, fontSizes.getMessageListSubject());
    view.findViewById(R.id.selected_checkbox_wrapper).setVisibility((fragment.checkboxes) ? View.VISIBLE : View.GONE);
    holder.flagged.setVisibility(fragment.stars ? View.VISIBLE : View.GONE);
    holder.flagged.setOnClickListener(holder);
    holder.selected = (CheckBox) view.findViewById(R.id.selected_checkbox);
    holder.selected.setOnClickListener(holder);
    view.setTag(holder);
    return view;
}
Also used : ContactBadge(com.fsck.k9.ui.ContactBadge) View(android.view.View) TextView(android.widget.TextView)

Example 5 with Part

use of com.fsck.k9.mail.Part in project k-9 by k9mail.

the class MessagingController method setFlag.

/**
     * Set or remove a flag for a set of messages in a specific folder.
     * <p>
     * <p>
     * The {@link Message} objects passed in are updated to reflect the new flag state.
     * </p>
     *
     * @param account
     *         The account the folder containing the messages belongs to.
     * @param folderName
     *         The name of the folder.
     * @param messages
     *         The messages to change the flag for.
     * @param flag
     *         The flag to change.
     * @param newState
     *         {@code true}, if the flag should be set. {@code false} if it should be removed.
     */
public void setFlag(Account account, String folderName, List<? extends Message> messages, Flag flag, boolean newState) {
    // TODO: Put this into the background, but right now some callers depend on the message
    //       objects being modified right after this method returns.
    Folder localFolder = null;
    try {
        Store localStore = account.getLocalStore();
        localFolder = localStore.getFolder(folderName);
        localFolder.open(Folder.OPEN_MODE_RW);
        // Allows for re-allowing sending of messages that could not be sent
        if (flag == Flag.FLAGGED && !newState && account.getOutboxFolderName().equals(folderName)) {
            for (Message message : messages) {
                String uid = message.getUid();
                if (uid != null) {
                    sendCount.remove(uid);
                }
            }
        }
        // Update the messages in the local store
        localFolder.setFlags(messages, Collections.singleton(flag), newState);
        int unreadMessageCount = localFolder.getUnreadMessageCount();
        for (MessagingListener l : getListeners()) {
            l.folderStatusChanged(account, folderName, unreadMessageCount);
        }
        // TODO: Skip the remote part for all local-only folders
        if (account.getErrorFolderName().equals(folderName)) {
            return;
        }
        List<String> uids = getUidsFromMessages(messages);
        queueSetFlag(account, folderName, newState, flag, uids);
        processPendingCommands(account);
    } catch (MessagingException me) {
        addErrorMessage(account, null, me);
        throw new RuntimeException(me);
    } finally {
        closeFolder(localFolder);
    }
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) MessagingException(com.fsck.k9.mail.MessagingException) LocalStore(com.fsck.k9.mailstore.LocalStore) Store(com.fsck.k9.mail.Store) Pop3Store(com.fsck.k9.mail.store.pop3.Pop3Store) Folder(com.fsck.k9.mail.Folder) LocalFolder(com.fsck.k9.mailstore.LocalFolder) SuppressLint(android.annotation.SuppressLint)

Aggregations

Part (com.fsck.k9.mail.Part)113 Test (org.junit.Test)92 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)78 BodyPart (com.fsck.k9.mail.BodyPart)73 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)39 Message (com.fsck.k9.mail.Message)32 MessageCreationHelper.createTextPart (com.fsck.k9.message.MessageCreationHelper.createTextPart)30 Body (com.fsck.k9.mail.Body)29 Multipart (com.fsck.k9.mail.Multipart)27 ArrayList (java.util.ArrayList)27 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)20 MessageCreationHelper.createEmptyPart (com.fsck.k9.message.MessageCreationHelper.createEmptyPart)19 MessagingException (com.fsck.k9.mail.MessagingException)16 MessageCreationHelper.createPart (com.fsck.k9.message.MessageCreationHelper.createPart)16 TextBody (com.fsck.k9.mail.internet.TextBody)14 AttachmentViewInfo (com.fsck.k9.mailstore.AttachmentViewInfo)13 Viewable (com.fsck.k9.mail.internet.Viewable)10 Uri (android.net.Uri)8 BinaryTempFileBody (com.fsck.k9.mail.internet.BinaryTempFileBody)6 BinaryMemoryBody (com.fsck.k9.mailstore.BinaryMemoryBody)6