use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class TestMaxMessageSize method testMaxMessageSizeSaveDraft.
/**
* Confirms that
* @throws Exception
*/
@Test
public void testMaxMessageSizeSaveDraft() throws Exception {
setMaxMessageSize(TEST_MAX_MESSAGE_SIZE);
// Upload attachment whose size is 50% of the threshold. If this number
// gets incremented twice, it would exceed the threshold.
Map<String, byte[]> attachments = new HashMap<String, byte[]>();
attachments.put("file1.exe", new byte[(int) (TEST_MAX_MESSAGE_SIZE * 0.5)]);
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
String aid = mbox.uploadAttachments(attachments, 5000);
// Save draft
ZOutgoingMessage outgoing = new ZOutgoingMessage();
List<ZEmailAddress> addresses = new ArrayList<ZEmailAddress>();
addresses.add(new ZEmailAddress(TestUtil.getAddress(USER_NAME), null, null, ZEmailAddress.EMAIL_TYPE_TO));
outgoing.setAddresses(addresses);
outgoing.setAttachmentUploadId(aid);
String subject = NAME_PREFIX + "testMaxMessageSizeSaveDraft";
outgoing.setSubject(subject);
ZMessage draft = mbox.saveDraft(outgoing, null, null);
// Send the draft
outgoing.setAttachmentUploadId(null);
List<AttachedMessagePart> attachedParts = new ArrayList<AttachedMessagePart>();
attachedParts.add(new AttachedMessagePart(draft.getId(), "1", null));
outgoing.setMessagePartsToAttach(attachedParts);
mbox.sendMessage(outgoing, null, false);
TestUtil.waitForMessage(mbox, "in:inbox subject:\"" + subject + "\"");
// Reduce max message size and confirm that the send fails.
setMaxMessageSize((int) (TEST_MAX_MESSAGE_SIZE * 0.6));
try {
mbox.sendMessage(outgoing, null, false);
Assert.fail("Message send should not have succeeded.");
} catch (SoapFaultException e) {
// Message send was not allowed, as expected.
validateMessageTooBigFault(e);
}
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class TestMaxMessageSize method testUploadMaxSize.
@Test
public void testUploadMaxSize() throws Exception {
/*
* bug 27610, default file upload size for messages is now limited by zimbraMtaMaxMessageSize
*/
// TestUtil.setServerAttr(Provisioning.A_zimbraFileUploadMaxSize, "900");
setMaxMessageSize(900);
// Upload an attachment that exceeds the max size
Map<String, byte[]> attachments = new HashMap<String, byte[]>();
attachments.put("file1.exe", new byte[1000]);
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
try {
mbox.uploadAttachments(attachments, 5000);
Assert.fail("Attachment upload should have failed");
} catch (ZClientException e) {
Assert.assertEquals(ZClientException.UPLOAD_SIZE_LIMIT_EXCEEDED, e.getCode());
}
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class GetMiniCal method doRemoteFolders.
private static void doRemoteFolders(ZimbraSoapContext zsc, String remoteAccountId, List<String> remoteFolders, long rangeStart, long rangeEnd, Set<String> busyDates, Element response, Map<ItemId, ItemId> reverseIidMap, ItemIdFormatter ifmt) {
try {
Account target = Provisioning.getInstance().get(Key.AccountBy.id, remoteAccountId);
if (target == null)
throw AccountServiceException.NO_SUCH_ACCOUNT(remoteAccountId);
AuthToken authToken = AuthToken.getCsrfUnsecuredAuthToken(zsc.getAuthToken());
ZMailbox.Options zoptions = new ZMailbox.Options(authToken.toZAuthToken(), AccountUtil.getSoapUri(target));
zoptions.setTargetAccount(remoteAccountId);
zoptions.setTargetAccountBy(AccountBy.id);
zoptions.setNoSession(true);
ZMailbox zmbx = ZMailbox.getMailbox(zoptions);
zmbx.setName(target.getName());
/* need this when logging in using another user's auth */
String[] remoteIds = new String[remoteFolders.size()];
for (int i = 0; i < remoteIds.length; i++) remoteIds[i] = remoteFolders.get(i).toString();
ZGetMiniCalResult result = zmbx.getMiniCal(rangeStart, rangeEnd, remoteIds);
Set<String> dates = result.getDates();
if (dates != null) {
for (String datestamp : dates) {
busyDates.add(datestamp);
}
}
List<ZMiniCalError> errors = result.getErrors();
if (errors != null) {
for (ZMiniCalError error : errors) {
try {
ItemId iid = new ItemId(error.getFolderId(), zsc);
// Error must mention folder id requested by client.
ItemId reqIid = reverseIidMap.get(iid);
String fid = ifmt.formatItemId(reqIid != null ? reqIid : iid);
addError(response, fid, error.getErrCode(), error.getErrMsg());
} catch (ServiceException e) {
}
}
}
} catch (ServiceException e) {
ZimbraLog.calendar.warn("Error making remote GetMiniCalRequest", e);
// Mark all remote folders with the same error.
for (String remoteFid : remoteFolders) {
try {
ItemId iid = new ItemId(remoteFid, zsc);
// Error must mention folder id requested by client.
ItemId reqIid = reverseIidMap.get(iid);
String fid = ifmt.formatItemId(reqIid != null ? reqIid : iid);
addError(response, fid, e.getCode(), e.getMessage());
} catch (ServiceException e2) {
}
}
}
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class TestFilter method testRedirect.
/**
* Tests the redirect filter action and confirms that the X-ZimbraForwarded
* header is set on the redirected message.
*/
@Test
public void testRedirect() throws Exception {
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
// if subject contains "testRedirect", redirect to user2
conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "testRedirect"));
actions.add(new ZRedirectAction(TestUtil.getAddress(REMOTE_USER_NAME)));
rules.add(new ZFilterRule("testRedirect", true, false, conditions, actions));
ZFilterRules zRules = new ZFilterRules(rules);
saveIncomingRules(mMbox, zRules);
// Add a message. Set the From header to something bogus to make
// sure we're not rewriting it
String from = "joebob@mycompany.com";
String subject = NAME_PREFIX + " testRedirect 1";
TestUtil.addMessageLmtp(subject, USER_NAME, from);
// Confirm that user1 did not receive it.
List<ZMessage> messages = TestUtil.search(mMbox, "subject:\"" + subject + "\"");
assertEquals(0, messages.size());
// Confirm that user2 received it, and make sure X-ZimbraForwarded is set.
ZMailbox remoteMbox = TestUtil.getZMailbox(REMOTE_USER_NAME);
ZMessage msg = TestUtil.waitForMessage(remoteMbox, "in:inbox subject:\"" + subject + "\"");
byte[] content = TestUtil.getContent(remoteMbox, msg.getId()).getBytes();
MimeMessage mimeMsg = new MimeMessage(new ByteArrayInputStream(content));
assertEquals(user1.getName(), mimeMsg.getHeader(FilterUtil.HEADER_FORWARDED));
assertEquals(from, mimeMsg.getHeader("From"));
// Check zimbraMailRedirectSetEnvelopeSender=FALSE.
int port = 6025;
DummySmtpServer smtp = startSmtpServer(port);
localServer.setSmtpPort(port);
localServer.setMailRedirectSetEnvelopeSender(false);
TestUtil.addMessageLmtp(subject, USER_NAME, from);
assertEquals(from, smtp.getMailFrom());
// Check zimbraMailRedirectSetEnvelopeSender=TRUE.
smtp = startSmtpServer(port);
localServer.setMailRedirectSetEnvelopeSender(true);
subject = NAME_PREFIX + " testRedirect 2";
TestUtil.addMessageLmtp(subject, USER_NAME, from);
String userAddress = Strings.nullToEmpty(TestUtil.getAddress(USER_NAME)).toLowerCase();
assertEquals("testRedirect 2 mail from", userAddress, smtp.getMailFrom());
// Check empty envelope sender.
smtp = startSmtpServer(port);
subject = NAME_PREFIX + " testRedirect 3";
String msgContent = TestUtil.getTestMessage(subject, USER_NAME, USER_NAME, null);
String[] recipients = new String[] { USER_NAME };
TestUtil.addMessageLmtp(recipients, null, msgContent);
assertTrue(smtp.getMailFrom(), StringUtil.isNullOrEmpty(smtp.getMailFrom()));
// Check Auto-Submitted=yes.
smtp = startSmtpServer(port);
subject = NAME_PREFIX + " testRedirect 4";
msgContent = "Auto-Submitted: yes\r\n" + TestUtil.getTestMessage(subject, USER_NAME, USER_NAME, null);
TestUtil.addMessageLmtp(recipients, USER_NAME, msgContent);
assertTrue(smtp.getMailFrom(), StringUtil.isNullOrEmpty(smtp.getMailFrom()));
// Check Auto-Submitted=no.
smtp = startSmtpServer(port);
subject = NAME_PREFIX + " testRedirect 5";
msgContent = "Auto-Submitted: no\r\n" + TestUtil.getTestMessage(subject, USER_NAME, USER_NAME, null);
TestUtil.addMessageLmtp(recipients, USER_NAME, msgContent);
assertEquals("testRedirect 5 mail from", userAddress, smtp.getMailFrom());
// Check Content-Type=multipart/report.
smtp = startSmtpServer(port);
subject = NAME_PREFIX + " testRedirect 6";
msgContent = TestUtil.getTestMessage(subject, USER_NAME, USER_NAME, null);
msgContent = msgContent.replace("text/plain", "multipart/report");
TestUtil.addMessageLmtp(recipients, USER_NAME, msgContent);
assertTrue(smtp.getMailFrom(), StringUtil.isNullOrEmpty(smtp.getMailFrom()));
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class TestFilter method setUp.
@Before
public void setUp() throws Exception {
cleanUp();
user1 = TestUtil.createAccount(USER_NAME);
TestUtil.createAccount(REMOTE_USER_NAME);
mMbox = TestUtil.getZMailbox(USER_NAME);
mTag1 = mMbox.createTag(TAG1_NAME, null);
mTag2 = mMbox.createTag(TAG2_NAME, null);
Account account = TestUtil.getAccount(USER_NAME);
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraMailSieveScript, "");
attrs.put(Provisioning.A_zimbraMailOutgoingSieveScript, "");
Provisioning.getInstance().modifyAttrs(account, attrs);
// Create mountpoint for testMountpoint()
ZMailbox remoteMbox = TestUtil.getZMailbox(REMOTE_USER_NAME);
TestUtil.createMountpoint(remoteMbox, "/" + MOUNTPOINT_FOLDER_NAME, mMbox, MOUNTPOINT_FOLDER_NAME);
TestUtil.createFolder(remoteMbox, MOUNTPOINT_SUBFOLDER_PATH);
mOriginalIncomingRules = mMbox.getIncomingFilterRules();
saveIncomingRules(mMbox, getTestIncomingRules());
mOriginalOutgoingRules = mMbox.getOutgoingFilterRules();
saveOutgoingRules(mMbox, getTestOutgoingRules());
mOriginalSpamApplyUserFilters = account.getAttr(Provisioning.A_zimbraSpamApplyUserFilters);
mAvailableRFCCompliantNotify = account.isSieveNotifyActionRFCCompliant();
}
Aggregations