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);
}
}
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;
}
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();
}
}
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;
}
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();
}
Aggregations