mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 18:02:15 -05:00
Add test for updating a message with a missing part
This commit is contained in:
parent
bd97004ebd
commit
2532362ed5
@ -13,10 +13,12 @@ import android.test.RenamingDelegatingContext;
|
||||
|
||||
import com.fsck.k9.Account;
|
||||
import com.fsck.k9.K9;
|
||||
import com.fsck.k9.mail.Body;
|
||||
import com.fsck.k9.mail.FetchProfile;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.internet.BinaryTempFileBody;
|
||||
import com.fsck.k9.mail.internet.MimeMessage;
|
||||
import org.apache.james.mime4j.util.MimeUtil;
|
||||
|
||||
|
||||
public class ReconstructMessageFromDatabaseTest extends ApplicationTestCase<K9> {
|
||||
@ -89,6 +91,39 @@ public class ReconstructMessageFromDatabaseTest extends ApplicationTestCase<K9>
|
||||
assertEquals(MESSAGE_SOURCE, reconstructedMessage);
|
||||
}
|
||||
|
||||
public void testAddMissingPart() throws MessagingException, IOException {
|
||||
LocalFolder folder = createFolderInDatabase();
|
||||
|
||||
MimeMessage message = new MimeMessage();
|
||||
message.addHeader("To", "to@example.com");
|
||||
message.addHeader("MIME-Version", "1.0");
|
||||
message.addHeader("Content-Type", "text/plain");
|
||||
message.setServerExtra("text");
|
||||
|
||||
saveMessageToDatabase(folder, message);
|
||||
|
||||
LocalMessage localMessage = readMessageFromDatabase(folder, message);
|
||||
|
||||
assertEquals("to@example.com", localMessage.getHeader("To")[0]);
|
||||
assertEquals("text/plain", localMessage.getMimeType());
|
||||
assertEquals("text", localMessage.getServerExtra());
|
||||
assertNull(localMessage.getBody());
|
||||
|
||||
Body body = new BinaryMemoryBody("Test message body".getBytes(), MimeUtil.ENC_7BIT);
|
||||
localMessage.setBody(body);
|
||||
folder.addPartToMessage(localMessage, localMessage);
|
||||
|
||||
LocalMessage completeLocalMessage = readMessageFromDatabase(folder, message);
|
||||
String reconstructedMessage = writeMessageToString(completeLocalMessage);
|
||||
|
||||
assertEquals("To: to@example.com\r\n" +
|
||||
"MIME-Version: 1.0\r\n" +
|
||||
"Content-Type: text/plain\r\n" +
|
||||
"\r\n" +
|
||||
"Test message body",
|
||||
reconstructedMessage);
|
||||
}
|
||||
|
||||
protected MimeMessage parseMessage() throws IOException, MessagingException {
|
||||
InputStream messageInputStream = new ByteArrayInputStream(MESSAGE_SOURCE.getBytes());
|
||||
try {
|
||||
|
@ -672,6 +672,7 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
|
||||
long parentId = cursor.getLong(2);
|
||||
String mimeType = cursor.getString(3);
|
||||
byte[] header = cursor.getBlob(6);
|
||||
int dataLocation = cursor.getInt(9);
|
||||
String serverExtra = cursor.getString(15);
|
||||
|
||||
final Part part;
|
||||
@ -711,7 +712,7 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
|
||||
part.setBody(multipart);
|
||||
multipart.setPreamble(preamble);
|
||||
multipart.setEpilogue(epilogue);
|
||||
} else {
|
||||
} else if (dataLocation != DataLocation.MISSING) {
|
||||
String encoding = cursor.getString(7);
|
||||
byte[] data = cursor.getBlob(10);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user