Search in sources :

Example 61 with Account

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

the class BrowseWrapper method browseByType.

private List<DavResource> browseByType(DavContext ctxt) throws IOException, ServiceException {
    ArrayList<DavResource> res = new ArrayList<DavResource>();
    String user = ctxt.getUser();
    Provisioning prov = Provisioning.getInstance();
    Account account = prov.get(AccountBy.name, user);
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
    List<BrowseTerm> terms = mbox.browse(ctxt.getOperationContext(), Mailbox.BrowseBy.attachments, "", 0);
    for (BrowseTerm term : terms) {
        String ctype = term.getText();
        int index = ctype.indexOf('/');
        if (index != -1 || ctype.equals("message") || ctype.equals("none")) {
            continue;
        // the client still gets confused about having a slash in the
        // path even after encoding
        //ctype = ctype.substring(0,index) + "%2F" + ctype.substring(index+1);
        }
        res.add(new BrowseWrapper(generateUri(ctype), getOwner()));
    }
    res.add(new BrowseWrapper(generateUri("word"), getOwner()));
    res.add(new BrowseWrapper(generateUri("excel"), getOwner()));
    res.add(new BrowseWrapper(generateUri("ppt"), getOwner()));
    res.add(new BrowseWrapper(generateUri("pdf"), getOwner()));
    return res;
}
Also used : Account(com.zimbra.cs.account.Account) DomainBrowseTerm(com.zimbra.cs.index.DomainBrowseTerm) BrowseTerm(com.zimbra.cs.index.BrowseTerm) Mailbox(com.zimbra.cs.mailbox.Mailbox) ArrayList(java.util.ArrayList) Provisioning(com.zimbra.cs.account.Provisioning)

Example 62 with Account

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

the class ScheduleOutbox method handlePost.

@Override
public void handlePost(DavContext ctxt) throws DavException, IOException, ServiceException {
    DelegationInfo delegationInfo = new DelegationInfo(ctxt.getRequest().getHeader(DavProtocol.HEADER_ORIGINATOR));
    Enumeration<String> recipients = ctxt.getRequest().getHeaders(DavProtocol.HEADER_RECIPIENT);
    InputStream in = ctxt.getUpload().getInputStream();
    ZCalendar.ZVCalendar vcalendar = ZCalendar.ZCalendarBuilder.build(in, MimeConstants.P_CHARSET_UTF8);
    Closeables.closeQuietly(in);
    Iterator<ZComponent> iter = vcalendar.getComponentIterator();
    ZComponent req = null;
    while (iter.hasNext()) {
        req = iter.next();
        if (req.getTok() != ICalTok.VTIMEZONE)
            break;
        req = null;
    }
    if (req == null) {
        throw new DavException("empty request", HttpServletResponse.SC_BAD_REQUEST);
    }
    ZimbraLog.dav.debug("originator: %s", delegationInfo.getOriginator());
    boolean isVEventOrVTodo = ICalTok.VEVENT.equals(req.getTok()) || ICalTok.VTODO.equals(req.getTok());
    boolean isOrganizerMethod = false, isCancel = false;
    if (isVEventOrVTodo) {
        String method = vcalendar.getPropVal(ICalTok.METHOD, null);
        if (method != null) {
            isOrganizerMethod = Invite.isOrganizerMethod(method);
            isCancel = ICalTok.CANCEL.toString().equalsIgnoreCase(method);
            ;
        }
        // Apple iCal fixup
        CalDavUtils.removeAttendeeForOrganizer(req);
    }
    // Get organizer and list of attendees. (mailto:email values)
    ArrayList<String> attendees = new ArrayList<String>();
    String organizer = null;
    for (Iterator<ZProperty> propsIter = req.getPropertyIterator(); propsIter.hasNext(); ) {
        ZProperty prop = propsIter.next();
        ICalTok token = prop.getToken();
        if (ICalTok.ATTENDEE.equals(token)) {
            String val = prop.getValue();
            if (val != null) {
                attendees.add(val.trim());
            }
        } else if (ICalTok.ORGANIZER.equals(token)) {
            String val = prop.getValue();
            if (val != null) {
                organizer = val.trim();
                String addr = CalDavUtils.stripMailto(organizer);
                // Rewrite the alias to primary address
                Account acct = Provisioning.getInstance().get(AccountBy.name, addr);
                if (acct != null) {
                    String newAddr = acct.getName();
                    if (!addr.equals(newAddr)) {
                        organizer = "mailto:" + newAddr;
                        prop.setValue(organizer);
                    }
                }
            }
        }
    }
    // Apple iCal is very inconsistent about the user's identity when the account has aliases.
    if (isVEventOrVTodo && delegationInfo.getOriginator() != null && ctxt.getAuthAccount() != null) {
        AccountAddressMatcher acctMatcher = new AccountAddressMatcher(ctxt.getAuthAccount());
        if (acctMatcher.matches(delegationInfo.getOriginatorEmail())) {
            if (isOrganizerMethod) {
                if (organizer != null) {
                    String organizerEmail = CalDavUtils.stripMailto(organizer);
                    if (!organizerEmail.equalsIgnoreCase(delegationInfo.getOriginatorEmail()) && acctMatcher.matches(organizerEmail)) {
                        delegationInfo.setOriginator(organizer);
                        ZimbraLog.dav.debug("changing originator to %s to match address/alias used in ORGANIZER", delegationInfo.getOriginator());
                    }
                }
            } else {
                for (String at : attendees) {
                    String atEmail = CalDavUtils.stripMailto(at);
                    if (delegationInfo.getOriginatorEmail().equalsIgnoreCase(atEmail)) {
                        break;
                    } else if (acctMatcher.matches(atEmail)) {
                        delegationInfo.setOriginator(at);
                        ZimbraLog.dav.debug("changing originator to %s to match address/alias used in ATTENDEE", delegationInfo.getOriginator());
                        break;
                    }
                }
            }
        }
    }
    // Get the recipients.
    ArrayList<String> rcptArray = new ArrayList<String>();
    while (recipients.hasMoreElements()) {
        String rcptHdr = recipients.nextElement();
        String[] rcpts = null;
        if (rcptHdr.indexOf(',') > 0) {
            rcpts = rcptHdr.split(",");
        } else {
            rcpts = new String[] { rcptHdr };
        }
        for (String rcpt : rcpts) {
            if (rcpt != null) {
                rcpt = rcpt.trim();
                if (rcpt.length() != 0) {
                    // Workaround for Apple iCal: Ignore attendees with address "invalid:nomail".
                    if (rcpt.equalsIgnoreCase("invalid:nomail")) {
                        continue;
                    }
                    if (isVEventOrVTodo) {
                        // iCal can sometimes do that when organizer account has aliases.
                        if (isOrganizerMethod && rcpt.equalsIgnoreCase(organizer)) {
                            continue;
                        }
                        // as ATTENDEE in the CANCEL component being sent.  (iCal does that part correctly, at least.)
                        if (isCancel) {
                            boolean isAttendee = false;
                            // Rcpt must be an attendee of the cancel component.
                            for (String at : attendees) {
                                if (rcpt.equalsIgnoreCase(at)) {
                                    isAttendee = true;
                                    break;
                                }
                            }
                            if (!isAttendee) {
                                ZimbraLog.dav.info("Ignoring non-attendee recipient '%s' of CANCEL request; likely a client bug", rcpt);
                                continue;
                            }
                        }
                    }
                    // All checks passed.
                    rcptArray.add(rcpt);
                }
            }
        }
    }
    Element scheduleResponse = ctxt.getDavResponse().getTop(DavElements.E_SCHEDULE_RESPONSE);
    for (String rcpt : rcptArray) {
        ZimbraLog.dav.debug("recipient email: " + rcpt);
        Element resp = scheduleResponse.addElement(DavElements.E_CALDAV_RESPONSE);
        switch(req.getTok()) {
            case VFREEBUSY:
                handleFreebusyRequest(ctxt, req, delegationInfo.getOriginator(), rcpt, resp);
                break;
            case VEVENT:
                // records.
                if (isOrganizerMethod) {
                    adjustOrganizer(ctxt, vcalendar, req, delegationInfo);
                }
                validateRequest(isOrganizerMethod, delegationInfo, organizer, ctxt, req);
                handleEventRequest(ctxt, vcalendar, req, delegationInfo, rcpt, resp);
                break;
            default:
                throw new DavException("unrecognized request: " + req.getTok(), HttpServletResponse.SC_BAD_REQUEST);
        }
    }
}
Also used : Account(com.zimbra.cs.account.Account) DavException(com.zimbra.cs.dav.DavException) InputStream(java.io.InputStream) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) ICalTok(com.zimbra.common.calendar.ZCalendar.ICalTok) ZCalendar(com.zimbra.common.calendar.ZCalendar) ZComponent(com.zimbra.common.calendar.ZCalendar.ZComponent) AccountAddressMatcher(com.zimbra.cs.util.AccountUtil.AccountAddressMatcher) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty)

Example 63 with Account

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

the class ScheduleOutbox method validateRequest.

/**
     * Check for illegal requests like trying to CANCEL a meeting when not the organizer or a delegate for
     * the organizer
     * e.g. Bug 85875 Mac OS X/10.8.5 Calendar sometimes sending CANCEL when ATTENDEE deletes an instance,
     *      resulting in other attendees getting invalid CANCELs
     */
private void validateRequest(boolean isOrganizerMethod, DelegationInfo delegationInfo, String organizer, DavContext ctxt, ZComponent req) throws ServiceException, DavException {
    if ((!isOrganizerMethod) || (organizer != null && organizer.equals(delegationInfo.getOriginator()))) {
        return;
    }
    // If here, only the ORGANIZER or a delegate acting as the ORGANIZER should be able to do this
    AccountAddressMatcher acctMatcher = new AccountAddressMatcher(ctxt.getAuthAccount());
    if (!acctMatcher.matches(delegationInfo.getOriginatorEmail())) {
        throw new DavException(String.format("invalid POST to scheduling outbox '%s'. originator '%s' is not authorized account or ORGANIZER", ctxt.getRequest().getRequestURI(), delegationInfo.getOriginatorEmail()), HttpServletResponse.SC_BAD_REQUEST);
    }
    String organizerEmail = CalDavUtils.stripMailto(organizer);
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(ctxt.getAuthAccount());
    List<com.zimbra.cs.mailbox.Mountpoint> sharedCalendars = mbox.getCalendarMountpoints(ctxt.getOperationContext(), SortBy.NONE);
    if (sharedCalendars != null) {
        for (com.zimbra.cs.mailbox.Mountpoint sharedCalendar : sharedCalendars) {
            Account acct = Provisioning.getInstance().get(AccountBy.id, sharedCalendar.getOwnerId());
            if (acct != null) {
                acctMatcher = new AccountAddressMatcher(acct);
                if (acctMatcher.matches(organizerEmail)) {
                    return;
                }
            }
        }
    }
    // We haven't found a shared calendar for the ORGANIZER that we are a delegate for.
    throw new DavException(String.format("invalid POST to scheduling outbox '%s'. '%s' cannot act as ORGANIZER '%s'", ctxt.getRequest().getRequestURI(), delegationInfo.getOriginatorEmail(), organizerEmail), HttpServletResponse.SC_BAD_REQUEST);
}
Also used : Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) DavException(com.zimbra.cs.dav.DavException) AccountAddressMatcher(com.zimbra.cs.util.AccountUtil.AccountAddressMatcher)

Example 64 with Account

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

the class ProxyGroupMembership method toElement.

@Override
public Element toElement(DavContext ctxt, Element parent, boolean nameOnly) {
    Element group = super.toElement(ctxt, parent, true);
    if (nameOnly) {
        return group;
    }
    ArrayList<Pair<Mountpoint, ZFolder>> mps = getMountpoints(ctxt);
    for (Pair<Mountpoint, ZFolder> folder : mps) {
        try {
            short rights = ACL.stringToRights(folder.getSecond().getEffectivePerms());
            if ((rights & ACL.RIGHT_WRITE) > 0) {
                Account owner = Provisioning.getInstance().get(AccountBy.id, folder.getFirst().getOwnerId());
                if (owner != null) {
                    group.addElement(DavElements.E_HREF).setText(UrlNamespace.getCalendarProxyWriteUrl(account, owner));
                }
            } else if ((rights & ACL.RIGHT_READ) > 0) {
                Account owner = Provisioning.getInstance().get(AccountBy.id, folder.getFirst().getOwnerId());
                if (owner != null) {
                    group.addElement(DavElements.E_HREF).setText(UrlNamespace.getCalendarProxyReadUrl(account, owner));
                }
            }
        } catch (ServiceException se) {
            ZimbraLog.dav.warn("can't convert rights", se);
        }
    }
    return group;
}
Also used : Account(com.zimbra.cs.account.Account) ServiceException(com.zimbra.common.service.ServiceException) Element(org.dom4j.Element) ZFolder(com.zimbra.client.ZFolder) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) Pair(com.zimbra.common.util.Pair)

Example 65 with Account

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

the class RemoteCollection method getRemoteMailbox.

static ZMailbox getRemoteMailbox(ZAuthToken zat, String ownerId) throws ServiceException {
    Account target = Provisioning.getInstance().get(Key.AccountBy.id, ownerId);
    if (target == null)
        return null;
    ZMailbox.Options zoptions = new ZMailbox.Options(zat, AccountUtil.getSoapUri(target));
    zoptions.setNoSession(true);
    zoptions.setTargetAccount(ownerId);
    zoptions.setTargetAccountBy(Key.AccountBy.id);
    return ZMailbox.getMailbox(zoptions);
}
Also used : Account(com.zimbra.cs.account.Account) ZMailbox(com.zimbra.client.ZMailbox)

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