Search in sources :

Example 1 with FetchProfile

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

the class ImapHelper method fetchVoicemailPayload.

/**
 * Fetches the body of the given message and returns the parsed voicemail payload.
 *
 * @throws MessagingException if fetching the body of the message fails
 */
private VoicemailPayload fetchVoicemailPayload(Message message) throws MessagingException {
    LogUtils.d(TAG, "Fetching message body for " + message.getUid());
    MessageBodyFetchedListener listener = new MessageBodyFetchedListener();
    FetchProfile fetchProfile = new FetchProfile();
    fetchProfile.add(FetchProfile.Item.BODY);
    mFolder.fetch(new Message[] { message }, fetchProfile, listener);
    return listener.getVoicemailPayload();
}
Also used : FetchProfile(com.android.voicemail.impl.mail.FetchProfile)

Example 2 with FetchProfile

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

the class ImapHelper method fetchMessageStructure.

/**
 * Fetches the structure of the given message and returns a wrapper containing the message
 * structure and the transcription structure (if applicable).
 *
 * @throws MessagingException if fetching the structure of the message fails
 */
private MessageStructureWrapper fetchMessageStructure(Message message) throws MessagingException {
    LogUtils.d(TAG, "Fetching message structure for " + message.getUid());
    MessageStructureFetchedListener listener = new MessageStructureFetchedListener();
    FetchProfile fetchProfile = new FetchProfile();
    fetchProfile.addAll(Arrays.asList(FetchProfile.Item.FLAGS, FetchProfile.Item.ENVELOPE, FetchProfile.Item.STRUCTURE));
    // The IMAP folder fetch method will call "messageRetrieved" on the listener when the
    // message is successfully retrieved.
    mFolder.fetch(new Message[] { message }, fetchProfile, listener);
    return listener.getMessageStructure();
}
Also used : FetchProfile(com.android.voicemail.impl.mail.FetchProfile)

Example 3 with FetchProfile

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

the class ImapHelper method getVoicemailFromMessageStructure.

/**
 * Extract voicemail details from the message structure. Also fetch transcription if a
 * transcription exists.
 */
private Voicemail getVoicemailFromMessageStructure(MessageStructureWrapper messageStructureWrapper) throws MessagingException {
    Message messageDetails = messageStructureWrapper.messageStructure;
    TranscriptionFetchedListener listener = new TranscriptionFetchedListener();
    if (messageStructureWrapper.transcriptionBodyPart != null) {
        FetchProfile fetchProfile = new FetchProfile();
        fetchProfile.add(messageStructureWrapper.transcriptionBodyPart);
        mFolder.fetch(new Message[] { messageDetails }, fetchProfile, listener);
    }
    // Found an audio attachment, this is a valid voicemail.
    long time = messageDetails.getSentDate().getTime();
    String number = getNumber(messageDetails.getFrom());
    boolean isRead = Arrays.asList(messageDetails.getFlags()).contains(Flag.SEEN);
    Long duration = messageDetails.getDuration();
    Voicemail.Builder builder = Voicemail.createForInsertion(time, number).setPhoneAccount(mPhoneAccount).setSourcePackage(mContext.getPackageName()).setSourceData(messageDetails.getUid()).setIsRead(isRead).setTranscription(listener.getVoicemailTranscription());
    if (duration != null) {
        builder.setDuration(duration);
    }
    return builder.build();
}
Also used : FetchProfile(com.android.voicemail.impl.mail.FetchProfile) Message(com.android.voicemail.impl.mail.Message) MimeMessage(com.android.voicemail.impl.mail.internet.MimeMessage) Voicemail(com.android.voicemail.impl.Voicemail)

Example 4 with FetchProfile

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

the class ImapHelper method fetchTranscription.

public boolean fetchTranscription(TranscriptionFetchedCallback callback, 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;
        }
        MessageStructureWrapper messageStructureWrapper = fetchMessageStructure(message);
        if (messageStructureWrapper != null) {
            TranscriptionFetchedListener listener = new TranscriptionFetchedListener();
            if (messageStructureWrapper.transcriptionBodyPart != null) {
                FetchProfile fetchProfile = new FetchProfile();
                fetchProfile.add(messageStructureWrapper.transcriptionBodyPart);
                // This method is called synchronously so the transcription will be populated
                // in the listener once the next method is called.
                mFolder.fetch(new Message[] { message }, fetchProfile, listener);
                callback.setVoicemailTranscription(listener.getVoicemailTranscription());
            }
        }
        return true;
    } catch (MessagingException e) {
        LogUtils.e(TAG, e, "Messaging Exception");
        return false;
    } finally {
        closeImapFolder();
    }
}
Also used : FetchProfile(com.android.voicemail.impl.mail.FetchProfile) Message(com.android.voicemail.impl.mail.Message) MimeMessage(com.android.voicemail.impl.mail.internet.MimeMessage) MessagingException(com.android.voicemail.impl.mail.MessagingException)

Aggregations

FetchProfile (com.android.voicemail.impl.mail.FetchProfile)4 Message (com.android.voicemail.impl.mail.Message)2 MimeMessage (com.android.voicemail.impl.mail.internet.MimeMessage)2 Voicemail (com.android.voicemail.impl.Voicemail)1 MessagingException (com.android.voicemail.impl.mail.MessagingException)1