com.icegreen.greenmail.server.AbstractServer Java Examples
The following examples show how to use
com.icegreen.greenmail.server.AbstractServer.
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: InterruptableGreenMail.java From syncope with Apache License 2.0 | 6 votes |
@Override protected Map<String, AbstractServer> createServices(final ServerSetup[] config, final Managers mgr) { Map<String, AbstractServer> srvc = new HashMap<>(); for (ServerSetup setup : config) { if (srvc.containsKey(setup.getProtocol())) { throw new IllegalArgumentException("Server '" + setup.getProtocol() + "' was found at least twice in the array"); } final String protocol = setup.getProtocol(); if (protocol.startsWith(ServerSetup.PROTOCOL_SMTP)) { srvc.put(protocol, new InterruptableSmtpServer(setup, mgr)); } else if (protocol.startsWith(ServerSetup.PROTOCOL_POP3)) { srvc.put(protocol, new Pop3Server(setup, mgr)); } else if (protocol.startsWith(ServerSetup.PROTOCOL_IMAP)) { srvc.put(protocol, new ImapServer(setup, mgr)); } } return srvc; }
Example #2
Source File: GreenMail.java From greenmail with Apache License 2.0 | 6 votes |
/** * Create the required services according to the server setup * * @param config Service configuration * @return Services map */ protected Map<String, AbstractServer> createServices(ServerSetup[] config, Managers mgr) { Map<String, AbstractServer> srvc = new HashMap<>(); for (ServerSetup setup : config) { if (srvc.containsKey(setup.getProtocol())) { throw new IllegalArgumentException("Server '" + setup.getProtocol() + "' was found at least twice in the array"); } final String protocol = setup.getProtocol(); if (protocol.startsWith(ServerSetup.PROTOCOL_SMTP)) { srvc.put(protocol, new SmtpServer(setup, mgr)); } else if (protocol.startsWith(ServerSetup.PROTOCOL_POP3)) { srvc.put(protocol, new Pop3Server(setup, mgr)); } else if (protocol.startsWith(ServerSetup.PROTOCOL_IMAP)) { srvc.put(protocol, new ImapServer(setup, mgr)); } } return srvc; }
Example #3
Source File: LargeMessageTest.java From greenmail with Apache License 2.0 | 6 votes |
/** * Retrieve message from retriever and check the attachment and text content * * @param server Server to read from * @param to Account to retrieve */ private void retrieveAndCheck(AbstractServer server, String to) throws MessagingException, IOException { try (Retriever retriever = new Retriever(server)) { Message[] messages = retriever.getMessages(to); assertEquals(1, messages.length); Message message = messages[0]; assertTrue(message.getContentType().startsWith("multipart/mixed")); MimeMultipart body = (MimeMultipart) message.getContent(); assertTrue(body.getContentType().startsWith("multipart/mixed")); assertEquals(2, body.getCount()); // Message text final BodyPart textPart = body.getBodyPart(0); String text = (String) textPart.getContent(); assertEquals(createLargeString(), text); final BodyPart attachment = body.getBodyPart(1); assertTrue(attachment.getContentType().equalsIgnoreCase("application/blubb; name=file")); InputStream attachmentStream = (InputStream) attachment.getContent(); byte[] bytes = IOUtils.toByteArray(attachmentStream); assertArrayEquals(createLargeByteArray(), bytes); } }
Example #4
Source File: LargeMessageTest.java From greenmail with Apache License 2.0 | 6 votes |
/** * Retrieve message from retriever and check the body content * * @param server Server to read from * @param to Account to retrieve */ private void retrieveAndCheckBody(AbstractServer server, String to) throws MessagingException, IOException { try (Retriever retriever = new Retriever(server)) { Message[] messages = retriever.getMessages(to); assertEquals(1, messages.length); Message message = messages[0]; assertTrue(message.getContentType().equalsIgnoreCase("application/blubb")); // Check content InputStream contentStream = (InputStream) message.getContent(); byte[] bytes = IOUtils.toByteArray(contentStream); assertArrayEquals(createLargeByteArray(), bytes); // Dump complete mail message. This leads to a FETCH command without section or "len" specified. message.writeTo(new ByteArrayOutputStream()); } }
Example #5
Source File: MailOperatorFactoryTest.java From digdag with Apache License 2.0 | 5 votes |
private void receiveCheck(String user, int size) { AbstractServer server = greenMail.getPop3(); Retriever retriever = new Retriever(server); Message[] messages = retriever.getMessages(user); assertEquals(size, messages.length); }
Example #6
Source File: SenderRecipientTest.java From greenmail with Apache License 2.0 | 5 votes |
/** * Retrieve message from retriever and check the sender and receivers * * @param server Server to read from * @param login Account to retrieve */ private void retrieveAndCheck(AbstractServer server, String login) throws MessagingException { try (Retriever retriever = new Retriever(server)) { Message[] messages = retriever.getMessages(login); assertEquals(1, messages.length); Message message = messages[0]; assertThat(toInetAddr(message.getRecipients(Message.RecipientType.TO)), is(TO_ADDRESSES)); assertThat(toInetAddr(message.getRecipients(Message.RecipientType.CC)), is(CC_ADDRESSES)); // BCC addresses are not contained in the message since other receivers are not allowed to know the list of // BCC recipients assertThat(toInetAddr(message.getRecipients(Message.RecipientType.BCC)), nullValue()); } }
Example #7
Source File: ReplyToTest.java From greenmail with Apache License 2.0 | 5 votes |
/** * Retrieve message from retriever and check the ReplyTo address * * @param server Server to read from * @param login Account to retrieve */ private void retrieveAndCheckReplyTo(AbstractServer server, String login, InternetAddress[] replyToAddrs) throws MessagingException { try (Retriever retriever = new Retriever(server)) { Message[] messages = retriever.getMessages(login); assertEquals(1, messages.length); Message message = messages[0]; assertThat(toInetAddr(message.getReplyTo()), is(replyToAddrs)); } }
Example #8
Source File: EscapingTest.java From greenmail with Apache License 2.0 | 5 votes |
/** * Retrieve message from retriever and check content * * @param server Server to read from * @param to Account to retrieve * @param subject Subject of message */ private void retrieveAndCheck(AbstractServer server, String to, String from, String subject) throws MessagingException { try (Retriever retriever = new Retriever(server)) { Message[] messages = retriever.getMessages(to); assertEquals(1, messages.length); Message message = messages[0]; // Message subject assertThat(message.getSubject(), is(subject)); assertThat(message.getAllRecipients()[0].toString(), is(to)); assertThat(message.getFrom()[0].toString(), is(from)); } }
Example #9
Source File: DateTest.java From greenmail with Apache License 2.0 | 5 votes |
/** * Retrieve message from retriever and check content * * @param server Server to read from * @param to Account to retrieve * @param sentDate Desired 'sent' date of message * @param checkReceivedDate True if received date should be checked. POP3 does not provide a received date */ private void retrieveAndCheck(AbstractServer server, String to, Date sentDate, boolean checkReceivedDate) throws MessagingException { try (Retriever retriever = new Retriever(server)) { Message[] messages = retriever.getMessages(to); assertThat(messages.length, is(1)); Message message = messages[0]; assertThat(milliSecondDateDiff(message.getSentDate(), sentDate), lessThan(3000L)); if (checkReceivedDate) { assertThat(milliSecondDateDiff(message.getReceivedDate(), new Date()), lessThan(3000L)); } } }
Example #10
Source File: MultiRequestTest.java From greenmail with Apache License 2.0 | 4 votes |
RetrieverThread(String to, AbstractServer server, ThreadGroup group, int expectedCount) { super(group, RetrieverThread.class.getName()); this.to = to; this.server = server; this.expectedCount = expectedCount; }
Example #11
Source File: Retriever.java From greenmail with Apache License 2.0 | 3 votes |
/** * Creates a retriever object for a particular server<br> * Example:<br> * <i> * GreenMail greenMail = new GreenMail();<br> * ...<br> * Retriever r = new Retriever(greenMail.getPop3())<br>; * r.getMessages("[email protected]");<br> * </i> * This will fetch all available messages for Billy using POP3. * * @param server the POP3 or IMAP server */ public Retriever(AbstractServer server) { if (null == server) { throw new IllegalArgumentException("Expected non null server argument"); } if (!(server.getProtocol().startsWith(ServerSetup.PROTOCOL_IMAP) || server.getProtocol().startsWith(ServerSetup.PROTOCOL_POP3))) { throw new IllegalArgumentException("Requires a " + ServerSetup.PROTOCOL_POP3 + " or " + ServerSetup.PROTOCOL_IMAP + " server but got " + server.getProtocol()); } this.server = server; }