예제 #1
0
  /**
   * Test for Command 'fileinto' with duplicate destinations. Only one ActionFileInto should result.
   */
  @Test
  public void testDuplicateFileInto() {
    boolean isTestPassed = false;
    String script = "fileinto \"INBOX.test1\"; fileinto \"INBOX.test1\";";

    try {
      MailAdapter mail = JUnitUtils.createMail();
      JUnitUtils.interpret(mail, script);
      Assert.assertTrue(mail.getActions().size() == 1);
      Assert.assertTrue(mail.getActions().get(0) instanceof ActionFileInto);
      Assert.assertTrue(
          ((ActionFileInto) mail.getActions().get(0)).getDestination().equals("INBOX.test1"));
      isTestPassed = true;
    } catch (ParseException e) {
    } catch (SieveException e) {
    }
    Assert.assertTrue(isTestPassed);
  }
예제 #2
0
  /**
   * @see org.apache.jsieve.tests.AbstractTest#executeBasic(MailAdapter, Arguments, SieveContext)
   */
  protected boolean executeBasic(MailAdapter mail, Arguments arguments, SieveContext context)
      throws SieveException {

    final List<String> argumentList =
        ((StringListArgument) arguments.getArgumentList().get(0)).getList();

    boolean found = true;
    for (final String arg : argumentList) {
      List<String> headers = mail.getMatchingHeader(arg);
      found = found && !headers.isEmpty();
      if (!found) {
        break;
      }
    }
    return found;
  }
예제 #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;
 }
예제 #4
0
 /**
  * Method testUnder.
  *
  * @param mail
  * @param size
  * @return boolean
  * @throws SieveMailException
  */
 protected boolean testUnder(MailAdapter mail, int size) throws SieveMailException {
   return mail.getSize() < size;
 }