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);
 }
示例#2
0
  private static void searchRemoteAccountCalendars(
      Element parent,
      SearchParams params,
      ZimbraSoapContext zsc,
      Account authAcct,
      Map<String, List<Integer>> accountFolders)
      throws ServiceException {
    String nominalTargetAcctId = null; // mail service soap requests want to see a target account
    StringBuilder queryStr = new StringBuilder();
    for (Map.Entry<String, List<Integer>> entry : accountFolders.entrySet()) {
      String acctId = entry.getKey();
      if (nominalTargetAcctId == null) nominalTargetAcctId = acctId;
      ItemIdFormatter ifmt = new ItemIdFormatter(authAcct.getId(), acctId, false);
      List<Integer> folderIds = entry.getValue();
      for (int folderId : folderIds) {
        if (queryStr.length() > 0) queryStr.append(" OR ");
        // must quote the qualified folder id
        queryStr.append("inid:\"").append(ifmt.formatItemId(folderId)).append("\"");
      }
    }
    Element req = zsc.createElement(MailConstants.SEARCH_REQUEST);
    req.addAttribute(MailConstants.A_SEARCH_TYPES, MailItem.Type.toString(params.getTypes()));
    if (params.getSortBy() != null) {
      req.addAttribute(MailConstants.A_SORTBY, params.getSortBy().toString());
    }
    req.addAttribute(MailConstants.A_QUERY_OFFSET, params.getOffset());
    if (params.getLimit() != 0) req.addAttribute(MailConstants.A_QUERY_LIMIT, params.getLimit());
    req.addAttribute(MailConstants.A_CAL_EXPAND_INST_START, params.getCalItemExpandStart());
    req.addAttribute(MailConstants.A_CAL_EXPAND_INST_END, params.getCalItemExpandEnd());
    req.addAttribute(MailConstants.E_QUERY, queryStr.toString(), Element.Disposition.CONTENT);

    Account target = Provisioning.getInstance().get(Key.AccountBy.id, nominalTargetAcctId);
    String pxyAuthToken = zsc.getAuthToken().getProxyAuthToken();
    ZAuthToken zat = pxyAuthToken == null ? zsc.getRawAuthToken() : new ZAuthToken(pxyAuthToken);
    ZMailbox.Options zoptions = new ZMailbox.Options(zat, AccountUtil.getSoapUri(target));
    zoptions.setTargetAccount(nominalTargetAcctId);
    zoptions.setTargetAccountBy(AccountBy.id);
    zoptions.setNoSession(true);
    ZMailbox zmbx = ZMailbox.getMailbox(zoptions);

    Element resp = zmbx.invoke(req);
    for (Element hit : resp.listElements()) {
      hit.detach();
      parent.addElement(hit);
    }
  }
示例#3
0
 @Override
 protected boolean executeBasic(MailAdapter mail, Arguments args, SieveContext ctx)
     throws SieveException {
   if (!(mail instanceof ZimbraMailAdapter)) {
     return false;
   }
   ZimbraMailAdapter adapter = (ZimbraMailAdapter) mail;
   for (String name : adapter.getHeaderNames()) {
     name = name.toUpperCase(); // compare in all upper-case
     if (HEADERS.contains(name)) { // test common bulk headers
       return true;
     } else if (LIST_UNSUBSCRIBE.equals(name)) { // test List-Unsubscribe
       // Check "to me" to avoid conflicting with legitimate mailing list messages
       List<InternetAddress> addrs = new ArrayList<InternetAddress>();
       for (String to : mail.getHeader("To")) {
         addrs.addAll(InternetAddress.parseHeader(to));
       }
       try {
         Set<String> me = AccountUtil.getEmailAddresses(adapter.getMailbox().getAccount());
         for (InternetAddress addr : addrs) {
           if (me.contains(addr.getAddress().toLowerCase())) {
             return true;
           }
         }
       } catch (ServiceException e) {
         ZimbraLog.filter.error("Failed to lookup my addresses", e);
       }
     } else if (PRECEDENCE.equals(name)) { // test "Precedence: bulk"
       for (String precedence : adapter.getHeader(PRECEDENCE)) {
         if ("bulk".equalsIgnoreCase(precedence)) {
           boolean zimbraOOONotif = false;
           for (String autoSubmitted : mail.getHeader(AUTO_SUBMITTED)) {
             if (ZIMBRA_OOO_AUTO_REPLY.equals(autoSubmitted)) {
               zimbraOOONotif = true;
               break;
             }
           }
           if (!zimbraOOONotif) {
             return true;
           }
         }
       }
     } else if (name.contains("CAMPAIGN")) { // test *CAMPAIGN*
       return true;
     } else if (name.equals(X_PROOFPOINT_SPAM_DETAILS)) { // test Proofpoint bulkscore > 50
       for (String value : adapter.getHeader(X_PROOFPOINT_SPAM_DETAILS)) {
         for (String field : Splitter.on(' ').split(value)) {
           if (field.startsWith("bulkscore=")) {
             String[] pair = field.split("=", 2);
             try {
               if (pair.length == 2 && Integer.parseInt(pair[1]) >= 50) {
                 return true;
               }
             } catch (NumberFormatException ignore) {
             }
             break;
           }
         }
       }
     }
   }
   return false;
 }