4 Replies Latest reply on Sep 19, 2006 11:40 AM by osterday

    Willing to pay for answer...

    jhudson

      Hello, I would be willing to pay for a a good code snippet of, starting with the org.jboss.mail.message.Mail, retrieving:
      - body content
      - body content type
      - all attachments with metadata

      I can send instant payment using PayPal. If you let me know what you would charge for the answer, I'll let you know if I can pay for it Thank you very much for your time.

      Joe

        • 1. Re: Willing to pay for answer...
          jhudson

          Please, can anybody help? I currently am using integrated James but *really* want to switch all the way over to JBoss. But, since it doesn't use the javax.mail.internet.MimeMessage, I'm not sure how to parse the content.

          I am willing to pay for the answer... Thanks for your time.

          Joe Hudson

          • 2. Re: Willing to pay for answer...
            sappenin

            You may want to wait a few days because I think Andy is re-writing some of the code to handle MIME messages.

            • 3. Re: Willing to pay for answer...
              jhudson

              Ok, thank you very much for the reply. I'm sure that will help me. Thank you.

              Joe

              • 4. Re: Willing to pay for answer...
                osterday

                I'm looking forward to checking out Andy's code as well.

                I the mean time, here's what I'm doing - even if it's not pretty, it does work! (I know there are known "problems" with javax.mail, but for the time being we can view messages.)

                Sorry, I can't post the complete code for some of the stuff we're doing, but I think this is good enough for a starting point!

                You need to get the sender mbean doing something like this:
                (There are examples in the JBCS code to see a complete example.)

                private String chainName = "jboss.mail:type=MailServices,name=MailSender";
                sender = (MailSender) JBMailJMXUtil.getMBean(chainName, MailSender.class);
                


                Then you can get the MailboxService from the sender
                MailboxService mbs = this.sender.getMailboxManager();
                


                I do this in a try/catch - writeMessage is copied from the pop3 code...
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                this.writeMessage(out, message, mbs);
                ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
                String cte = message.getHeader("Content-Transfer-Encoding");
                MimeMessage mimeMessage = createMimeMessage(cte, in);
                


                To create a MimeMessage I can use, I do this...
                (The content type decoding isn't 100% and I'm not sure why, but works for most things that have content type encoding.)
                private MimeMessage createMimeMessage(String cte, InputStream in) {
                 Properties props = new Properties();
                 Session session = Session.getInstance(props);
                 MimeMessage mimeMessage = null;
                 if (cte != null) {
                 cte = cte.trim();
                 log.debug("Decoding CTE as: " + cte);
                 try {
                 InputStream decodeIs = MimeUtility.decode(in, cte);
                 mimeMessage = new MimeMessage(session, decodeIs);
                 decodeIs.close();
                 } catch (Exception e) {
                 log.debug("Error creating MIME message. " + e.getMessage());
                 }
                 } else {
                 try {
                 mimeMessage = new MimeMessage(session, in);
                 } catch (Exception e) {
                 log.debug("Error creating MIME message. " + e.getMessage());
                 }
                 }
                 return mimeMessage;
                }
                


                Then you can process the MimeMessage to get the content, attachments, etc.
                Hope that helps!