inject UuidGenerator into MimeMessage via constructor instead of parameter

This commit is contained in:
Vincent Breitmoser 2016-08-10 14:23:20 +02:00
parent bb8e5a68df
commit 1e97f1ce16
29 changed files with 119 additions and 85 deletions

View file

@ -461,7 +461,7 @@ public class MessageTest {
}
private MimeMessage sampleMessage() throws MessagingException, IOException {
MimeMessage message = new MimeMessage();
MimeMessage message = MimeMessage.createMimeMessage();
message.setFrom(new Address("from@example.com"));
message.setRecipient(RecipientType.TO, new Address("to@example.com"));
message.setSubject("Test Message");

View file

@ -221,7 +221,7 @@ public class PgpMimeMessageTest {
InputStream messageInputStream = new ByteArrayInputStream(messageSource.getBytes());
MimeMessage message;
try {
message = new MimeMessage(messageInputStream, true);
message = MimeMessage.parseMimeMessage(messageInputStream, true);
} finally {
messageInputStream.close();
}

View file

@ -8,7 +8,6 @@ import java.io.InputStream;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.test.AndroidTestCase;
import com.fsck.k9.mail.internet.BinaryTempFileBody;
import com.fsck.k9.mail.internet.MimeMessage;
@ -58,7 +57,7 @@ public class ReconstructMessageTest {
InputStream messageInputStream = new ByteArrayInputStream(messageSource.getBytes());
MimeMessage message;
try {
message = new MimeMessage(messageInputStream, true);
message = MimeMessage.parseMimeMessage(messageInputStream, true);
} finally {
messageInputStream.close();
}

View file

@ -39,7 +39,7 @@ public class BinaryTempFileMessageBody extends BinaryTempFileBody implements Com
* could be sent along without processing. But since we
* don't know, we recursively parse it.
*/
MimeMessage message = new MimeMessage(in, true);
MimeMessage message = MimeMessage.parseMimeMessage(in, true);
message.setUsing7bitTransport();
message.writeTo(out);
} else {

View file

@ -43,6 +43,8 @@ import org.apache.james.mime4j.util.MimeUtil;
* RFC 2045 style headers.
*/
public class MimeMessage extends Message {
protected final UuidGenerator uuidGenerator;
private MimeHeader mHeader = new MimeHeader();
protected Address[] mFrom;
protected Address[] mTo;
@ -61,22 +63,23 @@ public class MimeMessage extends Message {
protected int mSize;
private String serverExtra;
public MimeMessage() {
public static MimeMessage createMimeMessage() {
UuidGenerator uuidGenerator = UuidGenerator.getInstance();
return new MimeMessage(uuidGenerator);
}
/**
* Parse the given InputStream using Apache Mime4J to build a MimeMessage.
*
* @param in
* @param recurse A boolean indicating to recurse through all nested MimeMessage subparts.
* @throws IOException
* @throws MessagingException
*/
public MimeMessage(InputStream in, boolean recurse) throws IOException, MessagingException {
parse(in, recurse);
public static MimeMessage parseMimeMessage(InputStream in, boolean recurse) throws IOException, MessagingException {
MimeMessage mimeMessage = createMimeMessage();
mimeMessage.parse(in, recurse);
return mimeMessage;
}
protected MimeMessage(UuidGenerator uuidGenerator) {
this.uuidGenerator = uuidGenerator;
}
/**
* Parse the given InputStream using Apache Mime4J to build a MimeMessage.
* Does not recurse through nested bodyparts.
@ -319,7 +322,7 @@ public class MimeMessage extends Message {
return mMessageId;
}
public void generateMessageId(UuidGenerator uuidGenerator) throws MessagingException {
public void generateMessageId() {
String hostname = null;
if (mFrom != null && mFrom.length >= 1) {
@ -502,7 +505,7 @@ public class MimeMessage extends Message {
expect(Part.class);
Part part = (Part) stack.peek();
MimeMessage m = new MimeMessage();
MimeMessage m = createMimeMessage();
part.setBody(m);
stack.addFirst(m);
}
@ -643,7 +646,7 @@ public class MimeMessage extends Message {
@Override
public MimeMessage clone() {
MimeMessage message = new MimeMessage();
MimeMessage message = createMimeMessage();
copy(message);
return message;
}

View file

@ -501,7 +501,7 @@ class ImapFolder extends Folder<ImapMessage> {
@Override
public ImapMessage getMessage(String uid) throws MessagingException {
return new ImapMessage(uid, this);
return ImapMessage.createImapMessage(uid, this);
}
@Override
@ -635,7 +635,7 @@ class ImapFolder extends Folder<ImapMessage> {
listener.messageStarted(uid, i, count);
}
ImapMessage message = new ImapMessage(uid, this);
ImapMessage message = ImapMessage.createImapMessage(uid, this);
messages.add(message);
if (listener != null) {

View file

@ -587,7 +587,7 @@ class ImapFolderPusher extends ImapFolder {
List<Message> messages = new ArrayList<Message>();
for (long uid = startUid; uid <= newUid; uid++) {
ImapMessage message = new ImapMessage(Long.toString(uid), ImapFolderPusher.this);
ImapMessage message = ImapMessage.createImapMessage(Long.toString(uid), ImapFolderPusher.this);
messages.add(message);
}
@ -626,7 +626,7 @@ class ImapFolderPusher extends ImapFolder {
}
for (String uid : removeUids) {
ImapMessage message = new ImapMessage(uid, ImapFolderPusher.this);
ImapMessage message = ImapMessage.createImapMessage(uid, ImapFolderPusher.this);
try {
message.setFlagInternal(Flag.DELETED, true);
@ -662,7 +662,7 @@ class ImapFolderPusher extends ImapFolder {
List<Message> messages = new ArrayList<Message>(count);
for (long uid = startUid; uid < uidNext; uid++) {
ImapMessage message = new ImapMessage(Long.toString(uid), ImapFolderPusher.this);
ImapMessage message = ImapMessage.createImapMessage(Long.toString(uid), ImapFolderPusher.this);
messages.add(message);
}

View file

@ -6,15 +6,23 @@ import java.util.Collections;
import com.fsck.k9.mail.Flag;
import com.fsck.k9.mail.Folder;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.UuidGenerator;
import com.fsck.k9.mail.internet.MimeMessage;
class ImapMessage extends MimeMessage {
ImapMessage(String uid, Folder folder) {
static ImapMessage createImapMessage(String uid, Folder folder) {
UuidGenerator uuidGenerator = UuidGenerator.getInstance();
return new ImapMessage(uuidGenerator, uid, folder);
}
private ImapMessage(UuidGenerator uuidGenerator, String uid, Folder folder) {
super(uuidGenerator);
this.mUid = uid;
this.mFolder = folder;
}
public void setSize(int size) {
this.mSize = size;
}

View file

@ -586,7 +586,7 @@ public class Pop3Store extends RemoteStore {
public Pop3Message getMessage(String uid) throws MessagingException {
Pop3Message message = mUidToMsgMap.get(uid);
if (message == null) {
message = new Pop3Message(uid, this);
message = Pop3Message.createPop3Message(uid, this);
}
return message;
}
@ -668,7 +668,7 @@ public class Pop3Store extends RemoteStore {
return;
}
String msgUid = uidParts[2];
message = new Pop3Message(msgUid, this);
message = Pop3Message.createPop3Message(msgUid, this);
indexMessage(msgNum, message);
}
}
@ -708,7 +708,7 @@ public class Pop3Store extends RemoteStore {
if (msgNum >= start && msgNum <= end) {
Pop3Message message = mMsgNumToMsgMap.get(msgNum);
if (message == null) {
message = new Pop3Message(msgUid, this);
message = Pop3Message.createPop3Message(msgUid, this);
indexMessage(msgNum, message);
}
}
@ -754,7 +754,7 @@ public class Pop3Store extends RemoteStore {
Pop3Message message = mUidToMsgMap.get(msgUid);
if (message == null) {
message = new Pop3Message(msgUid, this);
message = Pop3Message.createPop3Message(msgUid, this);
}
indexMessage(msgNum, message);
}
@ -1184,7 +1184,13 @@ public class Pop3Store extends RemoteStore {
}//Pop3Folder
static class Pop3Message extends MimeMessage {
public Pop3Message(String uid, Pop3Folder folder) {
public static Pop3Message createPop3Message(String uid, Pop3Folder folder) {
UuidGenerator uuidGenerator = UuidGenerator.getInstance();
return new Pop3Message(uuidGenerator, uid, folder);
}
private Pop3Message(UuidGenerator uuidGenerator, String uid, Pop3Folder folder) {
super(uuidGenerator);
mUid = uid;
mFolder = folder;
mSize = -1;

View file

@ -225,7 +225,7 @@ class WebDavFolder extends Folder<WebDavMessage> {
@Override
public WebDavMessage getMessage(String uid) throws MessagingException {
return new WebDavMessage(uid, this);
return WebDavMessage.createWebDavMessage(uid, this);
}
@Override
@ -265,7 +265,7 @@ class WebDavFolder extends Folder<WebDavMessage> {
if (listener != null) {
listener.messageStarted(uids[i], i, uidsLength);
}
WebDavMessage message = new WebDavMessage(uids[i], this);
WebDavMessage message = WebDavMessage.createWebDavMessage(uids[i], this);
message.setUrl(uidToUrl.get(uids[i]));
messages.add(message);
@ -696,7 +696,7 @@ class WebDavFolder extends Folder<WebDavMessage> {
+ " while sending/appending message. Response = "
+ response.getStatusLine().toString() + " for message " + messageURL);
}
WebDavMessage retMessage = new WebDavMessage(message.getUid(), this);
WebDavMessage retMessage = WebDavMessage.createWebDavMessage(message.getUid(), this);
retMessage.setUrl(messageURL);
retMessages.add(retMessage);

View file

@ -5,6 +5,7 @@ import android.util.Log;
import com.fsck.k9.mail.Flag;
import com.fsck.k9.mail.Folder;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.UuidGenerator;
import com.fsck.k9.mail.internet.MimeMessage;
import java.util.Collections;
@ -21,7 +22,13 @@ import static com.fsck.k9.mail.helper.UrlEncodingHelper.encodeUtf8;
class WebDavMessage extends MimeMessage {
private String mUrl = "";
WebDavMessage(String uid, Folder folder) {
static WebDavMessage createWebDavMessage(String uid, Folder folder) {
UuidGenerator uuidGenerator = UuidGenerator.getInstance();
return new WebDavMessage(uuidGenerator, uid, folder);
}
private WebDavMessage(UuidGenerator uuidGenerator, String uid, Folder folder) {
super(uuidGenerator);
this.mUid = uid;
this.mFolder = folder;
}

View file

@ -20,7 +20,7 @@ public class CharsetSupportTest {
charsetOnMail = "CP932";
expect = "shift_jis";
assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, new MimeMessage()));
assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, MimeMessage.createMimeMessage()));
// charsetOnMail = "koi8-u";
// expect = "koi8-r";
@ -28,73 +28,73 @@ public class CharsetSupportTest {
MimeMessage message;
message = new MimeMessage();
message = MimeMessage.createMimeMessage();
message.setHeader("From", "aaa@docomo.ne.jp");
charsetOnMail = "shift_jis";
expect = "x-docomo-shift_jis-2007";
assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, message));
message = new MimeMessage();
message = MimeMessage.createMimeMessage();
message.setHeader("From", "aaa@dwmail.jp");
charsetOnMail = "shift_jis";
expect = "x-docomo-shift_jis-2007";
assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, message));
message = new MimeMessage();
message = MimeMessage.createMimeMessage();
message.setHeader("From", "aaa@pdx.ne.jp");
charsetOnMail = "shift_jis";
expect = "x-docomo-shift_jis-2007";
assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, message));
message = new MimeMessage();
message = MimeMessage.createMimeMessage();
message.setHeader("From", "aaa@willcom.com");
charsetOnMail = "shift_jis";
expect = "x-docomo-shift_jis-2007";
assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, message));
message = new MimeMessage();
message = MimeMessage.createMimeMessage();
message.setHeader("From", "aaa@emnet.ne.jp");
charsetOnMail = "shift_jis";
expect = "x-docomo-shift_jis-2007";
assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, message));
message = new MimeMessage();
message = MimeMessage.createMimeMessage();
message.setHeader("From", "aaa@emobile.ne.jp");
charsetOnMail = "shift_jis";
expect = "x-docomo-shift_jis-2007";
assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, message));
message = new MimeMessage();
message = MimeMessage.createMimeMessage();
message.setHeader("From", "aaa@softbank.ne.jp");
charsetOnMail = "shift_jis";
expect = "x-softbank-shift_jis-2007";
assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, message));
message = new MimeMessage();
message = MimeMessage.createMimeMessage();
message.setHeader("From", "aaa@vodafone.ne.jp");
charsetOnMail = "shift_jis";
expect = "x-softbank-shift_jis-2007";
assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, message));
message = new MimeMessage();
message = MimeMessage.createMimeMessage();
message.setHeader("From", "aaa@disney.ne.jp");
charsetOnMail = "shift_jis";
expect = "x-softbank-shift_jis-2007";
assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, message));
message = new MimeMessage();
message = MimeMessage.createMimeMessage();
message.setHeader("From", "aaa@vertuclub.ne.jp");
charsetOnMail = "shift_jis";
expect = "x-softbank-shift_jis-2007";
assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, message));
message = new MimeMessage();
message = MimeMessage.createMimeMessage();
message.setHeader("From", "aaa@ezweb.ne.jp");
charsetOnMail = "shift_jis";
expect = "x-kddi-shift_jis-2007";
assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, message));
message = new MimeMessage();
message = MimeMessage.createMimeMessage();
message.setHeader("From", "aaa@ido.ne.jp");
charsetOnMail = "shift_jis";
expect = "x-kddi-shift_jis-2007";

View file

@ -117,7 +117,7 @@ public class ListHeadersTest {
}
private MimeMessage buildMimeMessageWithListPostValue(String... values) throws MessagingException {
MimeMessage message = new MimeMessage();
MimeMessage message = MimeMessage.createMimeMessage();
for (String value : values) {
message.addHeader("List-Post", value);
}

View file

@ -210,11 +210,11 @@ public class MimeMessageParseTest {
}
private static MimeMessage parseWithoutRecurse(InputStream data) throws Exception {
return new MimeMessage(data, false);
return MimeMessage.parseMimeMessage(data, false);
}
private static MimeMessage parseWithRecurse(InputStream data) throws Exception {
return new MimeMessage(data, true);
return MimeMessage.parseMimeMessage(data, true);
}
private static void checkAddresses(Address[] actual, String... expected) {

View file

@ -279,7 +279,7 @@ public class WebDavFolderTest {
List<WebDavMessage> messages = new ArrayList<>();
for (int i = 0; i < 25; i++) {
WebDavMessage message = new WebDavMessage("message" + i, folder);
WebDavMessage message = WebDavMessage.createWebDavMessage("message" + i, folder);
message.setUrl("http://example.org/Exchange/user/Inbox/message" + i + ".EML");
messages.add(message);
}

View file

@ -35,7 +35,7 @@ public class WebDavMessageTest {
MockitoAnnotations.initMocks(this);
when(mockFolder.getName()).thenReturn("Inbox");
when(mockFolder.getUrl()).thenReturn("http://example.org/Inbox");
message = new WebDavMessage("message1", mockFolder);
message = WebDavMessage.createWebDavMessage("message1", mockFolder);
}
@Test

View file

@ -95,7 +95,7 @@ public class ReconstructMessageFromDatabaseTest extends ApplicationTestCase<K9>
public void testAddMissingPart() throws MessagingException, IOException {
LocalFolder folder = createFolderInDatabase();
MimeMessage message = new MimeMessage();
MimeMessage message = MimeMessage.createMimeMessage();
message.addHeader("To", "to@example.com");
message.addHeader("MIME-Version", "1.0");
message.addHeader("Content-Type", "text/plain");
@ -128,7 +128,7 @@ public class ReconstructMessageFromDatabaseTest extends ApplicationTestCase<K9>
protected MimeMessage parseMessage() throws IOException, MessagingException {
InputStream messageInputStream = new ByteArrayInputStream(MESSAGE_SOURCE.getBytes());
try {
return new MimeMessage(messageInputStream, true);
return MimeMessage.parseMimeMessage(messageInputStream, true);
} finally {
messageInputStream.close();
}

View file

@ -33,22 +33,22 @@ public class EmailProviderTest extends ProviderTestCase2<EmailProvider> {
}
private void buildMessages() throws MessagingException {
message = new MimeMessage();
message = MimeMessage.createMimeMessage();
message.setSubject("Test Subject");
message.setSentDate(new GregorianCalendar(2016, 1, 2).getTime(), false);
message.setMessageId("<uid001@email.com>");
laterMessage = new MimeMessage();
laterMessage = MimeMessage.createMimeMessage();
laterMessage.setSubject("Test Subject2");
laterMessage.setSentDate(new GregorianCalendar(2016, 1, 3).getTime(), false);
reply = new MimeMessage();
reply = MimeMessage.createMimeMessage();
reply.setSubject("Re: Test Subject");
reply.setSentDate(new GregorianCalendar(2016, 1, 3).getTime(), false);
reply.setMessageId("<uid002@email.com>");
reply.setInReplyTo("<uid001@email.com>");
replyAtSameTime = new MimeMessage();
replyAtSameTime = MimeMessage.createMimeMessage();
replyAtSameTime.setSubject("Re: Test Subject");
replyAtSameTime.setSentDate(new GregorianCalendar(2016, 1, 2).getTime(), false);
replyAtSameTime.setMessageId("<uid002@email.com>");
@ -301,7 +301,7 @@ public class EmailProviderTest extends ProviderTestCase2<EmailProvider> {
Account account = Preferences.getPreferences(getContext()).newAccount();
account.getUuid();
Message message = new MimeMessage();
Message message = MimeMessage.createMimeMessage();
message.setSubject("Test Subject");
message.setSentDate(new GregorianCalendar(2016, 1, 2).getTime(), false);

View file

@ -2413,7 +2413,7 @@ public class MessagingController {
Store localStore = account.getLocalStore();
LocalFolder localFolder = (LocalFolder)localStore.getFolder(account.getErrorFolderName());
MimeMessage message = new MimeMessage();
MimeMessage message = MimeMessage.createMimeMessage();
MimeMessageHelper.setBody(message, new TextBody(body));
message.setFlag(Flag.X_DOWNLOADED_FULL, true);

View file

@ -21,7 +21,7 @@ class AttachmentMessageBodyUtil {
* could be sent along without processing. But since we
* don't know, we recursively parse it.
*/
MimeMessage message = new MimeMessage(in, true);
MimeMessage message = MimeMessage.parseMimeMessage(in, true);
message.setUsing7bitTransport();
message.writeTo(out);
} else {

View file

@ -739,7 +739,7 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
((Multipart) parentPart.getBody()).addBodyPart(bodyPart);
part = bodyPart;
} else if (MimeUtility.isMessage(parentMimeType)) {
Message innerMessage = new MimeMessage();
Message innerMessage = MimeMessage.createMimeMessage();
parentPart.setBody(innerMessage);
part = innerMessage;
} else {
@ -833,7 +833,8 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
public LocalMessage doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
try {
open(OPEN_MODE_RW);
LocalMessage message = new LocalMessage(LocalFolder.this.localStore, uid, LocalFolder.this);
LocalMessage message =
LocalMessage.createLocalMessage(LocalFolder.this.localStore, uid, LocalFolder.this);
Cursor cursor = null;
try {

View file

@ -17,6 +17,7 @@ import com.fsck.k9.mail.Address;
import com.fsck.k9.mail.Flag;
import com.fsck.k9.mail.Folder;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.UuidGenerator;
import com.fsck.k9.mail.internet.MimeMessage;
import com.fsck.k9.mail.message.MessageHeaderParser;
import com.fsck.k9.mailstore.LockableDatabase.DbCallback;
@ -40,16 +41,25 @@ public class LocalMessage extends MimeMessage {
private String mimeType;
private PreviewType previewType;
private LocalMessage(LocalStore localStore) {
static LocalMessage createLocalMessage(LocalStore localStore, String uid, Folder folder) {
UuidGenerator uuidGenerator = UuidGenerator.getInstance();
return new LocalMessage(uuidGenerator, localStore, uid, folder);
}
private LocalMessage(UuidGenerator uuidGenerator, LocalStore localStore) {
super(uuidGenerator);
this.localStore = localStore;
}
LocalMessage(LocalStore localStore, String uid, Folder folder) {
private LocalMessage(UuidGenerator uuidGenerator, LocalStore localStore, String uid, Folder folder) {
super(uuidGenerator);
this.localStore = localStore;
this.mUid = uid;
this.mFolder = folder;
}
void populateFromGetMessageCursor(Cursor cursor) throws MessagingException {
final String subject = cursor.getString(0);
this.setSubject(subject == null ? "" : subject);
@ -496,7 +506,7 @@ public class LocalMessage extends MimeMessage {
@Override
public LocalMessage clone() {
LocalMessage message = new LocalMessage(this.localStore);
LocalMessage message = new LocalMessage(uuidGenerator, localStore);
super.copy(message);
message.mId = mId;

View file

@ -602,7 +602,7 @@ public class LocalStore extends Store implements Serializable {
cursor = db.rawQuery(queryString + " LIMIT 10", placeHolders);
while (cursor.moveToNext()) {
LocalMessage message = new LocalMessage(LocalStore.this, null, folder);
LocalMessage message = LocalMessage.createLocalMessage(LocalStore.this, null, folder);
message.populateFromGetMessageCursor(cursor);
messages.add(message);
@ -615,7 +615,7 @@ public class LocalStore extends Store implements Serializable {
cursor = db.rawQuery(queryString + " LIMIT -1 OFFSET 10", placeHolders);
while (cursor.moveToNext()) {
LocalMessage message = new LocalMessage(LocalStore.this, null, folder);
LocalMessage message = LocalMessage.createLocalMessage(LocalStore.this, null, folder);
message.populateFromGetMessageCursor(cursor);
messages.add(message);

View file

@ -81,7 +81,7 @@ public class MimePartStreamParser {
} else {
Part part = (Part) stack.peek();
Message innerMessage = new MimeMessage();
Message innerMessage = MimeMessage.createMimeMessage();
part.setBody(innerMessage);
stack.push(innerMessage);

View file

@ -84,7 +84,7 @@ public abstract class MessageBuilder {
protected MimeMessage build() throws MessagingException {
//FIXME: check arguments
MimeMessage message = new MimeMessage();
MimeMessage message = MimeMessage.createMimeMessage();
buildHeader(message);
buildBody(message);
@ -124,7 +124,7 @@ public abstract class MessageBuilder {
message.setReferences(references);
}
message.generateMessageId(uuidGenerator);
message.generateMessageId();
if (isDraft && isPgpInlineEnabled) {
message.setFlag(Flag.X_DRAFT_OPENPGP_INLINE, true);

View file

@ -35,7 +35,7 @@ public class MessageDecryptVerifierTest {
@Test
public void findEncryptedPartsShouldReturnEmptyListForEmptyMessage() throws Exception {
MimeMessage emptyMessage = new MimeMessage();
MimeMessage emptyMessage = MimeMessage.createMimeMessage();
List<Part> encryptedParts = MessageDecryptVerifier.findEncryptedParts(emptyMessage);
@ -44,7 +44,7 @@ public class MessageDecryptVerifierTest {
@Test
public void findEncryptedPartsShouldReturnEmptyListForSimpleMessage() throws Exception {
MimeMessage message = new MimeMessage();
MimeMessage message = MimeMessage.createMimeMessage();
message.setBody(new TextBody("message text"));
List<Part> encryptedParts = MessageDecryptVerifier.findEncryptedParts(message);
@ -54,7 +54,7 @@ public class MessageDecryptVerifierTest {
@Test
public void findEncryptedPartsShouldReturnEmptyEncryptedPart() throws Exception {
MimeMessage message = new MimeMessage();
MimeMessage message = MimeMessage.createMimeMessage();
MimeMultipart multipartEncrypted = MimeMultipart.createMimeMultipart();
multipartEncrypted.setSubType("encrypted");
MimeMessageHelper.setBody(message, multipartEncrypted);
@ -68,7 +68,7 @@ public class MessageDecryptVerifierTest {
@Test
public void findEncryptedPartsShouldReturnMultipleEncryptedParts() throws Exception {
MimeMessage message = new MimeMessage();
MimeMessage message = MimeMessage.createMimeMessage();
MimeMultipart multipartMixed = MimeMultipart.createMimeMultipart();
multipartMixed.setSubType("mixed");
MimeMessageHelper.setBody(message, multipartMixed);
@ -273,7 +273,7 @@ public class MessageDecryptVerifierTest {
}
MimeMessage messageFromBody(BodyPart bodyPart) throws MessagingException {
MimeMessage message = new MimeMessage();
MimeMessage message = MimeMessage.createMimeMessage();
MimeMessageHelper.setBody(message, bodyPart.getBody());
return message;
}

View file

@ -69,7 +69,7 @@ public class MessageViewInfoExtractorTest {
TextBody body = new TextBody(BODY_TEXT);
// Create message
MimeMessage message = new MimeMessage();
MimeMessage message = MimeMessage.createMimeMessage();
MimeMessageHelper.setBody(message, body);
// Prepare fixture
@ -95,7 +95,7 @@ public class MessageViewInfoExtractorTest {
TextBody body = new TextBody(BODY_TEXT);
// Create message
MimeMessage message = new MimeMessage();
MimeMessage message = MimeMessage.createMimeMessage();
message.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "text/plain");
MimeMessageHelper.setBody(message, body);
@ -123,7 +123,7 @@ public class MessageViewInfoExtractorTest {
TextBody body = new TextBody(bodyText);
// Create message
MimeMessage message = new MimeMessage();
MimeMessage message = MimeMessage.createMimeMessage();
message.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "text/html");
MimeMessageHelper.setBody(message, body);
@ -158,7 +158,7 @@ public class MessageViewInfoExtractorTest {
multipart.addBodyPart(bodyPart2);
// Create message
MimeMessage message = new MimeMessage();
MimeMessage message = MimeMessage.createMimeMessage();
MimeMessageHelper.setBody(message, multipart);
// Extract text
@ -201,7 +201,7 @@ public class MessageViewInfoExtractorTest {
TextBody innerBody = new TextBody(innerBodyText);
// Create message/rfc822 body
MimeMessage innerMessage = new MimeMessage();
MimeMessage innerMessage = MimeMessage.createMimeMessage();
innerMessage.addSentDate(new Date(112, 02, 17), false);
innerMessage.setRecipients(RecipientType.TO, new Address[] { new Address("to@example.com") });
innerMessage.setSubject("Subject");
@ -217,7 +217,7 @@ public class MessageViewInfoExtractorTest {
multipart.addBodyPart(bodyPart2);
// Create message
MimeMessage message = new MimeMessage();
MimeMessage message = MimeMessage.createMimeMessage();
MimeMessageHelper.setBody(message, multipart);
// Extract text

View file

@ -52,7 +52,7 @@ public class MessageCreationHelper {
}
private static Message createMessage(String mimeType, Body body) throws MessagingException {
MimeMessage message = new MimeMessage();
MimeMessage message = MimeMessage.createMimeMessage();
message.setBody(body);
message.setHeader(MimeHeader.HEADER_CONTENT_TYPE, mimeType);

View file

@ -103,6 +103,6 @@ public class MessagePreviewCreatorTest {
}
private Message createDummyMessage() {
return new MimeMessage();
return MimeMessage.createMimeMessage();
}
}