javax.mail.search.FromTerm Java Examples
The following examples show how to use
javax.mail.search.FromTerm.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MailSteps.java From NoraUi with GNU Affero General Public License v3.0 | 5 votes |
/** * Valid activation email. * * @param mailHost * example: imap.gmail.com * @param mailUser * login of mail box * @param mailPassword * password of mail box * @param senderMail * sender of mail box * @param subjectMail * subject of mail box * @param firstCssQuery * the first matching element * @param conditions * list of 'expected' values condition and 'actual' values ({@link com.github.noraui.gherkin.GherkinStepCondition}). * @throws TechnicalException * is throws if you have a technical error (format, configuration, datas, ...) in NoraUi. * Exception with message and with screenshot and with exception if functional error but no screenshot and no exception if technical error. * @throws FailureException * if the scenario encounters a functional error */ @Experimental(name = "validActivationEmail") @RetryOnFailure(attempts = 3, delay = 60) @Conditioned @Et("Je valide le mail d'activation {string}(\\?)") @And("I valid activation email {string}(\\?)") public void validActivationEmail(String mailHost, String mailUser, String mailPassword, String senderMail, String subjectMail, String firstCssQuery, List<GherkinStepCondition> conditions) throws FailureException, TechnicalException { try { final Properties props = System.getProperties(); props.setProperty("mail.store.protocol", "imap"); final Session session = Session.getDefaultInstance(props, null); final Store store = session.getStore("imaps"); store.connect(mailHost, mailUser, mailPassword); final Folder inbox = store.getFolder("Inbox"); inbox.open(Folder.READ_ONLY); final SearchTerm filterA = new FlagTerm(new Flags(Flags.Flag.SEEN), false); final SearchTerm filterB = new FromTerm(new InternetAddress(senderMail)); final SearchTerm filterC = new SubjectTerm(subjectMail); final SearchTerm[] filters = { filterA, filterB, filterC }; final SearchTerm searchTerm = new AndTerm(filters); final Message[] messages = inbox.search(searchTerm); for (final Message message : messages) { validateActivationLink(subjectMail, firstCssQuery, message); } } catch (final Exception e) { new Result.Failure<>("", Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_MAIL_ACTIVATION), subjectMail), false, Context.getCallBack(Callbacks.RESTART_WEB_DRIVER)); } }
Example #2
Source File: SearchTermBuilder.java From greenmail with Apache License 2.0 | 5 votes |
private static SearchTermBuilder createFromSearchTermBuilder() { return new SearchTermBuilder() { @Override public SearchTerm build() { try { return new FromTerm(new InternetAddress(getParameters().get(0))); } catch (AddressException e) { throw new IllegalArgumentException("Address is not correct", e); } } }; }