Search in sources :

Example 1 with Options

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;
    }
}
Also used : ParsedMessageOptions(com.zimbra.cs.mime.ParsedMessageOptions) Options(com.zimbra.client.ZMailbox.Options) ZMailbox(com.zimbra.client.ZMailbox) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) AuthToken(com.zimbra.cs.account.AuthToken) ZAuthToken(com.zimbra.common.auth.ZAuthToken)

Example 2 with Options

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);
                }
            }
        }
    }
}
Also used : Account(com.zimbra.cs.account.Account) ParsedMessageOptions(com.zimbra.cs.mime.ParsedMessageOptions) Options(com.zimbra.client.ZMailbox.Options) ZOrganizer(com.zimbra.cs.mailbox.calendar.ZOrganizer) RecurId(com.zimbra.cs.mailbox.calendar.RecurId) IOException(java.io.IOException) SetCalendarItem(com.zimbra.cs.redolog.op.SetCalendarItem) ZMailbox(com.zimbra.client.ZMailbox) RenameMailbox(com.zimbra.cs.redolog.op.RenameMailbox) DbMailbox(com.zimbra.cs.db.DbMailbox) CreateMailbox(com.zimbra.cs.redolog.op.CreateMailbox) ZMailbox(com.zimbra.client.ZMailbox) DeleteMailbox(com.zimbra.cs.redolog.op.DeleteMailbox) StringWriter(java.io.StringWriter) AccountAddressMatcher(com.zimbra.cs.util.AccountUtil.AccountAddressMatcher) AuthToken(com.zimbra.cs.account.AuthToken) ZAuthToken(com.zimbra.common.auth.ZAuthToken) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) CreateInvite(com.zimbra.cs.redolog.op.CreateInvite) Invite(com.zimbra.cs.mailbox.calendar.Invite)

Example 3 with Options

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);
}
Also used : TwoFactorOptions(com.zimbra.common.auth.twofactor.TwoFactorOptions) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Options(com.zimbra.client.ZMailbox.Options) ZMailbox(com.zimbra.client.ZMailbox) Options(com.zimbra.client.ZMailbox.Options)

Example 4 with 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());
    }
}
Also used : Account(com.zimbra.cs.account.Account) Options(com.zimbra.client.ZMailbox.Options) SoapFaultException(com.zimbra.common.soap.SoapFaultException)

Example 5 with Options

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);
}
Also used : TwoFactorOptions(com.zimbra.common.auth.twofactor.TwoFactorOptions) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Options(com.zimbra.client.ZMailbox.Options) ZMailbox(com.zimbra.client.ZMailbox) Options(com.zimbra.client.ZMailbox.Options) ZAuthToken(com.zimbra.common.auth.ZAuthToken)

Aggregations

Options (com.zimbra.client.ZMailbox.Options)6 ZMailbox (com.zimbra.client.ZMailbox)4 ZAuthToken (com.zimbra.common.auth.ZAuthToken)3 TwoFactorOptions (com.zimbra.common.auth.twofactor.TwoFactorOptions)3 DeliveryOptions (com.zimbra.cs.mailbox.DeliveryOptions)3 Account (com.zimbra.cs.account.Account)2 AuthToken (com.zimbra.cs.account.AuthToken)2 ParsedMessageOptions (com.zimbra.cs.mime.ParsedMessageOptions)2 ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)1 ServiceException (com.zimbra.common.service.ServiceException)1 SoapFaultException (com.zimbra.common.soap.SoapFaultException)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 DbMailbox (com.zimbra.cs.db.DbMailbox)1 Invite (com.zimbra.cs.mailbox.calendar.Invite)1 RecurId (com.zimbra.cs.mailbox.calendar.RecurId)1 ZOrganizer (com.zimbra.cs.mailbox.calendar.ZOrganizer)1 CreateInvite (com.zimbra.cs.redolog.op.CreateInvite)1 CreateMailbox (com.zimbra.cs.redolog.op.CreateMailbox)1 DeleteMailbox (com.zimbra.cs.redolog.op.DeleteMailbox)1 RenameMailbox (com.zimbra.cs.redolog.op.RenameMailbox)1