Search in sources :

Example 71 with Account

use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.

the class ScheduleOutbox method adjustOrganizer.

/**
     * For Vanilla CalDAV access where Apple style delegation has not been enabled, attempts by the delegate
     * to use a shared calendar acting as themselves are translated to appear as if acting as a delegate,
     * otherwise the experience can be very poor.
     * @throws ServiceException
     */
private void adjustOrganizer(DavContext ctxt, ZCalendar.ZVCalendar cal, ZComponent req, DelegationInfo delegationInfo) throws ServiceException {
    // BusyCal 2.5.3 seems to post with the wrong organizer even if ical delegation is switched on - even though
    // it uses the right ORGANIZER in the calendar entry.
    // if (ctxt.useIcalDelegation()) { return; }
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(ctxt.getAuthAccount());
    String uid = req.getPropVal(ICalTok.UID, null);
    CalendarItem matchingCalendarEntry = mbox.getCalendarItemByUid(ctxt.getOperationContext(), uid);
    if (matchingCalendarEntry == null) {
        List<com.zimbra.cs.mailbox.Mountpoint> sharedCalendars = mbox.getCalendarMountpoints(ctxt.getOperationContext(), SortBy.NONE);
        if (sharedCalendars == null) {
            // Can't work out anything useful
            return;
        }
        Set<Account> accts = Sets.newHashSet();
        for (com.zimbra.cs.mailbox.Mountpoint sharedCalendar : sharedCalendars) {
            accts.add(Provisioning.getInstance().get(AccountBy.id, sharedCalendar.getOwnerId()));
        }
        for (Account acct : accts) {
            Mailbox sbox = MailboxManager.getInstance().getMailboxByAccount(acct);
            matchingCalendarEntry = sbox.getCalendarItemByUid(ctxt.getOperationContext(), uid);
            if (matchingCalendarEntry != null) {
                break;
            }
        }
    }
    if (matchingCalendarEntry == null) {
        return;
    }
    Invite[] invites = matchingCalendarEntry.getInvites();
    if (invites == null) {
        return;
    }
    for (Invite inv : invites) {
        ZOrganizer org = inv.getOrganizer();
        if (org != null) {
            delegationInfo.setOwner(org.getAddress());
            if (Strings.isNullOrEmpty(org.getCn())) {
                Account ownerAcct = Provisioning.getInstance().get(AccountBy.name, org.getAddress());
                if (!Strings.isNullOrEmpty(ownerAcct.getDisplayName())) {
                    delegationInfo.setOwnerCn(ownerAcct.getDisplayName());
                }
            } else {
                delegationInfo.setOwnerCn(org.getCn());
            }
            break;
        }
    }
    if (delegationInfo.getOwner() == null) {
        return;
    }
    AccountAddressMatcher acctMatcher = new AccountAddressMatcher(ctxt.getAuthAccount());
    boolean originatorIsCalEntryOrganizer = acctMatcher.matches(delegationInfo.getOwnerEmail());
    if (originatorIsCalEntryOrganizer) {
        return;
    }
    for (ZComponent component : cal.getComponents()) {
        ZProperty organizerProp = component.getProperty(ICalTok.ORGANIZER);
        if (organizerProp != null) {
            organizerProp.setValue(delegationInfo.getOwner());
            ZParameter cn = organizerProp.getParameter(ICalTok.CN);
            if (cn == null) {
                organizerProp.addParameter(new ZParameter(ICalTok.CN, delegationInfo.getOwnerCn()));
            } else {
                cn.setValue(delegationInfo.getOwnerCn());
            }
            ZParameter sentBy = organizerProp.getParameter(ICalTok.SENT_BY);
            if (sentBy == null) {
                organizerProp.addParameter(new ZParameter(ICalTok.SENT_BY, delegationInfo.getOriginator()));
            } else {
                sentBy.setValue(delegationInfo.getOriginator());
            }
        }
    }
}
Also used : Account(com.zimbra.cs.account.Account) ZOrganizer(com.zimbra.cs.mailbox.calendar.ZOrganizer) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter) CalendarItem(com.zimbra.cs.mailbox.CalendarItem) ZComponent(com.zimbra.common.calendar.ZCalendar.ZComponent) Mailbox(com.zimbra.cs.mailbox.Mailbox) AccountAddressMatcher(com.zimbra.cs.util.AccountUtil.AccountAddressMatcher) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) Invite(com.zimbra.cs.mailbox.calendar.Invite)

Example 72 with Account

use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.

the class SearchWrapper method getChildren.

@Override
public Collection<DavResource> getChildren(DavContext ctxt) {
    ArrayList<DavResource> children = new ArrayList<DavResource>();
    String user = ctxt.getUser();
    Provisioning prov = Provisioning.getInstance();
    ZimbraQueryResults zqr = null;
    try {
        Account account = prov.get(AccountBy.name, user);
        Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
        SearchParams params = new SearchParams();
        params.setQueryString(mQuery.toString());
        params.setTypes(SEARCH_TYPES);
        params.setSortBy(SortBy.NAME_ASC);
        params.setFetchMode(SearchParams.Fetch.NORMAL);
        params.setPrefetch(true);
        params.setChunkSize(SEARCH_LIMIT);
        zqr = mbox.index.search(SoapProtocol.Soap12, ctxt.getOperationContext(), params);
        while (zqr.hasNext()) {
            ZimbraHit hit = zqr.getNext();
            if (hit instanceof MessageHit)
                addAttachmentResources((MessageHit) hit, children);
        }
    } catch (Exception e) {
        ZimbraLog.dav.error("can't search: uri=" + getUri(), e);
    } finally {
        Closeables.closeQuietly(zqr);
    }
    return children;
}
Also used : ZimbraHit(com.zimbra.cs.index.ZimbraHit) Account(com.zimbra.cs.account.Account) SearchParams(com.zimbra.cs.index.SearchParams) Mailbox(com.zimbra.cs.mailbox.Mailbox) MessageHit(com.zimbra.cs.index.MessageHit) ArrayList(java.util.ArrayList) ZimbraQueryResults(com.zimbra.cs.index.ZimbraQueryResults) Provisioning(com.zimbra.cs.account.Provisioning)

Example 73 with Account

use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.

the class UrlNamespace method getMailItemById.

private static MailItem getMailItemById(DavContext ctxt, String user, int id) throws DavException, ServiceException {
    Provisioning prov = Provisioning.getInstance();
    Account account = prov.get(AccountBy.name, user);
    if (account == null) {
        // Anti-account name harvesting.
        ZimbraLog.dav.info("Failing GET of mail item - no such account '%s' id=%d", user, id);
        throw new DavException("Request denied", HttpServletResponse.SC_NOT_FOUND, null);
    }
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
    return mbox.getItemById(ctxt.getOperationContext(), id, MailItem.Type.UNKNOWN);
}
Also used : Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) DavException(com.zimbra.cs.dav.DavException) Provisioning(com.zimbra.cs.account.Provisioning)

Example 74 with Account

use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.

the class UrlNamespace method getFolders.

private static java.util.Collection<DavResource> getFolders(DavContext ctxt, String user) throws ServiceException, DavException {
    Provisioning prov = Provisioning.getInstance();
    Account account = prov.get(AccountBy.name, user);
    if (account == null) {
        // Anti-account name harvesting.
        ZimbraLog.dav.info("Failing GET of folders - no such account '%s'", user);
        throw new DavException("Request denied", HttpServletResponse.SC_NOT_FOUND, null);
    }
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
    OperationContext octxt = ctxt.getOperationContext();
    ArrayList<DavResource> rss = new ArrayList<DavResource>();
    for (Folder f : mbox.getVisibleFolders(octxt)) rss.add(getResourceFromMailItem(ctxt, f));
    return rss;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) DavException(com.zimbra.cs.dav.DavException) ArrayList(java.util.ArrayList) Folder(com.zimbra.cs.mailbox.Folder) Provisioning(com.zimbra.cs.account.Provisioning)

Example 75 with Account

use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.

the class UrlNamespace method getMailItemResource.

/**
     *
     * @param ctxt
     * @param user
     * @param path - May contain parameters
     * @return
     */
private static DavResource getMailItemResource(DavContext ctxt, String user, String path) throws ServiceException, DavException {
    Provisioning prov = Provisioning.getInstance();
    Account account = prov.get(AccountBy.name, user);
    if (account == null) {
        // Anti-account name harvesting.
        ZimbraLog.dav.info("Failing GET of mail item resource - no such account '%s' path '%s'", user, path);
        throw new DavException("Request denied", HttpServletResponse.SC_NOT_FOUND, null);
    }
    if (ctxt.getUser().compareTo(user) != 0 || !Provisioning.onLocalServer(account)) {
        try {
            return new RemoteCollection(ctxt, path, account);
        } catch (MailServiceException.NoSuchItemException e) {
            return null;
        }
    }
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
    int id = 0;
    int index = path.indexOf('?');
    if (index > 0) {
        Map<String, String> params = HttpUtil.getURIParams(path.substring(index + 1));
        path = path.substring(0, index);
        if (params.containsKey("id")) {
            try {
                id = Integer.parseInt(params.get("id"));
            } catch (NumberFormatException e) {
            }
        }
    }
    // At this point, path will have had any parameters stripped from it
    OperationContext octxt = ctxt.getOperationContext();
    MailItem item = null;
    // simple case.  root folder or if id is specified.
    if (path.equals("/")) {
        item = mbox.getFolderByPath(octxt, "/");
    } else if (id > 0) {
        item = mbox.getItemById(octxt, id, MailItem.Type.UNKNOWN);
    }
    if (item != null) {
        return getResourceFromMailItem(ctxt, item);
    }
    // check for named items (folders, documents)
    try {
        return getResourceFromMailItem(ctxt, mbox.getItemByPath(octxt, path));
    } catch (MailServiceException.NoSuchItemException e) {
    }
    // check if the this is renamed folder.
    DavResource rs = checkRenamedResource(user, path);
    if (rs != null)
        return rs;
    // look up the item from path
    if (path.endsWith("/")) {
        path = path.substring(0, path.length() - 1);
    }
    index = path.lastIndexOf('/');
    String folderPath = path.substring(0, index);
    String baseName = path.substring(index + 1);
    Folder f = null;
    if (index != -1) {
        try {
            f = mbox.getFolderByPath(octxt, folderPath);
        } catch (MailServiceException.NoSuchItemException e) {
        }
    }
    if (f != null) {
        /* First check whether the default name has been over-ridden - perhaps because the name was
             * chosen by a DAV client via PUT to a URL when creating the item. */
        DavNames.DavName davName = null;
        if (DebugConfig.enableDAVclientCanChooseResourceBaseName) {
            davName = DavNames.DavName.create(mbox.getId(), f.getId(), baseName);
        }
        if (davName != null) {
            Integer itemId = DavNames.get(davName);
            if (itemId != null) {
                item = mbox.getItemById(octxt, itemId, MailItem.Type.UNKNOWN);
                if ((item != null) && (f.getId() == item.getFolderId())) {
                    return getResourceFromMailItem(ctxt, item);
                }
                item = null;
            }
        }
        if (baseName.toLowerCase().endsWith(CalendarObject.CAL_EXTENSION)) {
            String uid = baseName.substring(0, baseName.length() - CalendarObject.CAL_EXTENSION.length());
            // Unescape the name (It was encoded in DavContext intentionally)
            uid = HttpUtil.urlUnescape(uid);
            index = uid.indexOf(',');
            if (index > 0) {
                try {
                    id = Integer.parseInt(uid.substring(index + 1));
                } catch (NumberFormatException e) {
                }
            }
            if (id > 0) {
                item = mbox.getItemById(octxt, id, MailItem.Type.UNKNOWN);
            } else {
                item = mbox.getCalendarItemByUid(octxt, uid);
            }
            if ((item != null) && (f.getId() != item.getFolderId())) {
                item = null;
            }
        } else if (baseName.toLowerCase().endsWith(AddressObject.VCARD_EXTENSION)) {
            rs = AddressObject.getAddressObjectByUID(ctxt, baseName, account, f);
            if (rs != null) {
                return rs;
            }
        } else if (f.getId() == Mailbox.ID_FOLDER_INBOX || f.getId() == Mailbox.ID_FOLDER_SENT) {
            ctxt.setActingAsDelegateFor(baseName);
            // delegated scheduling and notification handling
            return getResourceFromMailItem(ctxt, f);
        }
    }
    return getResourceFromMailItem(ctxt, item);
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) DavException(com.zimbra.cs.dav.DavException) Folder(com.zimbra.cs.mailbox.Folder) Provisioning(com.zimbra.cs.account.Provisioning) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) DavNames(com.zimbra.cs.mailbox.DavNames) MailItem(com.zimbra.cs.mailbox.MailItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) MailServiceException(com.zimbra.cs.mailbox.MailServiceException)

Aggregations

Account (com.zimbra.cs.account.Account)1244 Test (org.junit.Test)520 Mailbox (com.zimbra.cs.mailbox.Mailbox)389 OperationContext (com.zimbra.cs.mailbox.OperationContext)292 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)274 Message (com.zimbra.cs.mailbox.Message)255 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)242 Provisioning (com.zimbra.cs.account.Provisioning)222 Element (com.zimbra.common.soap.Element)220 ItemId (com.zimbra.cs.service.util.ItemId)219 ServiceException (com.zimbra.common.service.ServiceException)201 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)158 HashMap (java.util.HashMap)154 Domain (com.zimbra.cs.account.Domain)145 MimeMessage (javax.mail.internet.MimeMessage)104 GuestAccount (com.zimbra.cs.account.GuestAccount)98 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)92 AccountServiceException (com.zimbra.cs.account.AccountServiceException)77 ZMailbox (com.zimbra.client.ZMailbox)72 Header (javax.mail.Header)67