public static void main(String[] args) { try { final MessageBuilder builder = new DefaultMessageBuilder(); final Message message = builder.parseMessage(new FileInputStream(args[0])); javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(message); } }); } catch (ArrayIndexOutOfBoundsException e) { System.err.println("Wrong number of arguments."); System.err.println("Usage: org.mime4j.samples.tree.MessageTree" + " path/to/message"); } catch (FileNotFoundException e) { System.err.println("The file '" + args[0] + "' could not be found."); } catch (IOException e) { System.err.println("The file '" + args[0] + "' could not be read."); } catch (MimeException e) { System.err.println("The file '" + args[0] + "' is invalid."); } }
public void run(byte[] content, int repetitions) throws Exception { DefaultStorageProvider.setInstance(new MemoryStorageProvider()); MessageBuilder builder = new DefaultMessageBuilder(); for (int i = 0; i < repetitions; i++) { builder.parseMessage(new ByteArrayInputStream(content)); } } }
/** * Creates a new <code>Header</code> from the specified stream. * * @param is * the stream to read the header from. * * @throws IOException * on I/O errors. * @throws MimeIOException * on MIME protocol violations. */ public Message(InputStream is) throws IOException, MimeException { MessageBuilder mb = newMessageBuilder().newMessageBuilder(); org.apache.james.mime4j.dom.Message mImpl = mb.parseMessage(new EOLConvertingInputStream(is)); this.message = mImpl; }
/** * Parse a message and return a simple {@link String} representation of some important fields. * * @param messageBytes the message as {@link java.io.InputStream} * @return String * @throws IOException * @throws MimeException */ private static String messageSummary(InputStream messageBytes) throws IOException, MimeException { MessageBuilder builder = new DefaultMessageBuilder(); Message message = builder.parseMessage(messageBytes); return String.format("\nMessage %s \n" + "Sent by:\t%s\n" + "To:\t%s\n", message.getSubject(), message.getSender(), message.getTo()); } }