/** * <p>Return the size of the message including its headers. * MimeMessage.getSize() method only returns the size of the * message body.</p> * * <p>Note: this size is not guaranteed to be accurate - see Sun's * documentation of MimeMessage.getSize().</p> * * @return approximate size of full message including headers. * * @throws MessagingException if a problem occurs while computing the message size */ public long getMessageSize() throws MessagingException { return MimeMessageUtil.getMessageSize(message); }
/** * Write the headers to an output stream * * @param out the OutputStream to which to write the headers */ public void writeTo(OutputStream out) throws MessagingException{ MimeMessageUtil.writeHeadersTo(getAllHeaderLines(), out); }
/** * Convenience method to take any MimeMessage and write the headers and body to two * different output streams * * @param message the MimeMessage reading from * @param headerOs the OutputStream writting the headers to * @param bodyOs the OutputStream writting the body to * @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) throws IOException, MessagingException { writeTo(message, headerOs, bodyOs, null); }
/** * * @param message * @param headerOs * @param bodyOs * @param ignoreList * @throws MessagingException * @throws IOException * @throws UnsupportedDataTypeException */ public static void writeToInternal(MimeMessage message, OutputStream headerOs, OutputStream bodyOs, String[] ignoreList) throws MessagingException, IOException, UnsupportedDataTypeException { if(message.getMessageID() == null) { message.saveChanges(); } writeHeadersTo(message, headerOs, ignoreList); // Write the body to the output stream writeMessageBodyTo(message, bodyOs); }
/** * Return the full site of an mimeMessage * * @return size of full message including headers * @throws MessagingException if a problem occours while computing the message size */ public static long getMessageSize(MimeMessage message) throws MessagingException { //If we have a MimeMessageWrapper, then we can ask it for just the // message size and skip calculating it long size = -1; if (message instanceof MimeMessageWrapper) { MimeMessageWrapper wrapper = (MimeMessageWrapper) message; size = wrapper.getMessageSize(); } else if (message instanceof MimeMessageCopyOnWriteProxy) { MimeMessageCopyOnWriteProxy wrapper = (MimeMessageCopyOnWriteProxy) message; size = wrapper.getMessageSize(); } if (size == -1) { size = calculateMessageSize(message); } return size; }
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); } }
/** * 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); }
/** * Write the message headers to the given outputstream * * @param message the MimeMessage to read from * @param headerOs the OutputStream to which the headers get written * @param ignoreList the String[] which holds headers which should be ignored * @throws MessagingException */ private static void writeHeadersTo(MimeMessage message, OutputStream headerOs, String[] ignoreList) throws MessagingException { //Write the headers (minus ignored ones) Enumeration headers = message.getNonMatchingHeaderLines(ignoreList); writeHeadersTo(headers, headerOs); }
/** * @return the message size * @throws MessagingException */ public long getMessageSize() throws MessagingException { return MimeMessageUtil.getMessageSize(getWrappedMessage()); }