use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class MailItemResource method getZMailbox.
private static ZMailbox getZMailbox(DavContext ctxt, Collection col) throws ServiceException {
AuthToken authToken = AuthProvider.getAuthToken(ctxt.getAuthAccount());
Account acct = Provisioning.getInstance().getAccountById(col.getItemId().getAccountId());
ZMailbox.Options zoptions = new ZMailbox.Options(authToken.toZAuthToken(), AccountUtil.getSoapUri(acct));
zoptions.setNoSession(true);
zoptions.setTargetAccount(acct.getId());
zoptions.setTargetAccountBy(Key.AccountBy.id);
ZMailbox zmbx = ZMailbox.getMailbox(zoptions);
if (zmbx != null) {
zmbx.setName(acct.getName());
/* need this when logging in using another user's auth */
}
return zmbx;
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class MailItemResource method deleteDestinationItem.
private void deleteDestinationItem(DavContext ctxt, Collection dest, int id) throws ServiceException, DavException {
Mailbox mbox = getMailbox(ctxt);
if (dest.getItemId().belongsTo(mbox)) {
mbox.delete(ctxt.getOperationContext(), id, MailItem.Type.UNKNOWN, null);
} else {
ZMailbox zmbx = getZMailbox(ctxt, dest);
ItemId itemId = new ItemId(dest.getItemId().getAccountId(), id);
zmbx.deleteItem(itemId.toString(), null);
}
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class RemoteCollection method getRemoteMailbox.
static ZMailbox getRemoteMailbox(ZAuthToken zat, String ownerId) throws ServiceException {
Account target = Provisioning.getInstance().get(Key.AccountBy.id, ownerId);
if (target == null)
return null;
ZMailbox.Options zoptions = new ZMailbox.Options(zat, AccountUtil.getSoapUri(target));
zoptions.setNoSession(true);
zoptions.setTargetAccount(ownerId);
zoptions.setTargetAccountBy(Key.AccountBy.id);
ZMailbox zmbx = ZMailbox.getMailbox(zoptions);
if (zmbx != null) {
zmbx.setName(target.getName());
/* need this when logging in using another user's auth */
}
return zmbx;
}
use of com.zimbra.client.ZMailbox 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);
}
}
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class ImapCredentials method getImapMailboxStore.
protected ImapMailboxStore getImapMailboxStore() throws ServiceException {
if (mStore != null) {
return mStore;
}
if (mIsLocal && !LC.imap_always_use_remote_store.booleanValue() && ImapDaemon.isRunningImapInsideMailboxd()) {
ZimbraLog.imap.debug("ImapCredentials returning local mailbox store for %s", mAccountId);
return new LocalImapMailboxStore(MailboxManager.getInstance().getMailboxByAccountId(mAccountId));
}
try {
Account acct = getAccount();
ZMailbox.Options options = new ZMailbox.Options(AuthProvider.getAuthToken(acct).getEncoded(), AccountUtil.getSoapUri(acct));
/* getting by ID avoids failed GetInfo SOAP requests trying to determine ID before auth setup. */
options.setTargetAccountBy(AccountBy.id);
options.setTargetAccount(acct.getId());
options.setNoSession(false);
options.setUserAgent("zclient-imap", SystemUtil.getProductVersion());
options.setNotificationFormat(NotificationFormat.IMAP);
options.setAlwaysRefreshFolders(true);
ZMailbox store = ZMailbox.getMailbox(options);
store.setAccountId(acct.getId());
store.setName(acct.getName());
store.setAuthName(acct.getName());
mStore = ImapMailboxStore.get(store, mAccountId);
ZimbraLog.imap.debug("Registering listener with ZMailbox for '%s' [id=%s]", acct.getName(), mAccountId);
store.addEventHandler(zMailboxEventHandler);
return mStore;
} catch (AuthTokenException ate) {
throw ServiceException.FAILURE("error generating auth token", ate);
}
}
Aggregations