use of com.fsck.k9.mail.MessagingException in project k-9 by k9mail.
the class MessagingControllerTest method refreshRemoteSynchronous_shouldNotDeleteSpecialFoldersNotOnRemote.
@Test
public void refreshRemoteSynchronous_shouldNotDeleteSpecialFoldersNotOnRemote() throws MessagingException {
configureRemoteStoreWithFolder();
LocalFolder missingSpecialFolder = mock(LocalFolder.class);
when(account.isSpecialFolder("Outbox")).thenReturn(true);
when(missingSpecialFolder.getName()).thenReturn("Outbox");
when(localStore.getPersonalNamespaces(false)).thenReturn(Collections.singletonList(missingSpecialFolder));
List<Folder> folders = Collections.emptyList();
when(remoteStore.getPersonalNamespaces(false)).thenAnswer(createAnswer(folders));
controller.refreshRemoteSynchronous(account, listener);
verify(missingSpecialFolder, never()).delete(false);
}
use of com.fsck.k9.mail.MessagingException in project sms-backup-plus by jberkel.
the class MessageConverter method messageToContentValues.
@NonNull
public ContentValues messageToContentValues(final Message message) throws IOException, MessagingException {
if (message == null)
throw new MessagingException("message is null");
final ContentValues values = new ContentValues();
switch(getDataType(message)) {
case SMS:
if (message.getBody() == null)
throw new MessagingException("body is null");
InputStream is = MimeUtility.decodeBody(message.getBody());
if (is == null) {
throw new MessagingException("body.getInputStream() is null for " + message.getBody());
}
final String body = IOUtils.toString(is);
final String address = Headers.get(message, Headers.ADDRESS);
values.put(Telephony.TextBasedSmsColumns.BODY, body);
values.put(Telephony.TextBasedSmsColumns.ADDRESS, address);
values.put(Telephony.TextBasedSmsColumns.TYPE, Headers.get(message, Headers.TYPE));
values.put(Telephony.TextBasedSmsColumns.PROTOCOL, Headers.get(message, Headers.PROTOCOL));
values.put(Telephony.TextBasedSmsColumns.SERVICE_CENTER, Headers.get(message, Headers.SERVICE_CENTER));
values.put(Telephony.TextBasedSmsColumns.DATE, Headers.get(message, Headers.DATE));
values.put(Telephony.TextBasedSmsColumns.STATUS, Headers.get(message, Headers.STATUS));
values.put(Telephony.TextBasedSmsColumns.THREAD_ID, threadHelper.getThreadId(mContext, address));
values.put(Telephony.TextBasedSmsColumns.READ, mMarkAsReadOnRestore ? "1" : Headers.get(message, Headers.READ));
break;
case CALLLOG:
values.put(CallLog.Calls.NUMBER, Headers.get(message, Headers.ADDRESS));
values.put(CallLog.Calls.TYPE, Integer.valueOf(Headers.get(message, Headers.TYPE)));
values.put(CallLog.Calls.DATE, Headers.get(message, Headers.DATE));
values.put(CallLog.Calls.DURATION, Long.valueOf(Headers.get(message, Headers.DURATION)));
values.put(CallLog.Calls.NEW, 0);
PersonRecord record = mPersonLookup.lookupPerson(Headers.get(message, Headers.ADDRESS));
if (!record.isUnknown()) {
values.put(CallLog.Calls.CACHED_NAME, record.getName());
values.put(CallLog.Calls.CACHED_NUMBER_TYPE, -2);
}
break;
default:
throw new MessagingException("don't know how to restore " + getDataType(message));
}
return values;
}
use of com.fsck.k9.mail.MessagingException in project sms-backup-plus by jberkel.
the class MessageConverter method convertMessages.
@NonNull
public ConversionResult convertMessages(final Cursor cursor, DataType dataType) throws MessagingException {
final Map<String, String> msgMap = getMessageMap(cursor);
final Message m = mMessageGenerator.messageForDataType(msgMap, dataType);
final ConversionResult result = new ConversionResult(dataType);
if (m != null) {
m.setFlag(Flag.SEEN, markAsSeen(dataType, msgMap));
result.add(m, msgMap);
}
return result;
}
use of com.fsck.k9.mail.MessagingException in project sms-backup-plus by jberkel.
the class MessageGenerator method messageFromMapSms.
@Nullable
private Message messageFromMapSms(Map<String, String> msgMap) throws MessagingException {
final String address = msgMap.get(Telephony.TextBasedSmsColumns.ADDRESS);
if (TextUtils.isEmpty(address))
return null;
PersonRecord record = personLookup.lookupPerson(address);
if (!includePersonInBackup(record, DataType.SMS))
return null;
final Message msg = new MimeMessage();
msg.setSubject(getSubject(DataType.SMS, record));
setBody(msg, new TextBody(msgMap.get(Telephony.TextBasedSmsColumns.BODY)));
final int messageType = toInt(msgMap.get(Telephony.TextBasedSmsColumns.TYPE));
if (Telephony.TextBasedSmsColumns.MESSAGE_TYPE_INBOX == messageType) {
// Received message
msg.setFrom(record.getAddress(addressStyle));
msg.setRecipient(Message.RecipientType.TO, userAddress);
} else {
// Sent message
msg.setRecipient(Message.RecipientType.TO, record.getAddress(addressStyle));
msg.setFrom(userAddress);
}
Date sentDate;
try {
// TODO: should probably be TextBasedSmsColumns.DATE_SENT
sentDate = new Date(Long.valueOf(msgMap.get(Telephony.TextBasedSmsColumns.DATE)));
} catch (NumberFormatException n) {
Log.e(TAG, ERROR_PARSING_DATE, n);
sentDate = new Date();
}
headerGenerator.setHeaders(msg, msgMap, DataType.SMS, address, record, sentDate, messageType);
return msg;
}
use of com.fsck.k9.mail.MessagingException in project sms-backup-plus by jberkel.
the class MessageGenerator method messageFromMapMms.
@Nullable
private Message messageFromMapMms(Map<String, String> msgMap) throws MessagingException {
if (LOCAL_LOGV)
Log.v(TAG, "messageFromMapMms(" + msgMap + ")");
final Uri mmsUri = Uri.withAppendedPath(Consts.MMS_PROVIDER, msgMap.get(Telephony.BaseMmsColumns._ID));
MmsSupport.MmsDetails details = mmsSupport.getDetails(mmsUri, addressStyle);
if (details.isEmpty()) {
Log.w(TAG, "no recipients found");
return null;
} else if (!includeInBackup(DataType.MMS, details.records)) {
Log.w(TAG, "no recipients included");
return null;
}
final Message msg = new MimeMessage();
msg.setSubject(getSubject(DataType.MMS, details.getRecipient()));
if (details.inbound) {
// msg_box == MmsConsts.MESSAGE_BOX_INBOX does not work
msg.setFrom(details.getRecipientAddress());
msg.setRecipient(Message.RecipientType.TO, userAddress);
} else {
msg.setRecipients(Message.RecipientType.TO, details.getAddresses());
msg.setFrom(userAddress);
}
Date sentDate;
try {
sentDate = new Date(1000 * Long.valueOf(msgMap.get(Telephony.BaseMmsColumns.DATE)));
} catch (NumberFormatException n) {
Log.e(TAG, ERROR_PARSING_DATE, n);
sentDate = new Date();
}
final int msg_box = toInt(msgMap.get("msg_box"));
headerGenerator.setHeaders(msg, msgMap, DataType.MMS, details.address, details.getRecipient(), sentDate, msg_box);
MimeMultipart body = MimeMultipart.newInstance();
for (BodyPart p : mmsSupport.getMMSBodyParts(Uri.withAppendedPath(mmsUri, MMS_PART))) {
body.addBodyPart(p);
}
setBody(msg, body);
return msg;
}
Aggregations