当前位置: 首页>>代码示例>>Java>>正文


Java SearchTerm类代码示例

本文整理汇总了Java中javax.mail.search.SearchTerm的典型用法代码示例。如果您正苦于以下问题:Java SearchTerm类的具体用法?Java SearchTerm怎么用?Java SearchTerm使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SearchTerm类属于javax.mail.search包,在下文中一共展示了SearchTerm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isMailReceivedBySubject

import javax.mail.search.SearchTerm; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:34,代码来源:GreenMailServer.java

示例2: searchInternal

import javax.mail.search.SearchTerm; //导入依赖的package包/类
@Override
protected long[] searchInternal(SearchTerm searchTerm)
{
    List<SimpleStoredMessage> messages = getMessages();
    long[] result = new long[messages.size()];
    int i = 0;
    
    for (SimpleStoredMessage message : messages)
    {
        if (searchTerm.match(message.getMimeMessage()))
        {
            result[i] = message.getUid();
            i++;
        }
    }
    return Arrays.copyOfRange(result, 0, i);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:18,代码来源:AlfrescoImapFolder.java

示例3: search

import javax.mail.search.SearchTerm; //导入依赖的package包/类
public long[] search(SearchTerm searchTerm) {
    ArrayList matchedMessages = new ArrayList();

    for (int i = 0; i < mailMessages.size(); i++) {
        SimpleStoredMessage message = (SimpleStoredMessage) mailMessages.get(i);
        if (searchTerm.match(message.getMimeMessage())) {
            matchedMessages.add(message);
        }
    }

    long[] matchedUids = new long[matchedMessages.size()];
    for (int i = 0; i < matchedUids.length; i++) {
        SimpleStoredMessage storedMessage = (SimpleStoredMessage) matchedMessages.get(i);
        long uid = storedMessage.getUid();
        matchedUids[i] = uid;
    }
    return matchedUids;
}
 
开发者ID:Alfresco,项目名称:alfresco-greenmail,代码行数:19,代码来源:InMemoryStore.java

示例4: createFieldSearchTerm

import javax.mail.search.SearchTerm; //导入依赖的package包/类
private SearchTerm createFieldSearchTerm(String f) {
    switch (f.toLowerCase()) {
        case "from":
            return new FromStringTerm(matchingText);
        case "cc":
            return new RecipientStringTerm(Message.RecipientType.CC, matchingText);
        case "to":
            return new RecipientStringTerm(Message.RecipientType.TO, matchingText);
        case "body":
            return new BodyTerm(matchingText);
        case "subject":
            return new SubjectTerm(matchingText);
        default:
            return null;
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:17,代码来源:Rule.java

示例5: multipleFieldsShouldReturnOrTerm

import javax.mail.search.SearchTerm; //导入依赖的package包/类
@Test
public void multipleFieldsShouldReturnOrTerm() {
    final Set fields = new HashSet();
    fields.add("to");
    fields.add("from");
    fields.add("cc");

    Rule rule = Rule.create()
            .sourceFolder("INBOX")
            .matchingText("testText")
            .fields(fields);
    SearchTerm term = rule.getSearchTerm();
    Assert.assertTrue(term instanceof OrTerm);
    SearchTerm[] terms = ((OrTerm) term).getTerms();
    for (SearchTerm t : terms) {
        Assert.assertTrue(t instanceof FromStringTerm
                || (t instanceof RecipientStringTerm && ((RecipientStringTerm) t).getRecipientType() == Message.RecipientType.CC)
                || (t instanceof RecipientStringTerm && ((RecipientStringTerm) t).getRecipientType() == Message.RecipientType.TO));
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:21,代码来源:RuleTest.java

示例6: isMailReceivedBySubject

import javax.mail.search.SearchTerm; //导入依赖的package包/类
/**
 * 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);
            }
        }
    }
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:39,代码来源:MailToTransportUtil.java

示例7: testSearchTermBuilderFromAndSubject

import javax.mail.search.SearchTerm; //导入依赖的package包/类
public void testSearchTermBuilderFromAndSubject() throws Exception {
    SearchTermBuilder build = new SearchTermBuilder();
    SearchTerm st = build.from("[email protected]").subject("Camel").build();

    assertNotNull(st);

    // create dummy message
    Mailbox.clearAll();
    JavaMailSender sender = new DefaultJavaMailSender();

    MimeMessage msg = new MimeMessage(sender.getSession());
    msg.setSubject("Yeah Camel rocks");
    msg.setText("Apache Camel is a cool project. Have a fun ride.");
    msg.setFrom(new InternetAddress("[email protected]"));
    assertTrue("Should match message", st.match(msg));

    MimeMessage msg2 = new MimeMessage(sender.getSession());
    msg2.setSubject("Apache Camel is fantastic");
    msg2.setText("I like Camel.");
    msg2.setFrom(new InternetAddress("[email protected]"));
    assertFalse("Should not match message, as from doesn't match", st.match(msg2));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:SearchTermBuilderTest.java

示例8: testSearchTermBuilderFromOrSubject

import javax.mail.search.SearchTerm; //导入依赖的package包/类
public void testSearchTermBuilderFromOrSubject() throws Exception {
    SearchTermBuilder build = new SearchTermBuilder();
    SearchTerm st = build.subject("Camel").from(or, "[email protected]").build();

    assertNotNull(st);

    // create dummy message
    Mailbox.clearAll();
    JavaMailSender sender = new DefaultJavaMailSender();

    MimeMessage msg = new MimeMessage(sender.getSession());
    msg.setSubject("Yeah Camel rocks");
    msg.setText("Apache Camel is a cool project. Have a fun ride.");
    msg.setFrom(new InternetAddress("[email protected]"));
    assertTrue("Should match message", st.match(msg));

    MimeMessage msg2 = new MimeMessage(sender.getSession());
    msg2.setSubject("Beware");
    msg2.setText("This is from the administrator.");
    msg2.setFrom(new InternetAddress("[email protected]"));
    assertTrue("Should match message, as its from admin", st.match(msg2));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:SearchTermBuilderTest.java

示例9: search

import javax.mail.search.SearchTerm; //导入依赖的package包/类
public Message[] search(final SearchTerm term, final Message[] msgsToSearch) {
    final List<MockMessage> sms = new ArrayList<MockMessage>();
    final List<Message> msgsToSearchL = new ArrayList<Message>();

    if (msgsToSearch != null) {
        msgsToSearchL.addAll(Arrays.asList(msgsToSearch));
    }

    for (final Message msg : getMessages()) {
        if (term != null && term.match(msg)) {

            if (msgsToSearch == null || msgsToSearchL.contains(msg)) {
                sms.add((MockMessage) msg);
            }
        }
    }
    return sms.toArray(new Message[sms.size()]);
}
 
开发者ID:salyh,项目名称:javamail-mock2,代码行数:19,代码来源:MailboxFolder.java

示例10: MessageIterator

import javax.mail.search.SearchTerm; //导入依赖的package包/类
public MessageIterator(Folder folder, int batchSize) {
  try {
    this.folder = folder;
    this.batchSize = batchSize;
    SearchTerm st = getSearchTerm();
    if (st != null) {
      doBatching = false;
      messagesInCurBatch = folder.search(st);
      totalInFolder = messagesInCurBatch.length;
      folder.fetch(messagesInCurBatch, fp);
      current = 0;
      LOG.info("Total messages : " + totalInFolder);
      LOG.info("Search criteria applied. Batching disabled");
    } else {
      totalInFolder = folder.getMessageCount();
      LOG.info("Total messages : " + totalInFolder);
      getNextBatch(batchSize, folder);
    }
  } catch (MessagingException e) {
    throw new DataImportHandlerException(DataImportHandlerException.SEVERE,
            "Message retreival failed", e);
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:24,代码来源:MailEntityProcessor.java

示例11: search

import javax.mail.search.SearchTerm; //导入依赖的package包/类
@Override
public long[] search(SearchTerm searchTerm) {
    List<StoredMessage> matchedMessages = new ArrayList<>();

    synchronized (mailMessages) {
        for (int i = 0; i<mailMessages.size();i++) {
            StoredMessage mailMessage = mailMessages.get(i);
            // Update message sequence number for potential sequence set search
            // https://tools.ietf.org/html/rfc3501#page-10
            mailMessage.updateMessageNumber(i+1);
            if (searchTerm.match(mailMessage.getMimeMessage())) {
                matchedMessages.add(mailMessage);
            }
        }
    }

    long[] matchedUids = new long[matchedMessages.size()];
    for (int i = 0; i < matchedUids.length; i++) {
        StoredMessage storedMessage = matchedMessages.get(i);
        long uid = storedMessage.getUid();
        matchedUids[i] = uid;
    }
    return matchedUids;
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:25,代码来源:HierarchicalFolder.java

示例12: getMessagesByIds

import javax.mail.search.SearchTerm; //导入依赖的package包/类
@SuppressWarnings("serial")
private Message[] getMessagesByIds(Folder notesFolder, final List<String> notes) throws Exception {
    return notesFolder.search(new SearchTerm() {
        @Override
        public boolean match(Message message) {
            try {
                for (String note: notes) {
                    String[] id = message.getHeader(HeaderUtils.INOTES_ID_HEADER);
                    if (id != null && note.equals(id[0])) {
                        return true;
                    }
                }
                return false;
            } catch (Exception e) {
                return false;
            }
        }
    });
}
 
开发者ID:codeminders,项目名称:inotes,代码行数:20,代码来源:ImapService.java

示例13: search

import javax.mail.search.SearchTerm; //导入依赖的package包/类
/**
 * Searches the mailbox for messages that match the given searching criteria
 * 
 * @param searchTerm - search term that contains search criteria.
 * @return UIDs of the messages
 */
public long[] search(final SearchTerm searchTerm)
{
    CommandCallback<long[]> command = new CommandCallback<long[]>()
    {
        public long[] command() throws Throwable
        {
            return searchInternal(searchTerm);
        }
    };
    return command.run();
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:18,代码来源:AbstractImapFolder.java

示例14: extractSearchTermResultsToList

import javax.mail.search.SearchTerm; //导入依赖的package包/类
private void extractSearchTermResultsToList(List<AlfrescoImapFolder> folders, SearchTerm searchTerm, ArrayList<Long> resList)
{
    for (AlfrescoImapFolder folder : folders)
    {
        for (long l : folder.search(searchTerm))
        {
            resList.add(l);
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:11,代码来源:ImapServiceImplTest.java

示例15: doProcess

import javax.mail.search.SearchTerm; //导入依赖的package包/类
public void doProcess(ImapRequestLineReader request,
                      ImapResponse response,
                      ImapSession session,
                      boolean useUids)
        throws ProtocolException, FolderException {
    // Parse the search term from the request
    SearchTerm searchTerm = parser.searchTerm(request);
    parser.endLine(request);

    MailFolder folder = session.getSelected();
    long[] uids = folder.search(searchTerm);
    StringBuffer idList = new StringBuffer();
    for (int i = 0; i < uids.length; i++) {
        if (i > 0) {
            idList.append(SP);
        }
        long uid = uids[i];
        if (useUids) {
            idList.append(uid);
        } else {
            int msn = folder.getMsn(uid);
            idList.append(msn);
        }
    }

    response.commandResponse(this, idList.toString());

    boolean omitExpunged = (!useUids);
    session.unsolicitedResponses(response, omitExpunged);
    response.commandComplete(this);
}
 
开发者ID:Alfresco,项目名称:alfresco-greenmail,代码行数:32,代码来源:SearchCommand.java


注:本文中的javax.mail.search.SearchTerm类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。