/** * Rewritten for optimization purposes */ public synchronized void writeTo(OutputStream os) throws IOException, MessagingException { if (source != null && !isModified()) { // We do not want to instantiate the message... just read from source // and write to this outputstream InputStream in = source.getInputStream(); try { IOUtils.copy(in, os); } finally { IOUtils.closeQuietly(in); } } else { writeTo(os, os); } }
public synchronized void writeTo(OutputStream headerOs, OutputStream bodyOs, String[] ignoreList) throws IOException, MessagingException { if (source != null && !isModified()) { //We do not want to instantiate the message... just read from source // and write to this outputstream //First handle the headers InputStream in = source.getInputStream(); try { InternetHeaders headers = new InternetHeaders(in); IOUtils.copy(new InternetHeadersInputStream(headers), headerOs); IOUtils.copy(in, bodyOs); } finally { IOUtils.closeQuietly(in); } } else { MimeMessageUtil.writeToInternal(this, headerOs, bodyOs, ignoreList); } }
/** * Returns size of message, ie headers and content */ public long getMessageSize() throws MessagingException { if (source != null && !isModified()) { try { return source.getMessageSize(); } catch (IOException ioe) { throw new MessagingException("Error retrieving message size", ioe); } } else { return MimeMessageUtil.calculateMessageSize(this); } }
/** * @see javax.mail.internet.MimeMessage#getRawInputStream() */ public InputStream getRawInputStream() throws MessagingException { if (!messageParsed && !isModified() && source != null) { InputStream is; try { is = source.getInputStream(); // skip the headers. new MailHeaders(is); return is; } catch (IOException e) { throw new MessagingException("Unable to read the stream: " + e.getMessage(), e); } } else return super.getRawInputStream(); }
/** * Return an {@link InputStream} which holds the full content of the message. This method * tries to optimize this call as far as possible * * @return messageInputStream * @throws MessagingException */ public synchronized InputStream getMessageInputStream() throws MessagingException{ if (!messageParsed && !isModified() && source != null) { try { return source.getInputStream(); } catch (IOException e) { throw new MessagingException("Unable to get inputstream", e); } } else { return new MimeMessageInputStream(this, false); } }
.append(mc.getName()); System.out.println(debugBuffer.toString()); System.out.println("Modified: " + wrapper.isModified()); .append("/") .append(mc.getName()); if (destinationBuffer.toString().equals(wrapper.getSourceId()) && !wrapper.isModified()) {
StringBuffer debugBuffer = new StringBuffer(64).append("Saving to: ").append(destination).append("/").append(mc.getName()); System.out.println(debugBuffer.toString()); System.out.println("Modified: " + wrapper.isModified()); if (!wrapper.isModified()) {
/** * Convenience method to take any MimeMessage and write the headers and body to two * different output streams, with an ignore list * * @param message the MimeMessage reading from * @param headerOs the OutputStream writting the headers to * @param bodyOs the OutputStream writting the body to * @param ignoreList the String[] which contains headers which should be ignored * @throws IOException get thrown if an IO Error detected while writing to the streams * @throws MessagingException get thrown if an error detected while reading the message */ public static void writeTo(MimeMessage message, OutputStream headerOs, OutputStream bodyOs, String[] ignoreList) throws IOException, MessagingException { MimeMessage testMessage = message; if (message instanceof MimeMessageCopyOnWriteProxy) { MimeMessageCopyOnWriteProxy wr = (MimeMessageCopyOnWriteProxy) message; testMessage = wr.getWrappedMessage(); } if (testMessage instanceof MimeMessageWrapper) { MimeMessageWrapper wrapper = (MimeMessageWrapper)testMessage; if (!wrapper.isModified()) { wrapper.writeTo(headerOs, bodyOs, ignoreList); return; } } writeToInternal(message, headerOs, bodyOs, ignoreList); }