Package org.jasen.core

Examples of org.jasen.core.StandardJasenMessage


    public JasenMessage parse(MimeMessage mm) throws JasenParseException {

        try
        {
            List parts = new LinkedList ();
            StandardJasenMessage message = null;

            InternetAddress from = null;

            try
            {
                MimeUtils.getParts (parts, mm);

                message = new StandardJasenMessage ();

                message.setTextPart ((String) MimeUtils.getPartContent (MimeUtils.getFirstPartFromList (parts, MimeType.TEXT_PLAIN, null)));
                message.setHtmlPart ((String) MimeUtils.getPartContent (MimeUtils.getFirstPartFromList (parts, MimeType.TEXT_HTML, null)));

                from = getFromSafe(mm);

                if(from == null) {
                    throw new JasenParseException("Empty from", ParseErrorType.MALFORMED_MIME);
                }

                message.setFrom(from);

                if(mm.getHeader("x-envelope-sender") != null) {
                    message.setEnvelopeSender(mm.getHeader("x-envelope-sender")[0]);
                }
                else
                {
                    message.setEnvelopeSender(message.getFrom().getAddress());
                }

                // Get attachments
                List attachments = MimeUtils.getAllAttachmentParts (parts);

                if (attachments != null && attachments.size () > 0)
                {

                    String[] attachmentNames = new String[attachments.size ()];

                    Iterator i = attachments.iterator ();

                    int count = 0;

                    Part p = null;

                    while (i.hasNext ())
                    {
                        p = (Part) i.next ();
                        try
                        {
                            attachmentNames[count] = p.getFileName ();
                            count++;
                        }
                        catch (MessagingException e)
                        {
                            // Ignore this
                            ErrorHandlerBroker.getInstance().getErrorHandler().handleException(e);
                        }

                    }

                    message.setAttachmentNames (attachmentNames);
                }

            }
            catch (ParseException e)
            {
View Full Code Here

TOP

Related Classes of org.jasen.core.StandardJasenMessage

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.