Package org.apache.james.mime4j.dom

Examples of org.apache.james.mime4j.dom.Message


    assertStructure();
  }

  private void assertSaveMessage(String messageFile) throws MimeException, IOException, FileNotFoundException {
    MessageBuilder builder = new DefaultMessageBuilder();
    Message msg = builder.parseMessage(new FileInputStream(new File(TU.TEST_FOLDER, messageFile)));

    store.save(msg);

    final Resource r = resolver.getResource(getResourcePath(msg, store));
    assertNotNull("Expecting non-null Resource", r);
View Full Code Here


      return mboxIterator.hasNext();
    }

    public Message next() {
      MessageBuilder builder = new DefaultMessageBuilder();
      Message message = null;
      try {
        message = builder.parseMessage(new ByteArrayInputStream(mboxIterator.next().toString().getBytes(MailArchiveServerConstants.DEFAULT_ENCODER.charset().name())));
      } catch (MimeException e) {
        e.printStackTrace();
      } catch (IOException e) {
View Full Code Here

        ResourceResolver resolver = null;
        try {
            resolver = getResourceResolver();
            int mcount = 0;
            while (iterator.hasNext()) {
                Message msg = iterator.next();
                save(resolver, msg);

                mcount++;
                if (mcount % 100 == 0) {
                    logger.debug(mcount+" messages processed.");
View Full Code Here

            is = param.getInputStream();
            pw.println("Creating stats from supplied mbox file...");
            int counter=0;
            final Iterator<Message> it = parser.parse(is);
            while(it.hasNext()) {
                final Message m = it.next();
                final String [] to = MailStatsProcessorImpl.toArray(m.getTo());
                final String [] cc = MailStatsProcessorImpl.toArray(m.getCc());
                for(String from : MailStatsProcessorImpl.toArray(m.getFrom())) {
                    processor.computeStats(m.getDate(), from.toString(), to, cc);
                }
                counter++;
            }
            pw.println(counter + " messages parsed");
        } finally {
View Full Code Here

    Iterator<Message> iter = parser.parse(new FileInputStream(new File(TU.TEST_FOLDER, filePath)));
   
    int cnt = 0;
    Set<Message> set = new HashSet<Message>();
    while (iter.hasNext()) {
      Message message = (Message) iter.next();
      cnt++;
      set.add(message);
    }
    assertEquals("Expecting correct number of messages parsed", expectedMessagesCount, cnt);
    assertEquals("Expecting all messages unique", expectedMessagesCount, set.size());
View Full Code Here

        Iterator<Message> iter = parser.parse(new FileInputStream(new File(TU.TEST_FOLDER, WRONGBODY_MBOX)));

        boolean fail = true;
        int i = 1;
        while (iter.hasNext()) {
            final Message message = iter.next();
            File bodyFile = new File(TU.TEST_FOLDER, specialPathFromFilePath(WRONGBODY_MBOX, "_bodyOf" + i, "txt"));
            if (bodyFile.exists()) {
                final String actual = getPlainBody(message);
                final String expected = readTextFile(bodyFile);
                assertEquals("Body #"+i, expected, actual);
View Full Code Here

        DefaultStorageProvider.setInstance(storageProvider);

        // Create a template message. It would be possible to load a message
        // from an input stream but for this example a message object is created
        // from scratch for demonstration purposes.
        Message template = createTemplate();

        // Create a new message by transforming the template.
        Message transformed = transform(template);

        MessageWriter writer = new DefaultMessageWriter();

        // Print transformed message.
        System.out.println("\n\nTransformed message:\n--------------------\n");
        writer.writeMessage(transformed, System.out);

        // Messages should be disposed of when they are no longer needed.
        // Disposing of a message also disposes of all child elements (e.g. body
        // parts) of the message.
        transformed.dispose();

        // Print original message to illustrate that it was not affected by the
        // transformation.
        System.out.println("\n\nOriginal template:\n------------------\n");
        writer.writeMessage(template, System.out);
View Full Code Here

     */
    private static Message transform(Message original) throws IOException, ParseException {
        // Create a copy of the template. The copy can be modified without
        // affecting the original.
        MessageBuilder builder = new DefaultMessageBuilder();
        Message message = builder.newMessage(original);

        // In this example we know we have a multipart message. Use
        // Message#isMultipart() if uncertain.
        Multipart multipart = (Multipart) message.getBody();

        // Insert a new text/plain body part after every body part of the
        // template.
        final int count = multipart.getCount();
        for (int i = 0; i < count; i++) {
            String text = "Text inserted after part " + (i + 1);
            BodyPart bodyPart = createTextPart(text);
            multipart.addBodyPart(bodyPart, 2 * i + 1);
        }

        // For no particular reason remove the second binary body part (now
        // at index four).
        Entity removed = multipart.removeBodyPart(4);

        // The removed body part no longer has a parent entity it belongs to so
        // it should be disposed of.
        removed.dispose();

        // Set some headers on the transformed message
        message.createMessageId(HOSTNAME);
        message.setSubject("Transformed message");
        message.setDate(new Date());
        message.setFrom(AddressBuilder.DEFAULT.parseMailbox("John Doe <jdoe@machine.example>"));

        return message;
    }
View Full Code Here

    }

    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);
                }
View Full Code Here

    public void startMessage() throws MimeException {
        if (stack.isEmpty()) {
            stack.push(this.entity);
        } else {
            expect(Entity.class);
            Message m = new MessageImpl();
            ((Entity) stack.peek()).setBody(m);
            stack.push(m);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.james.mime4j.dom.Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.