Beispiel #1
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;
 }