com.sun.xml.internal.messaging.saaj.packaging.mime.MessagingException Java Examples

The following examples show how to use com.sun.xml.internal.messaging.saaj.packaging.mime.MessagingException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MimeUtility.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Wrap an encoder around the given output stream.
 * All the encodings defined in RFC 2045 are supported here.
 * They include "base64", "quoted-printable", "7bit", "8bit" and
 * "binary". In addition, "uuencode" is also supported.
 * The <code>filename</code> parameter is used with the "uuencode"
 * encoding and is included in the encoded output.
 *
 * @param   os              output stream
 * @param   encoding        the encoding of the stream.
 * @param   filename        name for the file being encoded (only used
 *                          with uuencode)
 * @return                  output stream that applies the
 *                          specified encoding.
 * @since                   JavaMail 1.2
 */
public static OutputStream encode(OutputStream os, String encoding,
                                  String filename)
            throws MessagingException {
    if (encoding == null)
        return os;
    else if (encoding.equalsIgnoreCase("base64"))
        return new BASE64EncoderStream(os);
    else if (encoding.equalsIgnoreCase("quoted-printable"))
        return new QPEncoderStream(os);
    else if (encoding.equalsIgnoreCase("uuencode") ||
             encoding.equalsIgnoreCase("x-uuencode") ||
             encoding.equalsIgnoreCase("x-uue"))
        return new UUEncoderStream(os, filename);
    else if (encoding.equalsIgnoreCase("binary") ||
             encoding.equalsIgnoreCase("7bit") ||
             encoding.equalsIgnoreCase("8bit"))
        return os;
    else
        throw new MessagingException("Unknown encoding: " +encoding);
}
 
Example #2
Source File: MimePullMultipart.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
protected  void readSOAPPart() throws  MessagingException {
    try {
        if (soapPart != null) {
            return;
        }
        in = dataSource.getInputStream();
        MIMEConfig config = new MIMEConfig(); //use defaults
        mm = new MIMEMessage(in, boundary, config);
        String st = contType.getParameter("start");
        if(startParam == null) {
            soapPart = mm.getPart(0);
        } else {
              // Strip <...> from root part's Content-I
            if (st != null && st.length() > 2 && st.charAt(0) == '<' && st.charAt(st.length()-1) == '>') {
                st = st.substring(1, st.length()-1);
            }
            startParam = st;
            soapPart = mm.getPart(startParam);

        }
    } catch (IOException ex) {
        throw new MessagingException("No inputstream from datasource", ex);
    }
}
 
Example #3
Source File: MimePullMultipart.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
protected  void readSOAPPart() throws  MessagingException {
    try {
        if (soapPart != null) {
            return;
        }
        in = dataSource.getInputStream();
        MIMEConfig config = new MIMEConfig(); //use defaults
        mm = new MIMEMessage(in, boundary, config);
        String st = contType.getParameter("start");
        if(startParam == null) {
            soapPart = mm.getPart(0);
        } else {
              // Strip <...> from root part's Content-I
            if (st != null && st.length() > 2 && st.charAt(0) == '<' && st.charAt(st.length()-1) == '>') {
                st = st.substring(1, st.length()-1);
            }
            startParam = st;
            soapPart = mm.getPart(startParam);

        }
    } catch (IOException ex) {
        throw new MessagingException("No inputstream from datasource", ex);
    }
}
 
Example #4
Source File: MimeBodyPart.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Set the "Content-Disposition" header field of this body part.
 * If the disposition is null, any existing "Content-Disposition"
 * header field is removed.
 *
 * @exception       IllegalStateException if this body part is
 *                  obtained from a READ_ONLY folder.
 */
public void setDisposition(String disposition) throws MessagingException {
    if (disposition == null)
        removeHeader("Content-Disposition");
    else {
        String s = getHeader("Content-Disposition", null);
        if (s != null) {
            /* A Content-Disposition header already exists ..
             *
             * Override disposition, but attempt to retain
             * existing disposition parameters
             */
            ContentDisposition cd = new ContentDisposition(s);
            cd.setDisposition(disposition);
            disposition = cd.toString();
        }
        setHeader("Content-Disposition", disposition);
    }
}
 
Example #5
Source File: MimeUtility.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Decode the given input stream. The Input stream returned is
 * the decoded input stream. All the encodings defined in RFC 2045
 * are supported here. They include "base64", "quoted-printable",
 * "7bit", "8bit", and "binary". In addition, "uuencode" is also
 * supported.
 *
 * @param   is              input stream
 * @param   encoding        the encoding of the stream.
 * @return                  decoded input stream.
 */
public static InputStream decode(InputStream is, String encoding)
            throws MessagingException {
    if (encoding.equalsIgnoreCase("base64"))
        return new BASE64DecoderStream(is);
    else if (encoding.equalsIgnoreCase("quoted-printable"))
        return new QPDecoderStream(is);
    else if (encoding.equalsIgnoreCase("uuencode") ||
             encoding.equalsIgnoreCase("x-uuencode") ||
             encoding.equalsIgnoreCase("x-uue"))
        return new UUDecoderStream(is);
    else if (encoding.equalsIgnoreCase("binary") ||
             encoding.equalsIgnoreCase("7bit") ||
             encoding.equalsIgnoreCase("8bit"))
        return is;
    else
        throw new MessagingException("Unknown encoding: " + encoding);
}
 
Example #6
Source File: MimeUtility.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Decode the given input stream. The Input stream returned is
 * the decoded input stream. All the encodings defined in RFC 2045
 * are supported here. They include "base64", "quoted-printable",
 * "7bit", "8bit", and "binary". In addition, "uuencode" is also
 * supported.
 *
 * @param   is              input stream
 * @param   encoding        the encoding of the stream.
 * @return                  decoded input stream.
 */
public static InputStream decode(InputStream is, String encoding)
            throws MessagingException {
    if (encoding.equalsIgnoreCase("base64"))
        return new BASE64DecoderStream(is);
    else if (encoding.equalsIgnoreCase("quoted-printable"))
        return new QPDecoderStream(is);
    else if (encoding.equalsIgnoreCase("uuencode") ||
             encoding.equalsIgnoreCase("x-uuencode") ||
             encoding.equalsIgnoreCase("x-uue"))
        return new UUDecoderStream(is);
    else if (encoding.equalsIgnoreCase("binary") ||
             encoding.equalsIgnoreCase("7bit") ||
             encoding.equalsIgnoreCase("8bit"))
        return is;
    else
        throw new MessagingException("Unknown encoding: " + encoding);
}
 
Example #7
Source File: MimePullMultipart.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void parseAll() throws MessagingException {
    if (parsed) {
        return;
    }
    if (soapPart == null) {
        readSOAPPart();
    }

    List<MIMEPart> prts = mm.getAttachments();
    for(MIMEPart part : prts) {
        if (part != soapPart) {
            AttachmentPart attach = new AttachmentPartImpl(part);
            this.addBodyPart(new MimeBodyPart(part));
        }
   }
   parsed = true;
}
 
Example #8
Source File: MimePullMultipart.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected  void readSOAPPart() throws  MessagingException {
    try {
        if (soapPart != null) {
            return;
        }
        in = dataSource.getInputStream();
        MIMEConfig config = new MIMEConfig(); //use defaults
        mm = new MIMEMessage(in, boundary, config);
        String st = contType.getParameter("start");
        if(startParam == null) {
            soapPart = mm.getPart(0);
        } else {
              // Strip <...> from root part's Content-I
            if (st != null && st.length() > 2 && st.charAt(0) == '<' && st.charAt(st.length()-1) == '>') {
                st = st.substring(1, st.length()-1);
            }
            startParam = st;
            soapPart = mm.getPart(startParam);

        }
    } catch (IOException ex) {
        throw new MessagingException("No inputstream from datasource", ex);
    }
}
 
Example #9
Source File: MimePullMultipart.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void parseAll() throws MessagingException {
    if (parsed) {
        return;
    }
    if (soapPart == null) {
        readSOAPPart();
    }

    List<MIMEPart> prts = mm.getAttachments();
    for(MIMEPart part : prts) {
        if (part != soapPart) {
            AttachmentPart attach = new AttachmentPartImpl(part);
            this.addBodyPart(new MimeBodyPart(part));
        }
   }
   parsed = true;
}
 
Example #10
Source File: MessageImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void initializeAllAttachments ()
   throws MessagingException, SOAPException {
   if (switchOffBM || switchOffLazyAttachment) {
       return;
   }

   if (attachmentsInitialized || (multiPart == null)) {
       return;
   }

   if (attachments == null)
       attachments = new FinalArrayList();

   int count = multiPart.getCount();
   for (int i=0; i < count; i++ ) {
       initializeAttachment(multiPart.getBodyPart(i));
   }
   attachmentsInitialized = true;
   //multiPart = null;
   needsSave();
}
 
Example #11
Source File: MimeBodyPart.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get the filename associated with this body part. <p>
 *
 * Returns the value of the "filename" parameter from the
 * "Content-Disposition" header field of this body part. If its
 * not available, returns the value of the "name" parameter from
 * the "Content-Type" header field of this body part.
 * Returns <code>null</code> if both are absent.
 *
 * @return  filename
 * @exception MessagingException in case of error
 */
public String getFileName() throws MessagingException {
    String filename = null;
    String s = getHeader("Content-Disposition", null);

    if (s != null) {
        // Parse the header ..
        ContentDisposition cd = new ContentDisposition(s);
        filename = cd.getParameter("filename");
    }
    if (filename == null) {
        // Still no filename ? Try the "name" ContentType parameter
        s = getHeader("Content-Type", null);
        if (s != null) {
        try {
            ContentType ct = new ContentType(s);
            filename = ct.getParameter("name");
        } catch (ParseException pex) { }    // ignore it
        }
    }
    return filename;
}
 
Example #12
Source File: MimeBodyPart.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get the filename associated with this body part. <p>
 *
 * Returns the value of the "filename" parameter from the
 * "Content-Disposition" header field of this body part. If its
 * not available, returns the value of the "name" parameter from
 * the "Content-Type" header field of this body part.
 * Returns <code>null</code> if both are absent.
 *
 * @return  filename
 */
public String getFileName() throws MessagingException {
    String filename = null;
    String s = getHeader("Content-Disposition", null);

    if (s != null) {
        // Parse the header ..
        ContentDisposition cd = new ContentDisposition(s);
        filename = cd.getParameter("filename");
    }
    if (filename == null) {
        // Still no filename ? Try the "name" ContentType parameter
        s = getHeader("Content-Type", null);
        if (s != null) {
        try {
            ContentType ct = new ContentType(s);
            filename = ct.getParameter("name");
        } catch (ParseException pex) { }    // ignore it
        }
    }
    return filename;
}
 
Example #13
Source File: MimeBodyPart.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Set the filename associated with this body part, if possible. <p>
 *
 * Sets the "filename" parameter of the "Content-Disposition"
 * header field of this body part.
 *
 * @param filename filename
 *
 * @exception MessagingException in case of error
 * @exception       IllegalStateException if this body part is
 *                  obtained from a READ_ONLY folder.
 */
public void setFileName(String filename) throws MessagingException {
    // Set the Content-Disposition "filename" parameter
    String s = getHeader("Content-Disposition", null);
    ContentDisposition cd =
        new ContentDisposition(s == null ? ATTACHMENT : s);
    cd.setParameter("filename", filename);
    setHeader("Content-Disposition", cd.toString());

    /* Also attempt to set the Content-Type "name" parameter,
     * to satisfy ancient MUAs.
     * XXX: This is not RFC compliant, and hence should really
     * be conditional based on some property. Fix this once we
     * figure out how to get at Properties from here !
     */
    s = getHeader("Content-Type", null);
    if (s != null) {
        try {
        ContentType cType = new ContentType(s);
        cType.setParameter("name", filename);
        setHeader("Content-Type", cType.toString());
        } catch (ParseException pex) { }    // ignore it
    }
}
 
Example #14
Source File: MessageImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void initializeAllAttachments ()
   throws MessagingException, SOAPException {
   if (switchOffBM || switchOffLazyAttachment) {
       return;
   }

   if (attachmentsInitialized || (multiPart == null)) {
       return;
   }

   if (attachments == null)
       attachments = new FinalArrayList();

   int count = multiPart.getCount();
   for (int i=0; i < count; i++ ) {
       initializeAttachment(multiPart.getBodyPart(i));
   }
   attachmentsInitialized = true;
   //multiPart = null;
   needsSave();
}
 
Example #15
Source File: MimeMultipart.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get the MimeBodyPart referred to by the given ContentID (CID).
 * Returns null if the part is not found.
 *
 * @param  CID      the ContentID of the desired part
 * @return          the MimeBodyPart
 * @exception       MessagingException if no such MimeBodyPart exists.
 */
public  MimeBodyPart getBodyPart(String CID)
        throws MessagingException {
    parse();

    int count = getCount();
    for (int i = 0; i < count; i++) {
       MimeBodyPart part = getBodyPart(i);
       String s = part.getContentID();
           // Old versions of AXIS2 put angle brackets around the content
           // id but not the start param
           String sNoAngle = (s!= null) ? s.replaceFirst("^<", "").replaceFirst(">$", "")
                   :null;
       if (s != null && (s.equals(CID) || CID.equals(sNoAngle)))
           return part;
    }
    return null;
}
 
Example #16
Source File: MimeUtility.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Wrap an encoder around the given output stream.
 * All the encodings defined in RFC 2045 are supported here.
 * They include "base64", "quoted-printable", "7bit", "8bit" and
 * "binary". In addition, "uuencode" is also supported.
 * The <code>filename</code> parameter is used with the "uuencode"
 * encoding and is included in the encoded output.
 *
 * @param   os              output stream
 * @param   encoding        the encoding of the stream.
 * @param   filename        name for the file being encoded (only used
 *                          with uuencode)
 * @return                  output stream that applies the
 *                          specified encoding.
 * @exception MessagingException in case of error
 * @since                   JavaMail 1.2
 */
public static OutputStream encode(OutputStream os, String encoding,
                                  String filename)
            throws MessagingException {
    if (encoding == null)
        return os;
    else if (encoding.equalsIgnoreCase("base64"))
        return new BASE64EncoderStream(os);
    else if (encoding.equalsIgnoreCase("quoted-printable"))
        return new QPEncoderStream(os);
    else if (encoding.equalsIgnoreCase("uuencode") ||
             encoding.equalsIgnoreCase("x-uuencode") ||
             encoding.equalsIgnoreCase("x-uue"))
        return new UUEncoderStream(os, filename);
    else if (encoding.equalsIgnoreCase("binary") ||
             encoding.equalsIgnoreCase("7bit") ||
             encoding.equalsIgnoreCase("8bit"))
        return os;
    else
        throw new MessagingException("Unknown encoding: " +encoding);
}
 
Example #17
Source File: MimePullMultipart.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected  void readSOAPPart() throws  MessagingException {
    try {
        if (soapPart != null) {
            return;
        }
        in = dataSource.getInputStream();
        MIMEConfig config = new MIMEConfig(); //use defaults
        mm = new MIMEMessage(in, boundary, config);
        String st = contType.getParameter("start");
        if(startParam == null) {
            soapPart = mm.getPart(0);
        } else {
              // Strip <...> from root part's Content-I
            if (st != null && st.length() > 2 && st.charAt(0) == '<' && st.charAt(st.length()-1) == '>') {
                st = st.substring(1, st.length()-1);
            }
            startParam = st;
            soapPart = mm.getPart(startParam);

        }
    } catch (IOException ex) {
        throw new MessagingException("No inputstream from datasource", ex);
    }
}
 
Example #18
Source File: MimePullMultipart.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public void parseAll() throws MessagingException {
    if (parsed) {
        return;
    }
    if (soapPart == null) {
        readSOAPPart();
    }

    List<MIMEPart> prts = mm.getAttachments();
    for(MIMEPart part : prts) {
        if (part != soapPart) {
            AttachmentPart attach = new AttachmentPartImpl(part);
            this.addBodyPart(new MimeBodyPart(part));
        }
   }
   parsed = true;
}
 
Example #19
Source File: MessageImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private void initializeAllAttachments ()
   throws MessagingException, SOAPException {
   if (switchOffBM || switchOffLazyAttachment) {
       return;
   }

   if (attachmentsInitialized || (multiPart == null)) {
       return;
   }

   if (attachments == null)
       attachments = new FinalArrayList();

   int count = multiPart.getCount();
   for (int i=0; i < count; i++ ) {
       initializeAttachment(multiPart.getBodyPart(i));
   }
   attachmentsInitialized = true;
   //multiPart = null;
   needsSave();
}
 
Example #20
Source File: BMMimeMultipart.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the InputStream from our DataSource, constructing the
 * appropriate MimeBodyParts.  The <code>parsed</code> flag is
 * set to true, and if true on entry nothing is done.  This
 * method is called by all other methods that need data for
 * the body parts, to make sure the data has been parsed.
 *
 * @since JavaMail 1.2
 */
@Override
protected void parse() throws MessagingException {
    if (parsed)
        return;

    initStream();

    SharedInputStream sin = null;
    if (in instanceof SharedInputStream) {
        sin = (SharedInputStream) in;
    }

    String bnd = "--" + boundary;
    byte[] bndbytes = ASCIIUtility.getBytes(bnd);
    try {
        parse(in, bndbytes, sin);
    } catch (IOException ioex) {
        throw new MessagingException("IO Error", ioex);
    } catch (Exception ex) {
        throw new MessagingException("Error", ex);
    }

    parsed = true;
}
 
Example #21
Source File: MimeUtility.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Decode the given input stream. The Input stream returned is
 * the decoded input stream. All the encodings defined in RFC 2045
 * are supported here. They include "base64", "quoted-printable",
 * "7bit", "8bit", and "binary". In addition, "uuencode" is also
 * supported.
 *
 * @param   is              input stream
 * @param   encoding        the encoding of the stream.
 * @return                  decoded input stream.
 */
public static InputStream decode(InputStream is, String encoding)
            throws MessagingException {
    if (encoding.equalsIgnoreCase("base64"))
        return new BASE64DecoderStream(is);
    else if (encoding.equalsIgnoreCase("quoted-printable"))
        return new QPDecoderStream(is);
    else if (encoding.equalsIgnoreCase("uuencode") ||
             encoding.equalsIgnoreCase("x-uuencode") ||
             encoding.equalsIgnoreCase("x-uue"))
        return new UUDecoderStream(is);
    else if (encoding.equalsIgnoreCase("binary") ||
             encoding.equalsIgnoreCase("7bit") ||
             encoding.equalsIgnoreCase("8bit"))
        return is;
    else
        throw new MessagingException("Unknown encoding: " + encoding);
}
 
Example #22
Source File: MimeUtility.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Wrap an encoder around the given output stream.
 * All the encodings defined in RFC 2045 are supported here.
 * They include "base64", "quoted-printable", "7bit", "8bit" and
 * "binary". In addition, "uuencode" is also supported.
 *
 * @param   os              output stream
 * @param   encoding        the encoding of the stream.
 * @return                  output stream that applies the
 *                          specified encoding.
 */
public static OutputStream encode(OutputStream os, String encoding)
            throws MessagingException {
    if (encoding == null)
        return os;
    else if (encoding.equalsIgnoreCase("base64"))
        return new BASE64EncoderStream(os);
    else if (encoding.equalsIgnoreCase("quoted-printable"))
        return new QPEncoderStream(os);
    else if (encoding.equalsIgnoreCase("uuencode") ||
             encoding.equalsIgnoreCase("x-uuencode") ||
             encoding.equalsIgnoreCase("x-uue"))
        return new UUEncoderStream(os);
    else if (encoding.equalsIgnoreCase("binary") ||
             encoding.equalsIgnoreCase("7bit") ||
             encoding.equalsIgnoreCase("8bit"))
        return os;
    else
        throw new MessagingException("Unknown encoding: " +encoding);
}
 
Example #23
Source File: MimeUtility.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Decode the given input stream. The Input stream returned is
 * the decoded input stream. All the encodings defined in RFC 2045
 * are supported here. They include "base64", "quoted-printable",
 * "7bit", "8bit", and "binary". In addition, "uuencode" is also
 * supported.
 *
 * @param   is              input stream
 * @param   encoding        the encoding of the stream.
 * @return                  decoded input stream.
 */
public static InputStream decode(InputStream is, String encoding)
            throws MessagingException {
    if (encoding.equalsIgnoreCase("base64"))
        return new BASE64DecoderStream(is);
    else if (encoding.equalsIgnoreCase("quoted-printable"))
        return new QPDecoderStream(is);
    else if (encoding.equalsIgnoreCase("uuencode") ||
             encoding.equalsIgnoreCase("x-uuencode") ||
             encoding.equalsIgnoreCase("x-uue"))
        return new UUDecoderStream(is);
    else if (encoding.equalsIgnoreCase("binary") ||
             encoding.equalsIgnoreCase("7bit") ||
             encoding.equalsIgnoreCase("8bit"))
        return is;
    else
        throw new MessagingException("Unknown encoding: " + encoding);
}
 
Example #24
Source File: MimePartDataSource.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an input stream from this  MimeBodyPart. <p>
 *
 * This method applies the appropriate transfer-decoding, based
 * on the Content-Transfer-Encoding attribute of this MimeBodyPart.
 * Thus the returned input stream is a decoded stream of bytes.<p>
 *
 * This implementation obtains the raw content from the MimeBodyPart
 * using the <code>getContentStream()</code> method and decodes
 * it using the <code>MimeUtility.decode()</code> method.
 *
 * @return decoded input stream
 */
@Override
public InputStream getInputStream() throws IOException {

    try {
        InputStream is = part.getContentStream();

        String encoding = part.getEncoding();
        if (encoding != null)
            return MimeUtility.decode(is, encoding);
        else
            return is;
    } catch (MessagingException mex) {
        throw new IOException(mex.getMessage());
    }
}
 
Example #25
Source File: MimePullMultipart.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
protected  void readSOAPPart() throws  MessagingException {
    try {
        if (soapPart != null) {
            return;
        }
        in = dataSource.getInputStream();
        MIMEConfig config = new MIMEConfig(); //use defaults
        mm = new MIMEMessage(in, boundary, config);
        String st = contType.getParameter("start");
        if(startParam == null) {
            soapPart = mm.getPart(0);
        } else {
              // Strip <...> from root part's Content-I
            if (st != null && st.length() > 2 && st.charAt(0) == '<' && st.charAt(st.length()-1) == '>') {
                st = st.substring(1, st.length()-1);
            }
            startParam = st;
            soapPart = mm.getPart(startParam);

        }
    } catch (IOException ex) {
        throw new MessagingException("No inputstream from datasource", ex);
    }
}
 
Example #26
Source File: MimeBodyPart.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Set the "Content-Disposition" header field of this body part.
 * If the disposition is null, any existing "Content-Disposition"
 * header field is removed.
 *
 * @exception       IllegalStateException if this body part is
 *                  obtained from a READ_ONLY folder.
 */
public void setDisposition(String disposition) throws MessagingException {
    if (disposition == null)
        removeHeader("Content-Disposition");
    else {
        String s = getHeader("Content-Disposition", null);
        if (s != null) {
            /* A Content-Disposition header already exists ..
             *
             * Override disposition, but attempt to retain
             * existing disposition parameters
             */
            ContentDisposition cd = new ContentDisposition(s);
            cd.setDisposition(disposition);
            disposition = cd.toString();
        }
        setHeader("Content-Disposition", disposition);
    }
}
 
Example #27
Source File: MimeBodyPart.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Set the filename associated with this body part, if possible. <p>
 *
 * Sets the "filename" parameter of the "Content-Disposition"
 * header field of this body part.
 *
 * @exception       IllegalStateException if this body part is
 *                  obtained from a READ_ONLY folder.
 */
public void setFileName(String filename) throws MessagingException {
    // Set the Content-Disposition "filename" parameter
    String s = getHeader("Content-Disposition", null);
    ContentDisposition cd =
        new ContentDisposition(s == null ? ATTACHMENT : s);
    cd.setParameter("filename", filename);
    setHeader("Content-Disposition", cd.toString());

    /* Also attempt to set the Content-Type "name" parameter,
     * to satisfy ancient MUAs.
     * XXX: This is not RFC compliant, and hence should really
     * be conditional based on some property. Fix this once we
     * figure out how to get at Properties from here !
     */
    s = getHeader("Content-Type", null);
    if (s != null) {
        try {
        ContentType cType = new ContentType(s);
        cType.setParameter("name", filename);
        setHeader("Content-Type", cType.toString());
        } catch (ParseException pex) { }    // ignore it
    }
}
 
Example #28
Source File: BMMimeMultipart.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a MimeMultipart object and its bodyparts from the
 * given DataSource. <p>
 *
 * This constructor handles as a special case the situation where the
 * given DataSource is a MultipartDataSource object.  In this case, this
 * method just invokes the superclass (i.e., Multipart) constructor
 * that takes a MultipartDataSource object. <p>
 *
 * Otherwise, the DataSource is assumed to provide a MIME multipart
 * byte stream.  The <code>parsed</code> flag is set to false.  When
 * the data for the body parts are needed, the parser extracts the
 * "boundary" parameter from the content type of this DataSource,
 * skips the 'preamble' and reads bytes till the terminating
 * boundary and creates MimeBodyParts for each part of the stream.
 *
 * @param   ct  content type.
 * @param   ds  DataSource, can be a MultipartDataSource.
 * @throws  MessagingException in case of error.
 */
public BMMimeMultipart(DataSource ds, ContentType ct)
        throws MessagingException {
    super(ds, ct);
    boundary = ct.getParameter("boundary");
    /*
if (ds instanceof MultipartDataSource) {
    // ask super to do this for us.
    setMultipartDataSource((MultipartDataSource)ds);
    return;
}

// 'ds' was not a MultipartDataSource, we have
// to parse this ourself.
parsed = false;
this.ds = ds;
    if (ct==null)
        contentType = new ContentType(ds.getContentType());
    else
        contentType = ct;
   */

}
 
Example #29
Source File: MimeUtility.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Decode the given input stream. The Input stream returned is
 * the decoded input stream. All the encodings defined in RFC 2045
 * are supported here. They include "base64", "quoted-printable",
 * "7bit", "8bit", and "binary". In addition, "uuencode" is also
 * supported.
 *
 * @param   is              input stream
 * @param   encoding        the encoding of the stream.
 * @return                  decoded input stream.
 */
public static InputStream decode(InputStream is, String encoding)
            throws MessagingException {
    if (encoding.equalsIgnoreCase("base64"))
        return new BASE64DecoderStream(is);
    else if (encoding.equalsIgnoreCase("quoted-printable"))
        return new QPDecoderStream(is);
    else if (encoding.equalsIgnoreCase("uuencode") ||
             encoding.equalsIgnoreCase("x-uuencode") ||
             encoding.equalsIgnoreCase("x-uue"))
        return new UUDecoderStream(is);
    else if (encoding.equalsIgnoreCase("binary") ||
             encoding.equalsIgnoreCase("7bit") ||
             encoding.equalsIgnoreCase("8bit"))
        return is;
    else
        throw new MessagingException("Unknown encoding: " + encoding);
}
 
Example #30
Source File: MimeBodyPart.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Set the filename associated with this body part, if possible. <p>
 *
 * Sets the "filename" parameter of the "Content-Disposition"
 * header field of this body part.
 *
 * @exception       IllegalStateException if this body part is
 *                  obtained from a READ_ONLY folder.
 */
public void setFileName(String filename) throws MessagingException {
    // Set the Content-Disposition "filename" parameter
    String s = getHeader("Content-Disposition", null);
    ContentDisposition cd =
        new ContentDisposition(s == null ? ATTACHMENT : s);
    cd.setParameter("filename", filename);
    setHeader("Content-Disposition", cd.toString());

    /* Also attempt to set the Content-Type "name" parameter,
     * to satisfy ancient MUAs.
     * XXX: This is not RFC compliant, and hence should really
     * be conditional based on some property. Fix this once we
     * figure out how to get at Properties from here !
     */
    s = getHeader("Content-Type", null);
    if (s != null) {
        try {
        ContentType cType = new ContentType(s);
        cType.setParameter("name", filename);
        setHeader("Content-Type", cType.toString());
        } catch (ParseException pex) { }    // ignore it
    }
}