use of com.zimbra.cs.session.SoapSession in project zm-mailbox by Zimbra.
the class Mailbox method snapshotCounts.
void snapshotCounts() throws ServiceException {
// for write ops, update the "new messages" count in the DB appropriately
OperationContext octxt = currentChange().octxt;
RedoableOp player = currentChange().getRedoPlayer();
RedoableOp recorder = currentChange().recorder;
if (recorder != null && (player == null || (octxt != null && !octxt.isRedo()))) {
assert (currentChange().writeChange);
boolean isNewMessage = recorder.getOperation() == MailboxOperation.CreateMessage;
if (isNewMessage) {
CreateMessage cm = (CreateMessage) recorder;
if (cm.getFolderId() == ID_FOLDER_SPAM || cm.getFolderId() == ID_FOLDER_TRASH) {
isNewMessage = false;
} else if ((cm.getFlags() & NON_DELIVERY_FLAGS) != 0) {
isNewMessage = false;
} else if (octxt != null && octxt.getSession() != null && !octxt.isDelegatedRequest(this)) {
isNewMessage = false;
}
if (isNewMessage) {
String folderList = getAccount().getPrefMailFoldersCheckedForNewMsgIndicator();
if (folderList != null) {
String[] folderIds = folderList.split(",");
isNewMessage = false;
for (int i = 0; i < folderIds.length; i++) {
if (cm.getFolderId() == Integer.parseInt(folderIds[i])) {
isNewMessage = true;
break;
}
}
}
}
}
if (isNewMessage) {
currentChange().recent = mData.recentMessages + 1;
} else if (octxt != null && mData.recentMessages != 0) {
Session s = octxt.getSession();
if (s instanceof SoapSession || (s instanceof SoapSession.DelegateSession && ((SoapSession.DelegateSession) s).getParentSession().isOfflineSoapSession())) {
currentChange().recent = 0;
}
}
}
if (currentChange().isMailboxRowDirty(mData)) {
assert (currentChange().writeChange);
if (currentChange().recent != MailboxChange.NO_CHANGE) {
ZimbraLog.mailbox.debug("setting recent count to %d", currentChange().recent);
}
DbMailbox.updateMailboxStats(this);
}
boolean foldersTagsDirty = false;
if (currentChange().dirty != null && currentChange().dirty.hasNotifications()) {
assert (currentChange().writeChange);
if (currentChange().dirty.created != null) {
for (MailItem item : currentChange().dirty.created.values()) {
if (item instanceof Folder) {
foldersTagsDirty = true;
if (item.getSize() != 0) {
((Folder) item).saveFolderCounts(false);
}
} else if (item instanceof Tag) {
foldersTagsDirty = true;
if (item.isUnread()) {
((Tag) item).saveTagCounts();
}
}
}
}
if (currentChange().dirty.modified != null) {
for (Change change : currentChange().dirty.modified.values()) {
if (change.what instanceof Folder) {
foldersTagsDirty = true;
if ((change.why & (Change.UNREAD | Change.SIZE)) != 0) {
((Folder) change.what).saveFolderCounts(false);
}
} else if (change.what instanceof Tag) {
foldersTagsDirty = true;
if ((change.why & Change.UNREAD | Change.SIZE) != 0) {
((Tag) change.what).saveTagCounts();
}
} else if ((change.what instanceof MailItem)) {
if (change.what instanceof Conversation) {
uncache((MailItem) change.what);
} else {
cache((MailItem) change.what);
}
}
}
}
if (currentChange().dirty.deleted != null) {
for (Change change : currentChange().dirty.deleted.values()) {
if (change.what instanceof Folder || change.what instanceof Tag) {
foldersTagsDirty = true;
break;
}
}
}
if (foldersTagsDirty) {
cacheFoldersTagsToMemcached();
}
}
if (DebugConfig.checkMailboxCacheConsistency && currentChange().dirty != null && currentChange().dirty.hasNotifications()) {
if (currentChange().dirty.created != null) {
for (MailItem item : currentChange().dirty.created.values()) {
DbMailItem.consistencyCheck(item, item.mData, item.encodeMetadata().toString());
}
}
if (currentChange().dirty.modified != null) {
for (Change change : currentChange().dirty.modified.values()) {
if (change.what instanceof MailItem) {
MailItem item = (MailItem) change.what;
DbMailItem.consistencyCheck(item, item.mData, item.encodeMetadata().toString());
}
}
}
}
}
use of com.zimbra.cs.session.SoapSession in project zm-mailbox by Zimbra.
the class DocumentHandler method proxyWithNotification.
public static Element proxyWithNotification(Element request, ProxyTarget proxy, ZimbraSoapContext zscProxy, Session localSession) throws ServiceException {
Server server = proxy.getServer();
boolean isLocal = getLocalHostId().equalsIgnoreCase(server.getId());
if (isLocal) {
zscProxy.resetProxyAuthToken();
}
if (zscProxy.isNotificationEnabled()) {
// if we've got a SOAP session, make sure to use the appropriate remote session ID
if (localSession instanceof SoapSession.DelegateSession) {
localSession = ((SoapSession.DelegateSession) localSession).getParentSession();
}
// note that requests proxied to *this same host* shouldn't request notification, as the existing local session collects the notifications
if (!(localSession instanceof SoapSession) || localSession.getMailbox() == null) {
zscProxy.disableNotifications();
} else if (!isLocal) {
zscProxy.setProxySession(((SoapSession) localSession).getRemoteSessionId(server));
} else {
zscProxy.setProxySession(localSession.getSessionId());
}
}
Pair<Element, Element> envelope = proxy.execute(request, zscProxy);
// if we've got a SOAP session, handle the returned notifications and session ID
if (localSession instanceof SoapSession && zscProxy.isNotificationEnabled())
((SoapSession) localSession).handleRemoteNotifications(server, envelope.getFirst());
return envelope.getSecond().detach();
}
use of com.zimbra.cs.session.SoapSession in project zm-mailbox by Zimbra.
the class ItemAction method forceRemoteSession.
private Account forceRemoteSession(ZimbraSoapContext zsc, Map<String, Object> context, OperationContext octxt, String op, Element action) throws ServiceException {
// only proxying notification from the user's home-server master session
if (!zsc.isNotificationEnabled()) {
return null;
}
Session session = (Session) context.get(SoapEngine.ZIMBRA_SESSION);
if (session instanceof SoapSession.DelegateSession) {
session = ((SoapSession.DelegateSession) session).getParentSession();
}
if (!(session instanceof SoapSession) || session.getMailbox() == null) {
return null;
}
SoapSession ss = (SoapSession) session;
// only have to worry about operations where things can get created in other mailboxes (regular notification works for all other cases)
if (!op.equals(OP_MOVE) && !op.equals(OP_COPY) && !op.equals(OP_SPAM) && !op.equals(OP_RENAME) && !op.equals(OP_UPDATE)) {
return null;
}
String folderStr = action.getAttribute(MailConstants.A_FOLDER, null);
if (folderStr == null) {
return null;
}
// recursively dereference mountpoints to find ultimate target folder
ItemId iidFolder = new ItemId(folderStr, zsc), iidRequested = iidFolder;
Account owner = null;
int hopCount = 0;
ZAuthToken zat = null;
while (hopCount < ZimbraSoapContext.MAX_HOP_COUNT) {
owner = Provisioning.getInstance().getAccountById(iidFolder.getAccountId());
if (Provisioning.onLocalServer(owner)) {
try {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(owner);
Folder folder = mbox.getFolderById(octxt, iidFolder.getId());
if (!(folder instanceof Mountpoint))
break;
iidFolder = ((Mountpoint) folder).getTarget();
} catch (ServiceException e) {
// could be a PERM_DENIED, could be something else -- this is not the right place to fail, however
break;
}
} else {
if (zat == null) {
AuthToken at = AuthToken.getCsrfUnsecuredAuthToken(zsc.getAuthToken());
String pxyAuthToken = at.getProxyAuthToken();
zat = pxyAuthToken == null ? at.toZAuthToken() : new ZAuthToken(pxyAuthToken);
}
ZMailbox.Options zoptions = new ZMailbox.Options(zat, AccountUtil.getSoapUri(owner));
zoptions.setNoSession(true);
zoptions.setTargetAccount(owner.getId());
zoptions.setTargetAccountBy(Key.AccountBy.id);
ZMailbox zmbx = ZMailbox.getMailbox(zoptions);
ZFolder zfolder = zmbx.getFolderById(iidFolder.toString(zsc.getAuthtokenAccountId()));
if (!(zfolder instanceof ZMountpoint))
break;
iidFolder = new ItemId(((ZMountpoint) zfolder).getCanonicalRemoteId(), zsc.getAuthtokenAccountId());
}
hopCount++;
}
if (hopCount >= ZimbraSoapContext.MAX_HOP_COUNT) {
throw MailServiceException.TOO_MANY_HOPS(iidRequested);
}
// avoid dereferencing the mountpoint again later on
action.addAttribute(MailConstants.A_FOLDER, iidFolder.toString());
// fault in a session to listen in on the target folder's mailbox
if (iidFolder.belongsTo(session.getAuthenticatedAccountId())) {
return null;
} else if (iidFolder.isLocal()) {
ss.getDelegateSession(iidFolder.getAccountId());
return null;
} else {
try {
proxyRequest(zsc.createElement(MailConstants.NO_OP_REQUEST), context, owner.getId());
return owner;
} catch (ServiceException e) {
return null;
}
}
}
Aggregations