/** * 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); } }
private synchronized void checkModifyHeaders() throws MessagingException { // Disable only-header loading optimizations for JAMES-559 if (!messageParsed) { loadMessage(); } // End JAMES-559 if (headers == null) { loadHeaders(); } modified = true; saved = false; headersModified = true; }
/** * @param original * MimeMessageSource * @throws MessagingException */ public MimeMessageCopyOnWriteProxy(MimeMessageSource original) throws MessagingException { this(new MimeMessageWrapper(original), true); }
MimeMessageWrapper wrapper = (MimeMessageWrapper) message; if (DEEP_DEBUG) { System.out.println("Retrieving from: " + wrapper.getSourceId()); 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 (destinationBuffer.toString().equals(wrapper.getSourceId())) { if (!wrapper.isModified()) { ((MimeMessageWrapper) message).loadMessage(); out = streamRepository.put(key); ((MimeMessageWrapper) message).writeTo(out, out, null, true);
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); } }
MimeMessageWrapper wrapper = (MimeMessageWrapper) message; if (DEEP_DEBUG) { System.out.println("Retrieving from: " + wrapper.getSourceId()); StringBuffer debugBuffer = new StringBuffer(64) .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()) {
/** * Rewritten for optimization purposes */ public void writeTo(OutputStream os, String[] ignoreList) throws IOException, MessagingException { writeTo(os, os, ignoreList); }
/** * @see javax.mail.internet.MimeMessage#getContentStream() */ protected InputStream getContentStream() throws MessagingException { if (!messageParsed) { loadMessage(); } return super.getContentStream(); }
InputStream in=null; try{ in = getContentStream(); }catch(Exception e){ return -1; if (getEncoding() != null) { counter = new LineNumberReader(new InputStreamReader(in, getEncoding())); } else { counter = new LineNumberReader(new InputStreamReader(in));
public void removeHeader(String name) throws MessagingException { checkModifyHeaders(); super.removeHeader(name); }
/** * Load the message headers from the internal source. * * @throws MessagingException if an error is encountered while * loading the headers */ protected synchronized void loadHeaders() throws MessagingException { if (headers != null) { //Another thread has already loaded these headers return; } else if (source != null) { try { InputStream in = source.getInputStream(); try { headers = createInternetHeaders(in); } finally { IOUtils.closeQuietly(in); } } catch (IOException ioe) { throw new MessagingException("Unable to parse headers from stream: " + ioe.getMessage(), ioe); } } else { throw new MessagingException("loadHeaders called for a message with no source, contentStream or stream"); } }
/** * 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); } }
/** * Write */ public void writeTo(OutputStream headerOs, OutputStream bodyOs) throws IOException, MessagingException { writeTo(headerOs, bodyOs, new String[0]); }
/** * This is the MimeMessage implementation - this should return ONLY the * body, not the entire message (should not count headers). Will have * to parse the message. */ public int getSize() throws MessagingException { if (!messageParsed) { loadMessage(); } return super.getSize(); }
public void setHeader(String name, String value) throws MessagingException { checkModifyHeaders(); super.setHeader(name, value); }
/** * 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); }
/** * @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(); }
public void addHeader(String name, String value) throws MessagingException { checkModifyHeaders(); super.addHeader(name, value); }
/** * Check the number of references over the MimeMessage and clone it if * needed before returning the reference * * @throws MessagingException * exception */ protected synchronized MimeMessage getWrappedMessageForWriting() throws MessagingException { if (refCount.getReferenceCount() > 1) { refCount.decrementReferenceCount(); refCount = new MessageReferenceTracker(new MimeMessageWrapper(refCount.getWrapped())); } return refCount.getWrapped(); }
/** * 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); } }