Search in sources :

Example 1 with Message

use of com.android.voicemail.impl.mail.Message in project android_packages_apps_Dialer by LineageOS.

the class MimeUtility method collectParts.

/**
 * Recursively scan a Part (usually a Message) and sort out which of its children will be
 * "viewable" and which will be attachments.
 *
 * @param part The part to be broken down
 * @param viewables This arraylist will be populated with all parts that appear to be the
 *     "message" (e.g. text/plain & text/html)
 * @param attachments This arraylist will be populated with all parts that appear to be
 *     attachments (including inlines)
 * @throws MessagingException
 */
public static void collectParts(Part part, ArrayList<Part> viewables, ArrayList<Part> attachments) throws MessagingException {
    String disposition = part.getDisposition();
    String dispositionType = MimeUtility.getHeaderParameter(disposition, null);
    // If a disposition is not specified, default to "inline"
    boolean inline = TextUtils.isEmpty(dispositionType) || "inline".equalsIgnoreCase(dispositionType);
    // The lower-case mime type
    String mimeType = part.getMimeType().toLowerCase();
    if (part.getBody() instanceof Multipart) {
        // If the part is Multipart but not alternative it's either mixed or
        // something we don't know about, which means we treat it as mixed
        // per the spec. We just process its pieces recursively.
        MimeMultipart mp = (MimeMultipart) part.getBody();
        boolean foundHtml = false;
        if (mp.getSubTypeForTest().equals("alternative")) {
            for (int i = 0; i < mp.getCount(); i++) {
                if (mp.getBodyPart(i).isMimeType("text/html")) {
                    foundHtml = true;
                    break;
                }
            }
        }
        for (int i = 0; i < mp.getCount(); i++) {
            // See if we have text and html
            BodyPart bp = mp.getBodyPart(i);
            // If there's html, don't bother loading text
            if (foundHtml && bp.isMimeType("text/plain")) {
                continue;
            }
            collectParts(bp, viewables, attachments);
        }
    } else if (part.getBody() instanceof Message) {
        // If the part is an embedded message we just continue to process
        // it, pulling any viewables or attachments into the running list.
        Message message = (Message) part.getBody();
        collectParts(message, viewables, attachments);
    } else if (inline && (mimeType.startsWith("text") || (mimeType.startsWith("image")))) {
        // We'll treat text and images as viewables
        viewables.add(part);
    } else {
        // Everything else is an attachment.
        attachments.add(part);
    }
}
Also used : BodyPart(com.android.voicemail.impl.mail.BodyPart) Multipart(com.android.voicemail.impl.mail.Multipart) Message(com.android.voicemail.impl.mail.Message)

Example 2 with Message

use of com.android.voicemail.impl.mail.Message in project android_packages_apps_Dialer by LineageOS.

the class ImapHelper method fetchVoicemailPayload.

public boolean fetchVoicemailPayload(VoicemailFetchedCallback callback, final String uid) {
    try {
        mFolder = openImapFolder(ImapFolder.MODE_READ_WRITE);
        if (mFolder == null) {
            // This means we were unable to successfully open the folder.
            return false;
        }
        Message message = mFolder.getMessage(uid);
        if (message == null) {
            return false;
        }
        VoicemailPayload voicemailPayload = fetchVoicemailPayload(message);
        callback.setVoicemailContent(voicemailPayload);
        return true;
    } catch (MessagingException e) {
    } finally {
        closeImapFolder();
    }
    return false;
}
Also used : Message(com.android.voicemail.impl.mail.Message) MimeMessage(com.android.voicemail.impl.mail.internet.MimeMessage) MessagingException(com.android.voicemail.impl.mail.MessagingException)

Example 3 with Message

use of com.android.voicemail.impl.mail.Message in project android_packages_apps_Dialer by LineageOS.

the class ImapHelper method fetchAllVoicemails.

/**
 * Fetch a list of voicemails from the server.
 *
 * @return A list of voicemail objects containing data about voicemails stored on the server.
 */
public List<Voicemail> fetchAllVoicemails() {
    List<Voicemail> result = new ArrayList<Voicemail>();
    Message[] messages;
    try {
        mFolder = openImapFolder(ImapFolder.MODE_READ_WRITE);
        if (mFolder == null) {
            // This means we were unable to successfully open the folder.
            return null;
        }
        // This method retrieves lightweight messages containing only the uid of the message.
        messages = mFolder.getMessages(null);
        for (Message message : messages) {
            // Get the voicemail details (message structure).
            MessageStructureWrapper messageStructureWrapper = fetchMessageStructure(message);
            if (messageStructureWrapper != null) {
                result.add(getVoicemailFromMessageStructure(messageStructureWrapper));
            }
        }
        return result;
    } catch (MessagingException e) {
        LogUtils.e(TAG, e, "Messaging Exception");
        return null;
    } finally {
        closeImapFolder();
    }
}
Also used : Message(com.android.voicemail.impl.mail.Message) MimeMessage(com.android.voicemail.impl.mail.internet.MimeMessage) MessagingException(com.android.voicemail.impl.mail.MessagingException) ArrayList(java.util.ArrayList) Voicemail(com.android.voicemail.impl.Voicemail)

Example 4 with Message

use of com.android.voicemail.impl.mail.Message in project android_packages_apps_Dialer by LineageOS.

the class ImapHelper method convertToImapMessages.

private Message[] convertToImapMessages(List<Voicemail> voicemails) {
    Message[] messages = new Message[voicemails.size()];
    for (int i = 0; i < voicemails.size(); ++i) {
        messages[i] = new MimeMessage();
        messages[i].setUid(voicemails.get(i).getSourceData());
    }
    return messages;
}
Also used : Message(com.android.voicemail.impl.mail.Message) MimeMessage(com.android.voicemail.impl.mail.internet.MimeMessage) MimeMessage(com.android.voicemail.impl.mail.internet.MimeMessage)

Example 5 with Message

use of com.android.voicemail.impl.mail.Message in project android_packages_apps_Dialer by LineageOS.

the class ImapStore method joinMessageUids.

/**
 * Returns UIDs of Messages joined with "," as the separator.
 */
static String joinMessageUids(Message[] messages) {
    StringBuilder sb = new StringBuilder();
    boolean notFirst = false;
    for (Message m : messages) {
        if (notFirst) {
            sb.append(',');
        }
        sb.append(m.getUid());
        notFirst = true;
    }
    return sb.toString();
}
Also used : Message(com.android.voicemail.impl.mail.Message) MimeMessage(com.android.voicemail.impl.mail.internet.MimeMessage)

Aggregations

Message (com.android.voicemail.impl.mail.Message)9 MimeMessage (com.android.voicemail.impl.mail.internet.MimeMessage)6 MessagingException (com.android.voicemail.impl.mail.MessagingException)4 Voicemail (com.android.voicemail.impl.Voicemail)2 FetchProfile (com.android.voicemail.impl.mail.FetchProfile)2 ImapMessage (com.android.voicemail.impl.mail.store.ImapStore.ImapMessage)2 ImapString (com.android.voicemail.impl.mail.store.imap.ImapString)2 ArrayList (java.util.ArrayList)2 ArrayMap (android.util.ArrayMap)1 Base64DataException (android.util.Base64DataException)1 AuthenticationFailedException (com.android.voicemail.impl.mail.AuthenticationFailedException)1 BodyPart (com.android.voicemail.impl.mail.BodyPart)1 Multipart (com.android.voicemail.impl.mail.Multipart)1 Part (com.android.voicemail.impl.mail.Part)1 MimeBodyPart (com.android.voicemail.impl.mail.internet.MimeBodyPart)1 ImapException (com.android.voicemail.impl.mail.store.ImapStore.ImapException)1 ImapList (com.android.voicemail.impl.mail.store.imap.ImapList)1 ImapResponse (com.android.voicemail.impl.mail.store.imap.ImapResponse)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1