use of com.zimbra.client.ZMailbox.Options 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;
}
}
use of com.zimbra.client.ZMailbox.Options 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.iCalReply(ical, sender);
} catch (IOException e) {
throw ServiceException.FAILURE("Error while posting REPLY to organizer mailbox host", e);
}
}
}
}
}
use of com.zimbra.client.ZMailbox.Options in project zm-mailbox by Zimbra.
the class TestUtil method getZMailbox.
public static ZMailbox getZMailbox(String username, String twoFactorCode, TrustedStatus trusted) throws ServiceException {
ZMailbox.Options options = new ZMailbox.Options();
options.setAccount(getAddress(username));
options.setAccountBy(Key.AccountBy.name);
options.setPassword(DEFAULT_PASSWORD);
options.setUri(TestUtil.getSoapUrl());
if (twoFactorCode != null) {
options.setTwoFactorCode(twoFactorCode);
}
if (trusted == TrustedStatus.trusted) {
options.setTrustedDevice(true);
}
return ZMailbox.getMailbox(options);
}
use of com.zimbra.client.ZMailbox.Options in project zm-mailbox by Zimbra.
the class TestZClient method testChangePassword.
public void testChangePassword() throws Exception {
Account account = TestUtil.getAccount(USER_NAME);
Options options = new Options();
options.setAccount(account.getName());
options.setAccountBy(AccountBy.name);
options.setPassword(TestUtil.DEFAULT_PASSWORD);
options.setNewPassword("test456");
options.setUri(TestUtil.getSoapUrl());
ZMailbox.changePassword(options);
try {
TestUtil.getZMailbox(USER_NAME);
} catch (SoapFaultException e) {
assertEquals(AuthFailedServiceException.AUTH_FAILED, e.getCode());
}
}
use of com.zimbra.client.ZMailbox.Options in project zm-mailbox by Zimbra.
the class TestUtil method getZMailboxAsAdmin.
public static ZMailbox getZMailboxAsAdmin(String username) throws ServiceException {
ZAuthToken adminAuthToken = newSoapProvisioning().getAuthToken();
ZMailbox.Options options = new ZMailbox.Options(adminAuthToken, getSoapUrl());
options.setTargetAccount(getAddress(username));
options.setTargetAccountBy(AccountBy.name);
return ZMailbox.getMailbox(options);
}
Aggregations