use of com.fsck.k9.mail.Message in project k-9 by k9mail.
the class MessageListFragment method groupMessagesByAccount.
private Map<Account, List<MessageReference>> groupMessagesByAccount(final List<MessageReference> messages) {
Map<Account, List<MessageReference>> messagesByAccount = new HashMap<>();
for (MessageReference message : messages) {
Account account = preferences.getAccount(message.getAccountUuid());
List<MessageReference> msgList = messagesByAccount.get(account);
if (msgList == null) {
msgList = new ArrayList<>();
messagesByAccount.put(account, msgList);
}
msgList.add(message);
}
return messagesByAccount;
}
use of com.fsck.k9.mail.Message in project k-9 by k9mail.
the class LocalFolder method loadMessageParts.
private void loadMessageParts(SQLiteDatabase db, LocalMessage message) throws MessagingException {
Map<Long, Part> partById = new HashMap<>();
String[] columns = { // 0
"id", // 1
"type", // 2
"parent", // 3
"mime_type", // 4
"decoded_body_size", // 5
"display_name", // 6
"header", // 7
"encoding", // 8
"charset", // 9
"data_location", // 10
"data", // 11
"preamble", // 12
"epilogue", // 13
"boundary", // 14
"content_id", // 15
"server_extra" };
Cursor cursor = db.query("message_parts", columns, "root = ?", new String[] { String.valueOf(message.getMessagePartId()) }, null, null, "seq");
try {
while (cursor.moveToNext()) {
loadMessagePart(message, partById, cursor);
}
} finally {
cursor.close();
}
}
use of com.fsck.k9.mail.Message in project k-9 by k9mail.
the class LocalFolder method moveMessages.
@Override
public Map<String, String> moveMessages(final List<? extends Message> msgs, final Folder destFolder) throws MessagingException {
if (!(destFolder instanceof LocalFolder)) {
throw new MessagingException("moveMessages called with non-LocalFolder");
}
final LocalFolder lDestFolder = (LocalFolder) destFolder;
final Map<String, String> uidMap = new HashMap<>();
try {
this.localStore.database.execute(false, new DbCallback<Void>() {
@Override
public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
try {
lDestFolder.open(OPEN_MODE_RW);
for (Message message : msgs) {
LocalMessage lMessage = (LocalMessage) message;
String oldUID = message.getUid();
Timber.d("Updating folder_id to %s for message with UID %s, " + "id %d currently in folder %s", lDestFolder.getId(), message.getUid(), lMessage.getId(), getName());
String newUid = K9.LOCAL_UID_PREFIX + UUID.randomUUID().toString();
message.setUid(newUid);
uidMap.put(oldUID, newUid);
// Message threading in the target folder
ThreadInfo threadInfo = lDestFolder.doMessageThreading(db, message);
/*
* "Move" the message into the new folder
*/
long msgId = lMessage.getId();
String[] idArg = new String[] { Long.toString(msgId) };
ContentValues cv = new ContentValues();
cv.put("folder_id", lDestFolder.getId());
cv.put("uid", newUid);
db.update("messages", cv, "id = ?", idArg);
// Create/update entry in 'threads' table for the message in the
// target folder
cv.clear();
cv.put("message_id", msgId);
if (threadInfo.threadId == -1) {
if (threadInfo.rootId != -1) {
cv.put("root", threadInfo.rootId);
}
if (threadInfo.parentId != -1) {
cv.put("parent", threadInfo.parentId);
}
db.insert("threads", null, cv);
} else {
db.update("threads", cv, "id = ?", new String[] { Long.toString(threadInfo.threadId) });
}
/*
* Add a placeholder message so we won't download the original
* message again if we synchronize before the remote move is
* complete.
*/
// We need to open this folder to get the folder id
open(OPEN_MODE_RW);
cv.clear();
cv.put("uid", oldUID);
cv.putNull("flags");
cv.put("read", 1);
cv.put("deleted", 1);
cv.put("folder_id", mFolderId);
cv.put("empty", 0);
String messageId = message.getMessageId();
if (messageId != null) {
cv.put("message_id", messageId);
}
final long newId;
if (threadInfo.msgId != -1) {
// There already existed an empty message in the target folder.
// Let's use it as placeholder.
newId = threadInfo.msgId;
db.update("messages", cv, "id = ?", new String[] { Long.toString(newId) });
} else {
newId = db.insert("messages", null, cv);
}
/*
* Update old entry in 'threads' table to point to the newly
* created placeholder.
*/
cv.clear();
cv.put("message_id", newId);
db.update("threads", cv, "id = ?", new String[] { Long.toString(lMessage.getThreadId()) });
}
} catch (MessagingException e) {
throw new WrappedException(e);
}
return null;
}
});
this.localStore.notifyChange();
return uidMap;
} catch (WrappedException e) {
throw (MessagingException) e.getCause();
}
}
use of com.fsck.k9.mail.Message in project k-9 by k9mail.
the class ReplyToParser method getRecipientsToReplyAllTo.
public ReplyToAddresses getRecipientsToReplyAllTo(Message message, Account account) {
List<Address> replyToAddresses = Arrays.asList(getRecipientsToReplyTo(message, account).to);
HashSet<Address> alreadyAddedAddresses = new HashSet<>(replyToAddresses);
ArrayList<Address> toAddresses = new ArrayList<>(replyToAddresses);
ArrayList<Address> ccAddresses = new ArrayList<>();
for (Address address : message.getFrom()) {
if (!alreadyAddedAddresses.contains(address) && !account.isAnIdentity(address)) {
toAddresses.add(address);
alreadyAddedAddresses.add(address);
}
}
for (Address address : message.getRecipients(RecipientType.TO)) {
if (!alreadyAddedAddresses.contains(address) && !account.isAnIdentity(address)) {
toAddresses.add(address);
alreadyAddedAddresses.add(address);
}
}
for (Address address : message.getRecipients(RecipientType.CC)) {
if (!alreadyAddedAddresses.contains(address) && !account.isAnIdentity(address)) {
ccAddresses.add(address);
alreadyAddedAddresses.add(address);
}
}
return new ReplyToAddresses(toAddresses, ccAddresses);
}
use of com.fsck.k9.mail.Message in project k-9 by k9mail.
the class MessageDecryptVerifierTest method findEncrypted__withMultipartMixedSubEncryptedAndText__shouldReturnEncrypted.
@Test
public void findEncrypted__withMultipartMixedSubEncryptedAndText__shouldReturnEncrypted() throws Exception {
Message message = messageFromBody(multipart("mixed", multipart("encrypted", bodypart("application/pgp-encrypted"), bodypart("application/octet-stream")), bodypart("text/plain")));
List<Part> encryptedParts = MessageDecryptVerifier.findEncryptedParts(message);
assertEquals(1, encryptedParts.size());
assertSame(getPart(message, 0), encryptedParts.get(0));
}
Aggregations