use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class ImapSessionManager method waitForWaitSetNotifications.
private void waitForWaitSetNotifications(ImapMailboxStore imapStore, FolderStore folder, ImapRemoteSession irs) {
ZMailbox sessMboxStore = (ZMailbox) irs.getMailbox();
if (sessMboxStore.isUsingSession()) {
return;
/* can rely on SOAP notifications */
}
LastChange zmboxLastKnownChange = sessMboxStore.getLastChange();
if (irs.getLastKnownChangeId() >= zmboxLastKnownChange.getId()) {
return;
/* WaitSet based notifications at least as current as anything we've done */
}
long start = System.currentTimeMillis();
ImapServerListener svrListener = imapStore.getServerListener(folder.getFolderItemIdentifier());
if (svrListener == null) {
return;
}
// Should be rare to have to wait for much of this time
long timeout = LC.imap_max_time_to_wait_for_catchup_millis.longValue();
if (zmboxLastKnownChange.getTime() != 0) {
if (start - zmboxLastKnownChange.getTime() >= timeout) {
ZimbraLog.imap.debug("ImapSessionManager.waitForWaitSetNotifications known a long time");
return;
}
timeout = timeout - (start - zmboxLastKnownChange.getTime());
}
CountDownLatch doneSignal = new CountDownLatch(1);
svrListener.addNotifyWhenCaughtUp(imapStore.getAccountId(), zmboxLastKnownChange.getId(), doneSignal);
try {
doneSignal.await(timeout, TimeUnit.MILLISECONDS);
} catch (InterruptedException ie) {
}
ZimbraLog.imap.debug("ImapSessionManager.waitForWaitSetNotifications folder=%s mboxCID=%s irsCID=%s timeout=%s %s", folder, zmboxLastKnownChange, irs.getLastKnownChangeId(), timeout, ZimbraLog.elapsedTime(start, System.currentTimeMillis()));
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class ImapSessionManager method getSessionForFolder.
/**
* Choose the listener which knows about the most recent change, preferring ones associated with
* a ZMailbox which is using a session, so that we know that our cache will be up to date to that
* change in that case.
*/
private static ImapListener getSessionForFolder(int folderId, List<ImapListener> sessionList) {
List<ImapListener> listeners = getSessionsForFolder(folderId, sessionList);
if (listeners.isEmpty()) {
return null;
}
int lastKnownChangeId = -1;
ImapListener bestListener = null;
boolean usingSession = false;
for (ImapListener i4listener : listeners) {
if (i4listener instanceof ImapRemoteSession) {
ImapRemoteSession irs = (ImapRemoteSession) i4listener;
ZMailbox zmbox = (ZMailbox) irs.getMailbox();
int zmLastKnownChangeId = zmbox.getLastChangeID();
if (zmLastKnownChangeId > lastKnownChangeId) {
bestListener = i4listener;
usingSession = zmbox.isUsingSession();
} else if ((zmLastKnownChangeId == lastKnownChangeId) && !usingSession) {
bestListener = i4listener;
usingSession = zmbox.isUsingSession();
}
}
}
return bestListener != null ? bestListener : listeners.get(0);
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class Mailbox method processICalReplies.
private void processICalReplies(OperationContext octxt, ZVCalendar cal, String sender) throws ServiceException {
// Reply from Outlook will usually have PRODID set to the following:
//
// Outlook2007+ZCO: PRODID:-//Microsoft Corporation//Outlook 12.0 MIMEDIR//EN
// Outlook2010+ZCO: PRODID:-//Microsoft Corporation//Outlook 14.0 MIMEDIR//EN
// Outlook20xx+Exchange: PRODID:Microsoft Exchange Server 2007
// (if Exchange is Exchange 2007; Exchange 2010 probably works similarly)
//
// Lowest common denominator is "Microsoft" substring.
String prodId = cal.getPropVal(ICalTok.PRODID, null);
boolean fromOutlook = prodId != null && prodId.toLowerCase().contains("microsoft");
AccountAddressMatcher acctMatcher = new AccountAddressMatcher(getAccount());
List<Invite> components = Invite.createFromCalendar(getAccount(), null, cal, false);
for (Invite inv : components) {
String orgAddress;
if (inv.hasOrganizer()) {
ZOrganizer org = inv.getOrganizer();
orgAddress = org.getAddress();
} else {
ZimbraLog.calendar.warn("No ORGANIZER found in REPLY. Assuming current mailbox.");
orgAddress = getAccount().getName();
}
if (acctMatcher.matches(orgAddress)) {
// RECURRENCE-ID.
if (fromOutlook && !inv.isAllDayEvent() && inv.hasRecurId()) {
RecurId rid = inv.getRecurId();
if (rid.getDt() != null && rid.getDt().hasZeroTime()) {
CalendarItem calItem = getCalendarItemByUid(octxt, inv.getUid());
if (calItem != null) {
Invite seriesInv = calItem.getDefaultInviteOrNull();
if (seriesInv != null) {
ParsedDateTime seriesDtStart = seriesInv.getStartTime();
if (seriesDtStart != null) {
ParsedDateTime fixedDt = seriesDtStart.cloneWithNewDate(rid.getDt());
RecurId fixedRid = new RecurId(fixedDt, rid.getRange());
ZimbraLog.calendar.debug("Fixed up invalid RECURRENCE-ID with zero time; before=[%s], after=[%s]", rid, fixedRid);
inv.setRecurId(fixedRid);
}
}
}
}
}
processICalReply(octxt, inv, sender);
} else {
Account orgAccount = inv.getOrganizerAccount();
// Unknown organizer
if (orgAccount == null) {
ZimbraLog.calendar.warn("Unknown organizer " + orgAddress + " in REPLY");
continue;
}
if (Provisioning.onLocalServer(orgAccount)) {
// Run in the context of organizer's mailbox.
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(orgAccount);
OperationContext orgOctxt = new OperationContext(mbox);
mbox.processICalReply(orgOctxt, inv, sender);
} else {
// Organizer's mailbox is on a remote server.
String uri = AccountUtil.getSoapUri(orgAccount);
if (uri == null) {
ZimbraLog.calendar.warn("Unable to determine URI for organizer account %s", orgAddress);
continue;
}
try {
// TODO: Get the iCalendar data from the
// MIME part since we already have it.
String ical;
StringWriter sr = null;
try {
sr = new StringWriter();
inv.setMethod(ICalTok.REPLY.toString());
inv.newToICalendar(true).toICalendar(sr);
ical = sr.toString();
} finally {
if (sr != null) {
sr.close();
}
}
Options options = new Options();
AuthToken authToken = AuthToken.getCsrfUnsecuredAuthToken(getAuthToken(octxt));
options.setAuthToken(authToken.toZAuthToken());
options.setTargetAccount(orgAccount.getName());
options.setTargetAccountBy(AccountBy.name);
options.setUri(uri);
options.setNoSession(true);
ZMailbox zmbox = ZMailbox.getMailbox(options);
zmbox.setAccountId(orgAccount.getId());
zmbox.iCalReply(ical, sender);
} catch (IOException e) {
throw ServiceException.FAILURE("Error while posting REPLY to organizer mailbox host", e);
}
}
}
}
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class Mailbox method refreshMountpoint.
/**
* Updates the remote owner and item id stored in the mountpoint to match the current location of the
* target folder. The target folder is identified by the remote UUID stored in the mountpoint's metadata.
* @param octxt
* @param mountpointId item id of the Mountpoint
* @return
* @throws ServiceException
*/
public Mountpoint refreshMountpoint(OperationContext octxt, int mountpointId) throws ServiceException {
Mountpoint mp = getMountpointById(octxt, mountpointId);
Provisioning prov = Provisioning.getInstance();
ShareLocator shloc = prov.getShareLocatorById(mp.getRemoteUuid());
if (shloc == null || mp.getOwnerId().equalsIgnoreCase(shloc.getShareOwnerAccountId())) {
// Share apparently did not move.
return mp;
}
// Look up remote folder by UUID to discover the new numeric id.
Account shareOwner = Provisioning.getInstance().get(Key.AccountBy.id, shloc.getShareOwnerAccountId());
AuthToken at = AuthToken.getCsrfUnsecuredAuthToken(octxt.getAuthToken());
String pxyAuthToken = Provisioning.onLocalServer(shareOwner) ? null : at.getProxyAuthToken();
ZAuthToken zat = null;
if (pxyAuthToken == null) {
zat = at.toZAuthToken();
zat.resetProxyAuthToken();
} else {
zat = new ZAuthToken(pxyAuthToken);
}
ZMailbox.Options zoptions = new ZMailbox.Options(zat, AccountUtil.getSoapUri(shareOwner));
zoptions.setNoSession(true);
zoptions.setTargetAccount(shareOwner.getId());
zoptions.setTargetAccountBy(Key.AccountBy.id);
ZMailbox zmbx = ZMailbox.getMailbox(zoptions);
zmbx.setName(shareOwner.getName());
/* need this when logging in using another user's auth */
ZFolder zfolder = zmbx.getFolderByUuid(shloc.getUuid());
if (zfolder != null) {
ItemId fid = new ItemId(zfolder.getId(), shareOwner.getId());
return refreshMountpoint(octxt, mountpointId, shareOwner.getId(), fid.getId());
} else {
return null;
}
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class Mailbox method getRemoteCalItemByUID.
public com.zimbra.soap.mail.type.CalendarItemInfo getRemoteCalItemByUID(Account ownerAccount, String uid, boolean includeInvites, boolean includeContent) throws ServiceException {
Options options = new Options();
AuthToken authToken = AuthToken.getCsrfUnsecuredAuthToken(getAuthToken(getOperationContext()));
options.setAuthToken(authToken.toZAuthToken());
options.setTargetAccount(getAccount().getName());
options.setTargetAccountBy(AccountBy.name);
options.setUri(AccountUtil.getSoapUri(ownerAccount));
options.setNoSession(true);
ZMailbox zmbox = ZMailbox.getMailbox(options);
try {
return zmbox.getRemoteCalItemByUID(ownerAccount.getId(), uid, includeInvites, includeContent);
} catch (ServiceException e) {
String exceptionCode = e.getCode();
if (exceptionCode.equals(AccountServiceException.NO_SUCH_ACCOUNT) || exceptionCode.equals(MailServiceException.NO_SUCH_CALITEM)) {
ZimbraLog.calendar.debug("Either remote acct or calendar item not found [%s]", exceptionCode);
} else {
ZimbraLog.calendar.debug("Unexpected exception thrown when getting remote calendar item - ignoring", e);
}
return null;
}
}
Aggregations