private boolean getNextBatch() { if ( batchLast >= end ) { return false; } else { batchFirst = batchLast + 1; batchLast = Math.min( batchFirst + batchSize - 1, end ); if ( batchLast < batchFirst ) { return false; } try { messages = folder.getMessages( batchFirst, batchLast ); buffIndex = 0; return messages != null && messages.length > 0; } catch ( MessagingException e ) { return false; } } }
public void findContent( Folder folder ) throws MessagingException, IOException { for ( Message m : folder.getMessages() ) { logger.info( "Subject: " + m.getSubject() ); } } }
@BeforeClass public static void setUp() throws MessagingException { folder = mock( Folder.class ); when( folder.getName() ).thenReturn( "INBOX" ); when( folder.getMessages( anyInt(), anyInt() ) ).thenAnswer( new Answer<Message[]>() { @Override public Message[] answer( InvocationOnMock invocation ) throws Throwable { Object[] args = invocation.getArguments(); int start = ( (Integer) args[0] ).intValue(); int end = ( (Integer) args[1] ).intValue(); return new Message[end - start + 1]; } } ); }
/** * Retrieve all messages from server * * @throws KettleException */ public void retrieveMessages() throws KettleException { try { // search term? if ( this.searchTerm != null ) { this.messages = this.folder.search( this.searchTerm ); } else { this.messages = this.folder.getMessages(); } } catch ( Exception e ) { this.messages = null; throw new KettleException( BaseMessages.getString( PKG, "MailConnection.Error.RetrieveMessages", getFolderName() ), e ); } }
messages = folder.getMessages(); } else { messages = folder.search(filter.getSearchTerm());
/** * Search this Folder for messages matching the specified * search criterion. Returns an array containing the matching * messages . Returns an empty array if no matches were found. <p> * * This implementation invokes * <code>search(term, getMessages())</code>, to apply the search * over all the messages in this folder. Providers that can implement * server-side searching might want to override this method to provide * a more efficient implementation. * * @param term the search criterion * @return array of matching messages * @exception javax.mail.search.SearchException if the search * term is too complex for the implementation to handle. * @exception FolderNotFoundException if this folder does * not exist. * @exception IllegalStateException if this folder is not opened. * @exception MessagingException for other failures * @see javax.mail.search.SearchTerm */ public Message[] search(SearchTerm term) throws MessagingException { return search(term, getMessages()); }
/** * Search this Folder for messages matching the specified * search criterion. Returns an array containing the matching * messages . Returns an empty array if no matches were found. <p> * * This implementation invokes * <code>search(term, getMessages())</code>, to apply the search * over all the messages in this folder. Providers that can implement * server-side searching might want to override this method to provide * a more efficient implementation. * * @param term the search criterion * @return array of matching messages * @exception javax.mail.search.SearchException if the search * term is too complex for the implementation to handle. * @exception FolderNotFoundException if this folder does * not exist. * @exception IllegalStateException if this folder is not opened. * @exception MessagingException for other failures * @see javax.mail.search.SearchTerm */ public Message[] search(SearchTerm term) throws MessagingException { return search(term, getMessages()); }
@Override protected Message[] searchForNewMessages() throws MessagingException { Folder folderToUse = getFolder(); int messageCount = folderToUse.getMessageCount(); if (messageCount == 0) { return new Message[0]; } return folderToUse.getMessages(); }
/** * Retrieves new messages from this receiver's folder. This implementation * creates a {@link SearchTerm} that searches for all messages in the * folder that are {@link javax.mail.Flags.Flag#RECENT RECENT}, not * {@link javax.mail.Flags.Flag#ANSWERED ANSWERED}, and not * {@link javax.mail.Flags.Flag#DELETED DELETED}. The search term is used * to {@link Folder#search(SearchTerm) search} for new messages. * @return the new messages * @throws MessagingException in case of JavaMail errors */ @Override protected Message[] searchForNewMessages() throws MessagingException { Folder folderToUse = getFolder(); Flags supportedFlags = folderToUse.getPermanentFlags(); SearchTerm searchTerm = compileSearchTerms(supportedFlags); if (folderToUse.isOpen()) { return nullSafeMessages(searchTerm != null ? folderToUse.search(searchTerm) : folderToUse.getMessages()); } throw new MessagingException("Folder is closed"); }
/** * Simply returns {@link Folder#getMessages()}. */ @Override protected Message[] searchForNewMessages(Folder folder) throws MessagingException { return folder.getMessages(); }
/** * Simply returns {@link Folder#getMessages()}. */ @Override protected Message[] searchForNewMessages(Folder folder) throws MessagingException { return folder.getMessages(); }
/** * Simply returns {@link Folder#getMessages()}. */ @Override protected Message[] searchForNewMessages(Folder folder) throws MessagingException { return folder.getMessages(); }
/** * Retrieve all messages. * * @return all messages in this folder * @throws MessagingException if there was a problem accessing the store */ public Message[] getMessages() throws MessagingException { return getMessages(1, getMessageCount()); }
/** * Retrieve all messages. * * @return all messages in this folder * @throws MessagingException if there was a problem accessing the store */ public Message[] getMessages() throws MessagingException { return getMessages(1, getMessageCount()); }
public List<Message> getTestEmails() throws MessagingException { final Folder inbox = store.getFolder(INBOX_FOLDER); inbox.open(Folder.READ_ONLY); List<Message> messages = Arrays.asList(inbox.getMessages()); messages = messages.stream() .limit(MAX_RECENT_MESSAGES_TO_SEARCH) .filter(this::isTestEmail) .collect(Collectors.toList()); inbox.close(false); return messages; }
private void deleteMessages(final Folder folder, final Predicate<Message> condition) { try { List<Message> messages = FluentIterable.from(asList(folder.getMessages())).filter(condition).toList(); doDeleteMessages(folder, messages); } catch (MessagingException ex) { throw new MailException(ex.getMessage(), ex); } }
Folder inbox = store.getFolder("inbox"); inbox.open(Folder.READ_WRITE); // Folder.READ_ONLY int messageCount = inbox.getMessageCount(); System.out.println("Total Messages" + messageCount); int startMessage = messageCount - 5; int endMessage = messageCount; if (messageCount < 5) { startMessage = 0; } Message[] messages = inbox.getMessages(startMessage, endMessage);
@Override public JavaxMailMessage[] getMessages() throws RuntimeMessagingException { try { return decorateMessageArray(delegate.getMessages()); } catch (MessagingException e) { throw new RuntimeMessagingException(e); } }
Session session = Session.getDefaultInstance(new Properties()); Store store = session.getStore(new URLName("mstor:c:/mailbox/MyStore")); store.connect(); // read messages from Inbox.. Folder inbox = store.getDefaultFolder().getFolder("Inbox"); inbox.open(Folder.READ_ONLY); Message[] messages = inbox.getMessages();
Session session = Session.getDefaultInstance(props, null); Store store = session.getStore("imaps"); store.connect("imap.gmail.com", "myemail@gmail.com", "password"); Folder inbox = store.getFolder("Inbox"); inbox.open(Folder.READ_ONLY); Message messages[] = inbox.getMessages(); for(Message message:messages) { MimeMessage im = new MimeMessage(session, message.getContent()); im.getFrom(); im.getMessageID(); ... }