@Override public void setSentDate(Date sentDate) throws MailParseException { try { this.helper.setSentDate(sentDate); } catch (MessagingException ex) { throw new MailParseException(ex); } }
@Override public void setSubject(String subject) throws MailParseException { try { this.helper.setSubject(subject); } catch (MessagingException ex) { throw new MailParseException(ex); } }
@Override public void setTo(String... to) throws MailParseException { try { this.helper.setTo(to); } catch (MessagingException ex) { throw new MailParseException(ex); } }
@Test public void testDeepCopyOfStringArrayTypedFieldsOnCopyCtor() throws Exception { SimpleMailMessage original = new SimpleMailMessage(); original.setTo(new String[]{"fiona@mail.org", "apple@mail.org"}); original.setCc(new String[]{"he@mail.org", "she@mail.org"}); original.setBcc(new String[]{"us@mail.org", "them@mail.org"}); SimpleMailMessage copy = new SimpleMailMessage(original); original.getTo()[0] = "mmm@mmm.org"; original.getCc()[0] = "mmm@mmm.org"; original.getBcc()[0] = "mmm@mmm.org"; assertEquals("fiona@mail.org", copy.getTo()[0]); assertEquals("he@mail.org", copy.getCc()[0]); assertEquals("us@mail.org", copy.getBcc()[0]); }
@Test public void javaMailSenderWithParseExceptionOnSimpleMessage() { MockJavaMailSender sender = new MockJavaMailSender(); SimpleMailMessage simpleMessage = new SimpleMailMessage(); simpleMessage.setFrom(""); try { sender.send(simpleMessage); } catch (MailParseException ex) { // expected assertTrue(ex.getCause() instanceof AddressException); } }
@Override public void setText(String text) throws MailParseException { try { this.helper.setText(text); } catch (MessagingException ex) { throw new MailParseException(ex); } }
@Override public void setFrom(String from) throws MailParseException { try { this.helper.setFrom(from); } catch (MessagingException ex) { throw new MailParseException(ex); } }
if (getFrom() != null) { target.setFrom(getFrom()); if (getReplyTo() != null) { target.setReplyTo(getReplyTo()); if (getTo() != null) { target.setTo(copy(getTo())); if (getCc() != null) { target.setCc(copy(getCc())); if (getBcc() != null) { target.setBcc(copy(getBcc())); if (getSentDate() != null) { target.setSentDate(getSentDate()); if (getSubject() != null) { target.setSubject(getSubject()); if (getText() != null) { target.setText(getText());
@Test public void failedMailServerClose() { MockJavaMailSender sender = new MockJavaMailSender(); sender.setHost(""); sender.setUsername("username"); sender.setPassword("password"); SimpleMailMessage simpleMessage1 = new SimpleMailMessage(); try { sender.send(simpleMessage1); fail("Should have thrown MailSendException"); } catch (MailSendException ex) { // expected ex.printStackTrace(); assertTrue(ex.getFailedMessages() != null); assertEquals(0, ex.getFailedMessages().size()); } }
@Test(expected = IllegalArgumentException.class) public void testCopyToChokesOnNullTargetMessage() throws Exception { new SimpleMailMessage().copyTo(null); }
/** * Copy constructor for creating a new {@code SimpleMailMessage} from the state * of an existing {@code SimpleMailMessage} instance. */ public SimpleMailMessage(SimpleMailMessage original) { Assert.notNull(original, "'original' message argument must not be null"); this.from = original.getFrom(); this.replyTo = original.getReplyTo(); this.to = copyOrNull(original.getTo()); this.cc = copyOrNull(original.getCc()); this.bcc = copyOrNull(original.getBcc()); this.sentDate = original.getSentDate(); this.subject = original.getSubject(); this.text = original.getText(); }
@Test(expected = IllegalArgumentException.class) public void testCopyCtorChokesOnNullOriginalMessage() throws Exception { new SimpleMailMessage(null); }
@Override public void setCc(String cc) throws MailParseException { try { this.helper.setCc(cc); } catch (MessagingException ex) { throw new MailParseException(ex); } }
@Override public void setBcc(String bcc) throws MailParseException { try { this.helper.setBcc(bcc); } catch (MessagingException ex) { throw new MailParseException(ex); } }
@Override public void setReplyTo(String replyTo) throws MailParseException { try { this.helper.setReplyTo(replyTo); } catch (MessagingException ex) { throw new MailParseException(ex); } }
@Override public MimeMessage createMimeMessage(InputStream contentStream) throws MailException { try { return new MimeMessage(getSession(), contentStream); } catch (Exception ex) { throw new MailParseException("Could not parse raw MIME content", ex); } }
@Nullable private static String[] copyOrNull(@Nullable String[] state) { if (state == null) { return null; } return copy(state); }
@Override public void setTo(String to) throws MailParseException { try { this.helper.setTo(to); } catch (MessagingException ex) { throw new MailParseException(ex); } }
@Override public void setCc(String... cc) throws MailParseException { try { this.helper.setCc(cc); } catch (MessagingException ex) { throw new MailParseException(ex); } }
@Override public void setBcc(String... bcc) throws MailParseException { try { this.helper.setBcc(bcc); } catch (MessagingException ex) { throw new MailParseException(ex); } }