本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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;
}
}
示例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));
}
}
示例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);
}
}
}
}
示例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));
}
示例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));
}
示例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()]);
}
示例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);
}
}
示例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;
}
示例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;
}
}
});
}
示例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();
}
示例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);
}
}
}
示例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);
}