use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.
the class TestLmtp method testAllowReceiveButNotSendWhenOverQuota.
/**
* Verifies send/receive behavior for {@code zimbraMailAllowReceiveButNotSendWhenOverQuota}.
*/
@Test
public void testAllowReceiveButNotSendWhenOverQuota() throws Exception {
TestUtil.setAccountAttr(USER_NAME, Provisioning.A_zimbraMailAllowReceiveButNotSendWhenOverQuota, LdapConstants.LDAP_TRUE);
TestUtil.setAccountAttr(USER_NAME, Provisioning.A_zimbraMailQuota, "1");
String subject = NAME_PREFIX + " testAllowReceiveButNotSendWhenOverQuota";
// Verify that receive is allowed.
TestUtil.addMessageLmtp(subject, USER_NAME, USER_NAME);
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
TestUtil.getMessage(mbox, "in:inbox subject:\"" + subject + "\"");
// Verify that send is disallowed.
try {
TestUtil.sendMessage(mbox, USER_NAME, subject);
Assert.fail("Send should have failed");
} catch (ServiceException e) {
Assert.assertEquals(MailServiceException.QUOTA_EXCEEDED, e.getCode());
}
// Verify that adding a document is disallowed.
try {
byte[] data = new byte[1024];
TestUtil.createDocument(mbox, Integer.toString(Mailbox.ID_FOLDER_BRIEFCASE), NAME_PREFIX + " receivenosend.bin", "application/content-stream", data);
Assert.fail("Document creation should have failed");
} catch (ServiceException e) {
Assert.assertEquals(MailServiceException.QUOTA_EXCEEDED, e.getCode());
}
// Verify that saving a draft is allowed (bug 51457).
String draftSubject1 = subject + " save draft 1";
String draftSubject2 = subject + " save draft 2 two";
ZOutgoingMessage outgoingDraft = TestUtil.getOutgoingMessage(USER_NAME, draftSubject1, draftSubject1, null);
// Add message
ZMessage draftMsg = mbox.saveDraft(outgoingDraft, null, Integer.toString(Mailbox.ID_FOLDER_DRAFTS));
outgoingDraft = TestUtil.getOutgoingMessage(USER_NAME, draftSubject2, draftSubject2, null);
// Set content of existing message
mbox.saveDraft(outgoingDraft, draftMsg.getId(), Integer.toString(Mailbox.ID_FOLDER_DRAFTS));
}
use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.
the class TestLmtp method testDiskStreamingEmptyFolder.
/**
* Another test for bug 25484. Delivers a message to user1 and user2, then confirms that
* user1 can still read the message after user2 empties the folder that contains the message.
*/
@Test
public void testDiskStreamingEmptyFolder() throws Exception {
TestUtil.createAccount(USER2_NAME);
TestUtil.setServerAttr(Provisioning.A_zimbraMailDiskStreamingThreshold, "0");
String[] recipients = { TestUtil.getAddress(USER_NAME), TestUtil.getAddress(USER2_NAME) };
String subject = NAME_PREFIX + " testDiskStreamingMultipleRecipients";
ZMailbox mbox1 = TestUtil.getZMailbox(USER_NAME);
ZMailbox mbox2 = TestUtil.getZMailbox(USER2_NAME);
TestUtil.addMessageLmtp(subject, recipients, TestUtil.getAddress(USER_NAME));
TestUtil.waitForMessage(mbox1, "in:inbox subject:\"" + subject + "\"");
ZMessage msg2 = TestUtil.waitForMessage(mbox2, "in:inbox subject:\"" + subject + "\"");
// Test bug 25484. Have user2 move the message to a folder, empty the folder,
// and then have user1 read the message.
ZFolder folder2 = TestUtil.createFolder(mbox2, "/" + NAME_PREFIX + " testDiskStreamingEmptyFolder");
mbox2.moveMessage(msg2.getId(), folder2.getId());
// Mark message as read, since unread messages result in uncache
// getting called explicitly in Folder.propagateDeletion().
mbox2.markItemRead(msg2.getId(), true, null);
mbox2.emptyFolder(folder2.getId());
mbox1 = TestUtil.getZMailbox(USER_NAME);
TestUtil.waitForMessage(mbox1, "in:inbox subject:\"" + subject + "\"");
}
use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.
the class TestLmtp method testDiskStreamingMultipleRecipients.
/**
* Confirms that mail can successfully be delivered to multiple users when streaming to disk.
*/
@Test
public void testDiskStreamingMultipleRecipients() throws Exception {
TestUtil.createAccount(USER2_NAME);
TestUtil.setServerAttr(Provisioning.A_zimbraMailDiskStreamingThreshold, "0");
String[] recipients = { TestUtil.getAddress(USER_NAME), TestUtil.getAddress(USER2_NAME) };
String subject = NAME_PREFIX + " testDiskStreamingMultipleRecipients";
ZMailbox mbox1 = TestUtil.getZMailbox(USER_NAME);
ZMailbox mbox2 = TestUtil.getZMailbox(USER2_NAME);
TestUtil.addMessageLmtp(subject, recipients, TestUtil.getAddress(USER_NAME));
TestUtil.waitForMessage(mbox1, "in:inbox subject:\"" + subject + "\"");
ZMessage msg2 = TestUtil.waitForMessage(mbox2, "in:inbox subject:\"" + subject + "\"");
// Test bug 25484. Make sure that user1 can still read the message after user2
// deletes it.
mbox2.deleteMessage(msg2.getId());
mbox1 = TestUtil.getZMailbox(USER_NAME);
TestUtil.waitForMessage(mbox1, "in:inbox subject:\"" + subject + "\"");
}
use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.
the class TestLmtp method testStartTLSSuccess.
@Test
public void testStartTLSSuccess() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
LmtpClient lmtpClient = new LmtpClient("localhost", Provisioning.getInstance().getLocalServer().getIntAttr(Provisioning.A_zimbraLmtpBindPort, 7025));
Assert.assertTrue(lmtpClient.getResponse(), lmtpClient.replyOk());
lmtpClient.sendLine("LHLO " + LC.zimbra_server_hostname.value());
Assert.assertTrue(lmtpClient.getResponse(), lmtpClient.replyOk());
if (lmtpClient.getResponse().contains(STARTTLS)) {
lmtpClient.startTLS();
lmtpClient.sendLine("LHLO " + LC.zimbra_server_hostname.value());
Assert.assertTrue(lmtpClient.getResponse(), lmtpClient.replyOk());
}
lmtpClient.sendLine("MAIL FROM:<" + TestUtil.addDomainIfNecessary(USER_NAME) + ">");
Assert.assertTrue(lmtpClient.getResponse(), lmtpClient.replyOk());
lmtpClient.sendLine("RCPT TO:<" + TestUtil.addDomainIfNecessary(USER_NAME) + ">");
Assert.assertTrue(lmtpClient.getResponse(), lmtpClient.replyOk());
lmtpClient.sendLine("DATA");
Assert.assertTrue(lmtpClient.getResponse(), lmtpClient.replyOk());
String subject = NAME_PREFIX + " testFinalDotNotSent";
lmtpClient.sendLine("Subject: " + subject);
lmtpClient.abruptClose();
// wait for some time
Thread.sleep(1000);
List<ZMessage> msgs = TestUtil.search(mbox, "in:inbox " + subject);
Assert.assertTrue("msg got delivered via LMTP even though <CRLF>.<CRLF> was not received", msgs.isEmpty());
}
use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.
the class TestOutOfOffice method testPrefFromAddress.
/**
* Confirms that out-of-office notifications use the user's address preference
* (bug 40869).
*/
public void testPrefFromAddress() throws Exception {
String newFromAddress = TestUtil.getAddress("testPrefFromAddress");
String newFromDisplay = NAME_PREFIX + " testPrefFromAddress";
String newReplyToAddress = TestUtil.getAddress("testReplyToAddress");
String newReplyToDisplay = NAME_PREFIX + " testReplyToAddress";
// Turn on out-of-office.
Account recipient = TestUtil.getAccount(RECIPIENT_NAME);
long now = System.currentTimeMillis();
recipient.setPrefOutOfOfficeFromDate(new Date(now));
recipient.setPrefOutOfOfficeUntilDate(new Date(now + Constants.MILLIS_PER_DAY));
recipient.setPrefOutOfOfficeReplyEnabled(true);
// Don't allow any From address, set display name pref only.
recipient.setAllowAnyFromAddress(false);
recipient.setPrefFromDisplay(newFromDisplay);
recipient.setPrefReplyToAddress(newReplyToAddress);
recipient.setPrefReplyToDisplay(newReplyToDisplay);
recipient.setPrefReplyToEnabled(false);
String subject = NAME_PREFIX + " testPrefFromAddress 1";
ZMailbox senderMbox = TestUtil.getZMailbox(SENDER_NAME);
TestUtil.sendMessage(senderMbox, RECIPIENT_NAME, subject);
ZMessage reply = TestUtil.waitForMessage(senderMbox, "in:inbox subject:\"" + subject + "\"");
// Validate addresses.
ZEmailAddress fromAddress = getAddress(reply, ZEmailAddress.EMAIL_TYPE_FROM);
assertEquals(recipient.getName(), fromAddress.getAddress());
assertEquals(newFromDisplay, fromAddress.getPersonal());
assertNull(getAddress(reply, ZEmailAddress.EMAIL_TYPE_REPLY_TO));
DbOutOfOffice.clear(mConn, mMbox);
mConn.commit();
// Don't allow any From address, set display name, from address, and reply-to prefs.
recipient.setPrefFromAddress(newFromAddress);
recipient.setAllowAnyFromAddress(false);
recipient.setPrefReplyToEnabled(true);
subject = NAME_PREFIX + " testPrefFromAddress 2";
TestUtil.sendMessage(senderMbox, RECIPIENT_NAME, subject);
reply = TestUtil.waitForMessage(senderMbox, "in:inbox subject:\"" + subject + "\"");
// Validate addresses.
fromAddress = getAddress(reply, ZEmailAddress.EMAIL_TYPE_FROM);
assertEquals(recipient.getName(), fromAddress.getAddress());
assertEquals(recipient.getDisplayName(), fromAddress.getPersonal());
ZEmailAddress replyToAddress = getAddress(reply, ZEmailAddress.EMAIL_TYPE_REPLY_TO);
assertEquals(newReplyToAddress, replyToAddress.getAddress());
assertEquals(newReplyToDisplay, replyToAddress.getPersonal());
DbOutOfOffice.clear(mConn, mMbox);
mConn.commit();
// Allow any From address, set display name and address prefs.
recipient.setAllowAnyFromAddress(true);
subject = NAME_PREFIX + " testPrefFromAddress 3";
TestUtil.sendMessage(senderMbox, RECIPIENT_NAME, subject);
reply = TestUtil.waitForMessage(senderMbox, "in:inbox subject:\"" + subject + "\"");
ZimbraLog.test.info("Second reply:\n" + TestUtil.getContent(senderMbox, reply.getId()));
// Validate addresses.
fromAddress = getAddress(reply, ZEmailAddress.EMAIL_TYPE_FROM);
assertEquals(newFromAddress, fromAddress.getAddress());
assertEquals(newFromDisplay, fromAddress.getPersonal());
replyToAddress = getAddress(reply, ZEmailAddress.EMAIL_TYPE_REPLY_TO);
assertEquals(newReplyToAddress, replyToAddress.getAddress());
assertEquals(newReplyToDisplay, replyToAddress.getPersonal());
}
Aggregations