use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class AbstractBlobConsistencyCheckTest method allBlobs.
@Test
public void allBlobs() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
int msgs = 10;
for (int i = 0; i < msgs; i++) {
mbox.addMessage(null, new ParsedMessage("From: test1-1@sub1.zimbra.com".getBytes(), false), dopt, null);
}
BlobConsistencyChecker checker = getChecker();
Results results = checker.check(getVolumeIds(), mbox.getId(), true, true);
Assert.assertEquals(0, results.missingBlobs.size());
Assert.assertEquals(0, results.unexpectedBlobs.size());
Assert.assertEquals(msgs, results.usedBlobs.size());
Assert.assertEquals(0, results.incorrectSize.size());
Assert.assertEquals(0, results.incorrectModContent.size());
}
use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class AbstractBlobConsistencyCheckTest method wrongSize.
@Test
public void wrongSize() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
Message msg = mbox.addMessage(null, new ParsedMessage("From: test1-1@sub1.zimbra.com".getBytes(), false), dopt, null);
MailboxBlob blob = msg.getBlob();
String text = "some garbage";
appendText(blob, text);
BlobConsistencyChecker checker = getChecker();
Results results = checker.check(getVolumeIds(), mbox.getId(), true, false);
Assert.assertEquals(0, results.missingBlobs.size());
Assert.assertEquals(0, results.unexpectedBlobs.size());
Assert.assertEquals(0, results.usedBlobs.size());
Assert.assertEquals(1, results.incorrectSize.size());
BlobInfo info = results.incorrectSize.values().iterator().next();
Assert.assertEquals(blob.size + text.length(), (long) info.fileDataSize);
Assert.assertEquals(0, results.incorrectModContent.size());
}
use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class AbstractBlobConsistencyCheckTest method unexpectedBlobs.
@Test
public void unexpectedBlobs() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
String path = createUnexpectedBlob(0);
BlobConsistencyChecker checker = getChecker();
Results results = checker.check(getVolumeIds(), mbox.getId(), true, false);
Assert.assertEquals(0, results.missingBlobs.size());
Assert.assertEquals(1, results.unexpectedBlobs.size());
BlobInfo info = results.unexpectedBlobs.values().iterator().next();
Assert.assertEquals(path, info.path);
Assert.assertEquals(0, results.usedBlobs.size());
Assert.assertEquals(0, results.incorrectSize.size());
Assert.assertEquals(0, results.incorrectModContent.size());
deleteAllBlobs();
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
mbox.addMessage(null, new ParsedMessage("From: test1-1@sub1.zimbra.com".getBytes(), false), dopt, null);
int msgs = 10;
for (int i = 0; i < msgs; i++) {
createUnexpectedBlob(i);
}
results = checker.check(getVolumeIds(), mbox.getId(), true, false);
Assert.assertEquals(0, results.missingBlobs.size());
Assert.assertEquals(msgs, results.unexpectedBlobs.size());
Assert.assertEquals(0, results.usedBlobs.size());
Assert.assertEquals(0, results.incorrectSize.size());
Assert.assertEquals(0, results.incorrectModContent.size());
}
use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class MailItemImport method addMessage.
public Message addMessage(OperationContext octxt, ParsedMessage pm, int size, int folderId, int flags, DeliveryContext dc) throws ServiceException, IOException {
Message msg = null;
CurrentUsage usage = new CurrentUsage(size);
switch(folderId) {
case Mailbox.ID_FOLDER_INBOX:
try {
List<ItemId> addedMessageIds = RuleManager.applyRulesToIncomingMessage(octxt, mbox, pm, size, dataSource.getEmailAddress(), dc, Mailbox.ID_FOLDER_INBOX, true);
Integer newMessageId = getFirstLocalId(addedMessageIds);
if (newMessageId == null) {
// Message was discarded or filed remotely
return null;
} else {
// purgeIfNecessary(octxt, usage, pm);
msg = mbox.getMessageById(null, newMessageId);
}
// Set flags (setting of BITMASK_UNREAD is implicit)
if (flags != Flag.BITMASK_UNREAD) {
// Bug 28275: Cannot set DRAFT flag after message has been created
flags &= ~Flag.BITMASK_DRAFT;
mbox.setTags(octxt, newMessageId, MailItem.Type.MESSAGE, flags, MailItem.TAG_UNCHANGED);
}
} catch (Exception e) {
ZimbraLog.datasource.warn("Error applying filter rules", e);
}
break;
case Mailbox.ID_FOLDER_DRAFTS:
case Mailbox.ID_FOLDER_SENT:
flags |= Flag.BITMASK_FROM_ME;
break;
}
if (msg == null) {
msg = mbox.addMessage(octxt, pm, new DeliveryOptions().setFolderId(folderId).setFlags(flags), null);
}
return msg;
}
use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class FilterUtil method addMessage.
/**
* Adds a message to the given folder. Handles both local folders and mountpoints.
* @return the id of the new message, or <tt>null</tt> if it was a duplicate
*/
public static ItemId addMessage(DeliveryContext context, Mailbox mbox, ParsedMessage pm, String recipient, String folderPath, boolean noICal, int flags, String[] tags, int convId, OperationContext octxt) throws ServiceException {
// Do initial lookup.
Pair<Folder, String> folderAndPath = mbox.getFolderByPathLongestMatch(octxt, Mailbox.ID_FOLDER_USER_ROOT, folderPath);
Folder folder = folderAndPath.getFirst();
String remainingPath = folderAndPath.getSecond();
ZimbraLog.filter.debug("Attempting to file to %s, remainingPath=%s.", folder, remainingPath);
if (folder instanceof Mountpoint) {
Mountpoint mountpoint = (Mountpoint) folder;
ZMailbox remoteMbox = getRemoteZMailbox(mbox, mountpoint);
// Look up remote folder.
String remoteAccountId = mountpoint.getOwnerId();
ItemId id = mountpoint.getTarget();
ZFolder remoteFolder = remoteMbox.getFolderById(id.toString());
if (remoteFolder != null) {
if (remainingPath != null) {
remoteFolder = remoteFolder.getSubFolderByPath(remainingPath);
if (remoteFolder == null) {
String msg = String.format("Subfolder %s of mountpoint %s does not exist.", remainingPath, mountpoint.getName());
throw ServiceException.FAILURE(msg, null);
}
}
}
// File to remote folder.
if (remoteFolder != null) {
byte[] content;
try {
content = pm.getRawData();
} catch (Exception e) {
throw ServiceException.FAILURE("Unable to get message content", e);
}
String msgId = remoteMbox.addMessage(remoteFolder.getId(), com.zimbra.cs.mailbox.Flag.toString(flags), null, 0, content, false);
return new ItemId(msgId, remoteAccountId);
} else {
String msg = String.format("Unable to find remote folder %s for mountpoint %s.", remainingPath, mountpoint.getName());
throw ServiceException.FAILURE(msg, null);
}
} else {
if (!StringUtil.isNullOrEmpty(remainingPath)) {
// Only part of the folder path matched. Auto-create the remaining path.
ZimbraLog.filter.info("Could not find folder %s. Automatically creating it.", folderPath);
folder = mbox.createFolder(octxt, folderPath, new Folder.FolderOptions().setDefaultView(MailItem.Type.MESSAGE));
}
try {
DeliveryOptions dopt = new DeliveryOptions().setFolderId(folder).setNoICal(noICal);
dopt.setFlags(flags).setTags(tags).setConversationId(convId).setRecipientEmail(recipient);
Message msg = mbox.addMessage(octxt, pm, dopt, context);
if (msg == null) {
return null;
} else {
return new ItemId(msg);
}
} catch (IOException e) {
throw ServiceException.FAILURE("Unable to add message", e);
}
}
}
Aggregations