Package javax.mail.internet

Examples of javax.mail.internet.ContentType


    public OMElement processDocument(Reader reader, String contentType,
                                     MessageContext messageContext) throws AxisFault {
        String charset;
        try {
            ContentType ct = new ContentType(contentType);
            charset = ct.getParameter("charset");
        } catch (ParseException ex) {
            charset = null;
        }
        if (charset == null) {
            charset = MessageContext.DEFAULT_CHAR_SET_ENCODING;
View Full Code Here


     * @throws IOException
     */
    private Part getMessagePart(Message message, AxisConfiguration axisCfg)
            throws MessagingException, IOException {
       
        ContentType contentType = new ContentType(message.getContentType());
        if (contentType.getBaseType().equalsIgnoreCase("multipart/mixed")) {
            Multipart multipart = (Multipart)message.getContent();
            Part textMainPart = null;
            for (int i=0; i<multipart.getCount(); i++) {
                MimeBodyPart bodyPart = (MimeBodyPart)multipart.getBodyPart(i);
                ContentType partContentType = new ContentType(bodyPart.getContentType());
                if (axisCfg.getMessageBuilder(partContentType.getBaseType()) != null) {
                    if (partContentType.getBaseType().equalsIgnoreCase("text/plain")) {
                        // If it's a text/plain part, remember it. We will return
                        // it later if we don't find something more interesting.
                        textMainPart = bodyPart;
                    } else {
                        return bodyPart;
View Full Code Here

   
    /**
     * Obtains the content of the encoded message, if previously encoded as <code>format=flowed</code>.
     */
    public static String deflow(Message m) throws IOException, MessagingException {
        ContentType ct = new ContentType(m.getContentType());
        String format = ct.getParameter("format");
        if (ct.getBaseType().equals("text/plain") && format != null && format.equalsIgnoreCase("flowed")) {
            String delSp = ct.getParameter("delsp");
            return deflow((String) m.getContent(), delSp != null && delSp.equalsIgnoreCase("yes"));
           
        } else if (ct.getPrimaryType().equals("text")) return (String) m.getContent();
       
        else return null;
    }
View Full Code Here

    /**
     * If the message is <code>format=flowed</code>
     * set the encoded version as message content.
     */
    public static void deflowMessage(Message m) throws MessagingException, IOException {
        ContentType ct = new ContentType(m.getContentType());
        String format = ct.getParameter("format");
        if (ct.getBaseType().equals("text/plain") && format != null && format.equalsIgnoreCase("flowed")) {
            String delSp = ct.getParameter("delsp");
            String deflowed = deflow((String) m.getContent(), delSp != null && delSp.equalsIgnoreCase("yes"));
           
            ct.getParameterList().remove("format");
            ct.getParameterList().remove("delsp");
           
            if (ct.toString().contains("flowed"))
                System.out.println("\n\n*************************\n* ERROR!!! FlowedMessageUtils dind't remove the flowed correctly!\n******************\n\n" + ct.toString() + " \n " + ct.toString() + "\n");
           
            m.setContent(deflowed, ct.toString());
            m.saveChanges();
        }
    }
View Full Code Here

     * Encodes the input text and sets it as the new message content.
     */
    public static void setFlowedContent(Message m, String text, boolean delSp, int width, boolean preserveCharset, String charset) throws MessagingException {
        String coded = flow(text, delSp, width);
        if (preserveCharset) {
            ContentType ct = new ContentType(m.getContentType());
            charset = ct.getParameter("charset");
        }
        ContentType ct = new ContentType();
        ct.setPrimaryType("text");
        ct.setSubType("plain");
        if (charset != null) ct.setParameter("charset", charset);
        ct.setParameter("format", "flowed");
        if (delSp) ct.setParameter("delsp", "yes");
        m.setContent(coded, ct.toString());
        m.saveChanges();
    }
View Full Code Here

    /**
     * Encodes the message content (if text/plain).
     */
    public static void flowMessage(Message m, boolean delSp, int width) throws MessagingException, IOException {
        ContentType ct = new ContentType(m.getContentType());
        if (!ct.getBaseType().equals("text/plain")) return;
        String format = ct.getParameter("format");
        String text = format != null && format.equals("flowed") ? deflow(m) : (String) m.getContent();
        String coded = flow(text, delSp, width);
        ct.setParameter("format", "flowed");
        if (delSp) ct.setParameter("delsp", "yes");
        m.setContent(coded, ct.toString());
        m.saveChanges();
    }
View Full Code Here

    /**
     * Checks whether the input message is <code>format=flowed</code>.
     */
    public static boolean isFlowedTextMessage(Message m) throws MessagingException {
        ContentType ct = new ContentType(m.getContentType());
        String format = ct.getParameter("format");
        return ct.getBaseType().equals("text/plain") && format != null && format.equalsIgnoreCase("flowed");
    }
View Full Code Here

    protected String getCharacterSet(String aType)
    {
        String characterSet = null;
        try
        {
            characterSet = new ContentType(aType).getParameter("charset");
        }
        catch (ParseException e)
        {
            // no-op
        }
View Full Code Here

                if (bodyObj instanceof String) {
                    String body = (String) bodyObj;
                    body = applyPatterns(rConfig.bodyPatterns, rConfig.bodySubstitutions, rConfig.bodyFlags, body, debug, this);
                    String contentType = mail.getMessage().getContentType();
                    if (charset != null) {
                        ContentType ct = new ContentType(contentType);
                        ct.setParameter("charset", charset);
                        contentType = ct.toString();
                    }
                    mail.getMessage().setContent(body, contentType);
                    mod = true;
                    contentChanged = true;
                }
            }
           
            if (charset != null && !contentChanged) {
                ContentType ct = new ContentType(mail.getMessage().getContentType());
                ct.setParameter("charset", charset);
                String contentType = mail.getMessage().getContentType();
                mail.getMessage().setContent(mail.getMessage().getContent(), contentType);
            }
           
            if (mod) mail.getMessage().saveChanges();
View Full Code Here

    }
   
    private static void setContentFromPart(Message m, Part p, String newText, boolean setTextPlain) throws MessagingException, IOException {
        String contentType = p.getContentType();
        if (setTextPlain) {
            ContentType ct = new ContentType(contentType);
            ct.setPrimaryType("text");
            ct.setSubType("plain");
            contentType = ct.toString();
        }
        m.setContent(newText != null ? newText : p.getContent(), contentType);
        String[] h = p.getHeader("Content-Transfer-Encoding");
        if (h != null && h.length > 0) m.setHeader("Content-Transfer-Encoding", h[0]);
        m.saveChanges();
View Full Code Here

TOP

Related Classes of javax.mail.internet.ContentType

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.