@Override protected InputStream getContentStream() throws MessagingException { try { if (this.contentStream == null) { if (content != null) { return new SharedByteArrayInputStream(content); } else { throw new MessagingException("No content"); } } return this.contentStream; } catch (Exception e) { throw new MessagingException(e.getMessage(),e); } }
/** * Provides a private unstuffed {@link InputStream} for each invocation unless * <code>useCopy</code> is false in which case the <code>data</code> stream * is unstuffed and returned. Unstuffing is made by encapsulating the stream within * special streams. * * @see org.mailster.smtp.util.CharTerminatedInputStream * @see org.mailster.smtp.util.DotUnstuffingInputStream */ public static InputStream getPrivateInputStream(boolean useCopy, InputStream data) { InputStream in = data; if (useCopy) { if (data instanceof SharedByteArrayInputStream) in = ((SharedByteArrayInputStream) data).newStream(0, -1); else if (data instanceof SharedTmpFileInputStream) in = ((SharedTmpFileInputStream) data).newStream(0, -1); else throw new IllegalArgumentException("Unexpected data stream type : " +data.getClass().getName()); } in = new CharTerminatedInputStream(in, SMTP_TERMINATOR); in = new DotUnstuffingInputStream(in); return in; }
/** * Clones the <code>Message</code>. This is a workaround as documented here: http://www.oracle.com/technetwork/java/javamail/faq/index.html#imapserverbug. * The internal Greenmail server is not supporting newer versions of the mail protocol. * @param session * @param n * @return * @throws MessagingException * @throws IOException */ private MimeMessage copy(final Session session, final Message n) throws MessagingException, IOException { final MimeMessage msg = (MimeMessage)n; final ByteArrayOutputStream bos = new ByteArrayOutputStream(); msg.writeTo(bos); bos.close(); final SharedByteArrayInputStream bis = new SharedByteArrayInputStream(bos.toByteArray()); final MimeMessage cmsg = new MimeMessage(session, bis); bis.close(); return cmsg; }
protected void setUp() throws Exception { super.setUp(); mailRepository = getMailRepository(); MimeMessageInputStreamSource mmis = null; try { mmis = new MimeMessageInputStreamSource("test", new SharedByteArrayInputStream((content + sep + body).getBytes())); } catch (MessagingException e) { } mimeMessage = new MimeMessageCopyOnWriteProxy(mmis); Collection<MailAddress> recipients = new ArrayList<MailAddress>(); recipients.add(new MailAddress("rec1", "domain.com")); recipients.add(new MailAddress("rec2", "domain.com")); mail = new MailImpl("mail1", new MailAddress("sender", "domain.com"), recipients, mimeMessage); mail.setAttribute("testAttribute", "testValue"); }
protected MimeMessage getMessageFromSources(String sources) throws Exception { MimeMessageInputStreamSource mmis = null; try { mmis = new MimeMessageInputStreamSource("test", new SharedByteArrayInputStream(sources.getBytes())); } catch (MessagingException e) { } return new TestableMimeMessageWrapper(mmis); }
protected MimeMessage getMessageFromSources(String sources) throws Exception { MimeMessageInputStreamSource mmis = null; try { mmis = new MimeMessageInputStreamSource("test", new SharedByteArrayInputStream(sources.getBytes())); } catch (MessagingException e) { } return new MimeMessageCopyOnWriteProxy(mmis); // return new MimeMessage(Session.getDefaultInstance(new // Properties()),new ByteArrayInputStream(sources.getBytes())); }
/** */ protected InputStream getNewInputStream() throws IOException { if (this.thresholdReached) return new SharedTmpFileInputStream(this.outFile); else return new SharedByteArrayInputStream(asArray(this.buf)); }
public MimeMessageObjectMessageSource(ObjectMessage message) throws JMSException { this.message = message; this.id = message.getJMSMessageID(); this.content = (byte[]) message.getObject(); in = new SharedByteArrayInputStream(content); }
protected MimeMessage getMessageFromSources(String sources) throws Exception { return new MimeMessage(Session.getDefaultInstance(new Properties()), new SharedByteArrayInputStream(sources.getBytes())); }