use of javax.mail.util.SharedByteArrayInputStream in project zm-mailbox by Zimbra.
the class SetCalendarItem method deserializeSetCalendarItemData.
private Mailbox.SetCalendarItemData deserializeSetCalendarItemData(RedoLogInput in, boolean attachmentIndexingEnabled) throws IOException, MessagingException {
Mailbox.SetCalendarItemData toRet = new Mailbox.SetCalendarItemData();
int mboxId = getMailboxId();
try {
// keep this for backward compatibility with when SetCalendarItemData
in.readBoolean();
// used to have mForce field
ICalTimeZone localTz = Util.decodeTimeZoneFromMetadata(new Metadata(in.readUTF()));
toRet.invite = Invite.decodeMetadata(mboxId, new Metadata(in.readUTF()), null, localTz);
boolean hasPm;
if (getVersion().atLeast(1, 24)) {
hasPm = in.readBoolean();
} else {
hasPm = true;
}
// If version is earlier than 1.24, we always have ParsedMessage array.
if (hasPm) {
long receivedDate = in.readLong();
int dataLen = in.readInt();
byte[] rawPmData = new byte[dataLen];
in.readFully(rawPmData, 0, dataLen);
InputStream is = new SharedByteArrayInputStream(rawPmData);
MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSession(), is);
toRet.message = new ParsedMessage(mm, receivedDate, attachmentIndexingEnabled);
}
} catch (ServiceException ex) {
ex.printStackTrace();
throw new IOException("Cannot read serialized entry for CreateInvite " + ex.toString());
}
return toRet;
}
use of javax.mail.util.SharedByteArrayInputStream in project zm-mailbox by Zimbra.
the class TestParsedMessage method testAddMessage.
/**
* Tests adding a <tt>ParsedMessage</tt> to a mailbox.
*/
@Test
public void testAddMessage() throws Exception {
String msg = TestUtil.getTestMessage(NAME_PREFIX + " testAddMessage", SENDER_NAME, SENDER_NAME, null);
// Test ParsedMessage from byte[]
ParsedMessage pm = new ParsedMessage(msg.getBytes(), true);
runAddMessageTest(msg, pm);
// Test ParsedMessage from File
mFile = File.createTempFile("TestParsedMessage", null);
FileOutputStream out = new FileOutputStream(mFile);
out.write(msg.getBytes());
pm = new ParsedMessage(mFile, null, true);
runAddMessageTest(msg, pm);
// Test ParsedMessage from MimeMessage
MimeMessage mimeMsg = new ZMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(msg.getBytes()));
pm = new ParsedMessage(mimeMsg, true);
runAddMessageTest(msg, pm);
}
use of javax.mail.util.SharedByteArrayInputStream in project zm-mailbox by Zimbra.
the class TestParsedMessage method testGetData.
/**
* Confirms that the digest returned by a <tt>ParsedMessage</tt> is the same,
* regardless of whether the source comes from a byte array, file or <tt>MimeMessage</tt>.
*/
@Test
public void testGetData() throws Exception {
String msg = TestUtil.getTestMessage(NAME_PREFIX + " testGetData", SENDER_NAME, SENDER_NAME, null);
// Test ParsedMessage from byte[]
ParsedMessage pm = new ParsedMessage(msg.getBytes(), true);
runContentTests(msg, pm);
// Test ParsedMessage from File
mFile = File.createTempFile("TestParsedMessage", null);
FileOutputStream out = new FileOutputStream(mFile);
out.write(msg.getBytes());
pm = new ParsedMessage(mFile, null, true);
runContentTests(msg, pm);
// Test ParsedMessage from MimeMessage
MimeMessage mimeMsg = new ZMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(msg.getBytes()));
pm = new ParsedMessage(mimeMsg, true);
runContentTests(msg, pm);
}
use of javax.mail.util.SharedByteArrayInputStream in project zm-mailbox by Zimbra.
the class TestMailSender method testRestrictEnvelopeSender.
@Test
public void testRestrictEnvelopeSender() throws Exception {
Server server = Provisioning.getInstance().getLocalServer();
server.setSmtpPort(TEST_SMTP_PORT);
Mailbox mbox = TestUtil.getMailbox(SENDER_NAME);
Account account = mbox.getAccount();
// Create a message with a different From header value.
String from = TestUtil.getAddress("testRestrictEnvelopeSender");
String subject = NAME_PREFIX + " testRestrictEnvelopeSender";
MessageBuilder builder = new MessageBuilder().withFrom(from).withToRecipient(RECIPIENT_NAME).withSubject(subject).withBody("Who are you?");
String content = builder.create();
MimeMessage msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
account.setSmtpRestrictEnvelopeFrom(true);
// Restrict envelope sender, disallow custom from.
account.setAllowAnyFromAddress(false);
DummySmtpServer smtp = startDummySmtpServer(null, null);
mbox.getMailSender().sendMimeMessage(null, mbox, msg);
Assert.assertEquals(account.getName(), smtp.getMailFrom());
// Test contains to handle personal name
Assert.assertTrue(getHeaderValue(smtp.getDataLines(), "From").contains(account.getName()));
// Restrict envelope sender, allow custom from.
msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
account.setAllowAnyFromAddress(true);
smtp = startDummySmtpServer(null, null);
mbox.getMailSender().sendMimeMessage(null, mbox, msg);
Assert.assertEquals(account.getName(), smtp.getMailFrom());
Assert.assertEquals(from, getHeaderValue(smtp.getDataLines(), "From"));
account.setSmtpRestrictEnvelopeFrom(false);
// Don't restrict envelope sender, disallow custom from.
account.setAllowAnyFromAddress(false);
smtp = startDummySmtpServer(null, null);
mbox.getMailSender().sendMimeMessage(null, mbox, msg);
Assert.assertEquals(account.getName(), smtp.getMailFrom());
Assert.assertTrue(getHeaderValue(smtp.getDataLines(), "From").contains(account.getName()));
// Don't restrict envelope sender, allow custom from.
msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
account.setAllowAnyFromAddress(true);
smtp = startDummySmtpServer(null, null);
mbox.getMailSender().sendMimeMessage(null, mbox, msg);
Assert.assertEquals(from, smtp.getMailFrom());
Assert.assertEquals(from, getHeaderValue(smtp.getDataLines(), "From"));
}
use of javax.mail.util.SharedByteArrayInputStream in project zm-mailbox by Zimbra.
the class ParsedMessage method updateMimeMessage.
public void updateMimeMessage() throws IOException, MessagingException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
mimeMessage.writeTo(buffer);
byte[] content = buffer.toByteArray();
ByteUtil.closeStream(sharedStream);
sharedStream = new SharedByteArrayInputStream(content);
mimeMessage = expandedMessage = null;
mimeMessage = expandedMessage = new Mime.FixedMimeMessage(JMSession.getSession(), sharedStream);
}
Aggregations