Java 类javax.mail.search.AndTerm 实例源码

项目:product-ei    文件:GreenMailServer.java   
/**
 * Check mail folder for an email using subject.
 *
 * @param emailSubject Email subject
 * @param folder       mail folder to check for an email
 * @param protocol     protocol used to connect to the server
 * @return whether mail received or not
 * @throws MessagingException if we're unable to connect to the store
 */
private static boolean isMailReceivedBySubject(String emailSubject, String folder, String protocol,
        GreenMailUser user) throws MessagingException {
    boolean emailReceived = false;
    Folder mailFolder;
    Store store = getConnection(user, protocol);
    try {
        mailFolder = store.getFolder(folder);
        mailFolder.open(Folder.READ_WRITE);
        SearchTerm searchTerm = new AndTerm(new SubjectTerm(emailSubject), new BodyTerm(emailSubject));
        Message[] messages = mailFolder.search(searchTerm);
        for (Message message : messages) {
            if (message.getSubject().contains(emailSubject)) {
                log.info("Found the Email with Subject : " + emailSubject);
                emailReceived = true;
                break;
            }
        }
    } finally {
        if (store != null) {
            store.close();
        }
    }
    return emailReceived;
}
项目:product-ei    文件:MailToTransportUtil.java   
/**
 * Check a particular email has received to a given email folder by email subject.
 *
 * @param emailSubject - Email emailSubject to find email is in inbox or not
 * @return - found the email or not
 * @throws ESBMailTransportIntegrationTestException - Is thrown if an error occurred while reading the emails
 */
public static boolean isMailReceivedBySubject(String emailSubject, String folder)
        throws ESBMailTransportIntegrationTestException {
    boolean emailReceived = false;
    Folder mailFolder;
    Store store = getConnection();
    try {
        mailFolder = store.getFolder(folder);
        mailFolder.open(Folder.READ_WRITE);
        SearchTerm searchTerm = new AndTerm(new SubjectTerm(emailSubject), new BodyTerm(emailSubject));
        Message[] messages = mailFolder.search(searchTerm);
        for (Message message : messages) {
            if (message.getSubject().contains(emailSubject)) {
                log.info("Found the email emailSubject : " + emailSubject);
                emailReceived = true;
                break;
            }
        }
        return emailReceived;
    } catch (MessagingException ex) {
        log.error("Error when getting mail count ", ex);
        throw new ESBMailTransportIntegrationTestException("Error when getting mail count ", ex);
    } finally {
        if (store != null) {
            try {
                store.close();
            } catch (MessagingException e) {
                log.warn("Error when closing the store ", e);
            }
        }
    }
}
项目:alfresco-greenmail    文件:SearchCommand.java   
/**
 * Some expressions can use brackets for complex parameters
 * @param request request
 * @return search term in brackets
 * @throws ProtocolException
 */
private SearchTerm paren(ImapRequestLineReader request) throws ProtocolException
{
    request.consume();
    SearchTerm resultTerm = null;
    char next = request.nextWordChar();
    while (next != ')')
    {
        SearchTerm searchTerm = extractSearchTerm(request);
        resultTerm = (resultTerm == null ? searchTerm : new AndTerm(resultTerm, searchTerm));
        next = request.nextWordChar();
    }
    request.consume();
    return resultTerm;
}
项目:community-edition-old    文件:SearchCommand.java   
/**
 * Some expressions can use brackets for complex parameters
 * @param request request
 * @return search term in brackets
 * @throws ProtocolException
 */
private SearchTerm paren(ImapRequestLineReader request) throws ProtocolException
{
    request.consume();
    SearchTerm resultTerm = null;
    char next = request.nextWordChar();
    while (next != ')')
    {
        SearchTerm searchTerm = extractSearchTerm(request);
        resultTerm = (resultTerm == null ? searchTerm : new AndTerm(resultTerm, searchTerm));
        next = request.nextWordChar();
    }
    request.consume();
    return resultTerm;
}
项目:read-open-source-code    文件:MailConnection.java   
/**
* Add search term.
* @param Term search term to add
*/
  private void addSearchTerm(SearchTerm Term)
  {
if (this.searchTerm != null) {
 this.searchTerm = new AndTerm(this.searchTerm, Term);
      } else  {
        this.searchTerm = Term;
      }
  }
项目:read-open-source-code    文件:MailConnection.java   
public void setReceivedDateTermBetween(Date beginDate, Date endDate) {
  if (this.protocol == MailConnectionMeta.PROTOCOL_POP3) {
    log.logError(BaseMessages.getString(PKG, "MailConnection.Error.ReceivedDatePOP3Unsupported"));
  } else {
    addSearchTerm(
            new AndTerm(new ReceivedDateTerm(ComparisonTerm.LT, endDate),
            new ReceivedDateTerm(ComparisonTerm.GT, beginDate)));
  }
}
项目:kettle-4.4.0-stable    文件:MailConnection.java   
/**
* Add search term.
* @param Term search term to add
*/
  private void addSearchTerm(SearchTerm Term)
  {
if (this.searchTerm != null) {
 this.searchTerm = new AndTerm(this.searchTerm, Term);
      } else  {
        this.searchTerm = Term;
      }
  }
项目:kettle-4.4.0-stable    文件:MailConnection.java   
public void setReceivedDateTermBetween(Date beginDate, Date endDate) {
  if (this.protocol == MailConnectionMeta.PROTOCOL_POP3) {
    log.logError(BaseMessages.getString(PKG, "MailConnection.Error.ReceivedDatePOP3Unsupported"));
  } else {
    addSearchTerm(
            new AndTerm(new ReceivedDateTerm(ComparisonTerm.LT, endDate),
            new ReceivedDateTerm(ComparisonTerm.GT, beginDate)));
  }
}
项目:kettle-trunk    文件:MailConnection.java   
/**
* Add search term.
* @param term search term to add
*/
  private void addSearchTerm(SearchTerm term)
  {
if (this.searchTerm != null) {
 this.searchTerm = new AndTerm(this.searchTerm, term);
      } else  {
        this.searchTerm = term;
      }
  }
项目:kettle-trunk    文件:MailConnection.java   
public void setReceivedDateTermBetween(Date beginDate, Date endDate) {
  if (this.protocol == MailConnectionMeta.PROTOCOL_POP3) {
    log.logError(BaseMessages.getString(PKG, "MailConnection.Error.ReceivedDatePOP3Unsupported"));
  } else {
    addSearchTerm(
            new AndTerm(new ReceivedDateTerm(ComparisonTerm.LT, endDate),
            new ReceivedDateTerm(ComparisonTerm.GT, beginDate)));
  }
}
项目:pentaho-kettle    文件:MailConnection.java   
/**
 * Add search term.
 *
 * @param term
 *          search term to add
 */
private void addSearchTerm( SearchTerm term ) {
  if ( this.searchTerm != null ) {
    this.searchTerm = new AndTerm( this.searchTerm, term );
  } else {
    this.searchTerm = term;
  }
}
项目:pentaho-kettle    文件:MailConnection.java   
public void setReceivedDateTermBetween( Date beginDate, Date endDate ) {
  if ( this.protocol == MailConnectionMeta.PROTOCOL_POP3 ) {
    log.logError( BaseMessages.getString( PKG, "MailConnection.Error.ReceivedDatePOP3Unsupported" ) );
  } else {
    addSearchTerm( new AndTerm( new ReceivedDateTerm( ComparisonTerm.LT, endDate ), new ReceivedDateTerm(
      ComparisonTerm.GT, beginDate ) ) );
  }
}