@Test @Ignore public void testReadMessagesWithSearchTerm() throws JavaMailerException, MessagingException, InterruptedException { String gmailAccount = getUser(); String gmailPassword = getPassword(); JavaSendMailer sendMailer = createSendMailer(gmailAccount, gmailPassword); String term1 = String.valueOf(Calendar.getInstance().getTimeInMillis()); Thread.sleep(2); String term2 = String.valueOf(Calendar.getInstance().getTimeInMillis()); Thread.sleep(2); String term3 = String.valueOf(Calendar.getInstance().getTimeInMillis()); Thread.sleep(2); SendmailMessage sendMsg = createAckMessage(gmailAccount, "1", term1, "ack"); sendMailer.setMessage(sendMailer.buildMimeMessage(sendMsg)); sendMailer.send(); sendMsg = createAckMessage(gmailAccount, "2", term2, "ack"); sendMailer.setMessage(sendMailer.buildMimeMessage(sendMsg)); sendMailer.send(); sendMsg = createAckMessage(gmailAccount, "3", term3, "ack"); sendMailer.setMessage(sendMailer.buildMimeMessage(sendMsg)); sendMailer.send(); JavaReadMailer readMailer = createGoogleReadMailer(gmailAccount, gmailPassword); SearchTerm st = new OrTerm(new SubjectTerm(".*"+term1+" #.*"), new SubjectTerm(".*"+term2+" #.*")); st = new OrTerm(st, new SubjectTerm("*."+term3+" #.*")); List<Message> msgs = null; try { msgs = readMailer.retrieveMessages(st); } catch (JavaMailerException e) { e.printStackTrace(); } Assert.assertEquals(3, msgs.size()); st = new OrTerm(new SubjectTerm(".*"+term1+" #.*"), new SubjectTerm(".*"+term2+" #.*")); try { msgs = readMailer.retrieveMessages(st); } catch (JavaMailerException e) { e.printStackTrace(); } Assert.assertNotNull(msgs); Assert.assertEquals(2, msgs.size()); for (Message msg : msgs) { msg.setFlag(Flag.DELETED, true); } st = new SubjectTerm("*."+term3+" #.*"); try { msgs = readMailer.retrieveMessages(st); } catch (JavaMailerException e) { e.printStackTrace(); } Assert.assertNotNull(msgs); Assert.assertTrue(msgs.size() >= 1); for (Message eventMsg : msgs) { eventMsg.setFlag(Flag.DELETED, true); } st = new OrTerm(new SubjectTerm(".*"+term1+" #.*"), new SubjectTerm(".*"+term2+" #.*")); st = new OrTerm(st, new SubjectTerm("*."+term3+" #.*")); try { msgs = readMailer.retrieveMessages(st); } catch (JavaMailerException e) { e.printStackTrace(); } Assert.assertTrue(msgs.isEmpty()); }
public List<Message> retrieveMessages() throws JavaMailerException { Message[] msgs; Folder mailFolder = null; try { m_store = m_session.getStore(m_config.getReadmailHost().getReadmailProtocol().getTransport()); m_store.connect(m_config.getReadmailHost().getHost(), (int)m_config.getReadmailHost().getPort(), m_config.getUserAuth().getUserName(), m_config.getUserAuth().getPassword()); mailFolder = m_store.getFolder(m_config.getMailFolder()); mailFolder.open(Folder.READ_WRITE); msgs = mailFolder.getMessages(); } catch (NoSuchProviderException e) { throw new JavaMailerException("No provider matching:"+m_config.getReadmailHost().getReadmailProtocol().getTransport()+" from config:"+m_config.getName(), e); } catch (MessagingException e) { throw new JavaMailerException("Problem reading messages from configured mail store", e); } return new ArrayList<Message>(Arrays.asList(msgs)); }
JavaReadMailer extends JavaMailer2 { public List<Message> retrieveMessages() throws JavaMailerException { Message[] msgs; Folder mailFolder = null; try { m_store = m_session.getStore(m_config.getReadmailHost().getReadmailProtocol().getTransport()); m_store.connect(m_config.getReadmailHost().getHost(), (int)m_config.getReadmailHost().getPort(), m_config.getUserAuth().getUserName(), m_config.getUserAuth().getPassword()); mailFolder = m_store.getFolder(m_config.getMailFolder()); mailFolder.open(Folder.READ_WRITE); msgs = mailFolder.getMessages(); } catch (NoSuchProviderException e) { throw new JavaMailerException("No provider matching:"+m_config.getReadmailHost().getReadmailProtocol().getTransport()+" from config:"+m_config.getName(), e); } catch (MessagingException e) { throw new JavaMailerException("Problem reading messages from configured mail store", e); } return new ArrayList<Message>(Arrays.asList(msgs)); } }
JavaReadMailer extends JavaMailer2 { public List<Message> retrieveMessages() throws JavaMailerException { Message[] msgs; Folder mailFolder = null; try { m_store = m_session.getStore(m_config.getReadmailHost().getReadmailProtocol().getTransport()); m_store.connect(m_config.getReadmailHost().getHost(), (int)m_config.getReadmailHost().getPort(), m_config.getUserAuth().getUserName(), m_config.getUserAuth().getPassword()); mailFolder = m_store.getFolder(m_config.getMailFolder()); mailFolder.open(Folder.READ_WRITE); msgs = mailFolder.getMessages(); } catch (NoSuchProviderException e) { throw new JavaMailerException("No provider matching:"+m_config.getReadmailHost().getReadmailProtocol().getTransport()+" from config:"+m_config.getName(), e); } catch (MessagingException e) { throw new JavaMailerException("Problem reading messages from configured mail store", e); } return new ArrayList<Message>(Arrays.asList(msgs)); } JavaReadMailer(final ReadmailConfig config, Boolean closeOnDelete); }
JavaReadMailer extends JavaMailer2 { public List<Message> retrieveMessages() throws JavaMailerException { Message[] msgs; Folder mailFolder = null; try { m_store = m_session.getStore(m_config.getReadmailHost().getReadmailProtocol().getTransport()); m_store.connect(m_config.getReadmailHost().getHost(), (int)m_config.getReadmailHost().getPort(), m_config.getUserAuth().getUserName(), m_config.getUserAuth().getPassword()); mailFolder = m_store.getFolder(m_config.getMailFolder()); mailFolder.open(Folder.READ_WRITE); msgs = mailFolder.getMessages(); } catch (NoSuchProviderException e) { throw new JavaMailerException("No provider matching:"+m_config.getReadmailHost().getReadmailProtocol().getTransport()+" from config:"+m_config.getName(), e); } catch (MessagingException e) { throw new JavaMailerException("Problem reading messages from configured mail store", e); } return new ArrayList<Message>(Arrays.asList(msgs)); } JavaReadMailer(final ReadmailConfig config, Boolean closeOnDelete); List<Message> retrieveMessages(); List<Message> retrieveMessages(SearchTerm term); List<Message> getMessages(); static List<String> getText(Message msg); Boolean isDeleteOnClose(); void setDeleteOnClose(Boolean deleteOnClose); static List<String> string2Lines(String text); }
JavaReadMailer extends JavaMailer2 { public List<Message> retrieveMessages() throws JavaMailerException { Message[] msgs; Folder mailFolder = null; try { m_store = m_session.getStore(m_config.getReadmailHost().getReadmailProtocol().getTransport()); m_store.connect(m_config.getReadmailHost().getHost(), (int)m_config.getReadmailHost().getPort(), m_config.getUserAuth().getUserName(), m_config.getUserAuth().getPassword()); mailFolder = m_store.getFolder(m_config.getMailFolder()); mailFolder.open(Folder.READ_WRITE); msgs = mailFolder.getMessages(); } catch (NoSuchProviderException e) { throw new JavaMailerException("No provider matching:"+m_config.getReadmailHost().getReadmailProtocol().getTransport()+" from config:"+m_config.getName(), e); } catch (MessagingException e) { throw new JavaMailerException("Problem reading messages from configured mail store", e); } return new ArrayList<Message>(Arrays.asList(msgs)); } JavaReadMailer(final ReadmailConfig config, Boolean closeOnDelete); List<Message> retrieveMessages(); List<Message> retrieveMessages(SearchTerm term); List<Message> getMessages(); static List<String> getText(Message msg); Boolean isDeleteOnClose(); void setDeleteOnClose(Boolean deleteOnClose); static List<String> string2Lines(String text);  }