Package javax.mail

Examples of javax.mail.Part


   * (non-Javadoc)
   *
   * @see javax.mail.Part#getContent()
   */
  public Object getContent() throws IOException, MessagingException {
    Part part = getPartOnFile();
    return part.getContent();
  }
View Full Code Here


   *
   * @see javax.mail.Part#writeTo(java.io.OutputStream)
   */
  public void writeTo(OutputStream outStream) throws IOException,
  MessagingException {
    Part part = getPartOnFile();
    part.writeTo(outStream);
  }
View Full Code Here

   *             checking the parts HashMap. If it is not parsed yet then call
   *             the getNextPart() till we find the required part.
   */
  public DataHandler getDataHandler(String blobContentID) throws OMException {

    Part bodyPart;
    blobContentID = "<" + blobContentID + ">";
    boolean attachmentFound = false;

    //    // without the following part a Null Pointer Exception is thrown
    //   
    if (bodyPartsMap.containsKey(blobContentID)) {
      bodyPart = (Part) bodyPartsMap.get(blobContentID);
      attachmentFound = true;
      DataHandler dh;
      try {
        dh = bodyPart.getDataHandler();
      } catch (MessagingException e) {
        throw new OMException("Problem with Mime Body Part No "
            + partIndex + ".  " + e);
      }
      return dh;
    } else {
      try {
        while (true) {
          bodyPart = this.getNextPart();
          if (bodyPart == null) {
            return null;
          }
          if (bodyPartsMap.containsKey(blobContentID)) {
            bodyPart = (Part) bodyPartsMap.get(blobContentID);
            DataHandler dh = bodyPart.getDataHandler();
            return dh;
          }
        }
      } catch (MessagingException e) {
        throw new OMException("Invalid Mime Message " + e.toString());
View Full Code Here

    outFileStream.close();
  }
 
  private Part getPartOnFile() {
    FileInputStream inFileStream;
    Part part=null;
    try {
      inFileStream = new FileInputStream(fileName);
     
      part = new MimeBodyPart(inFileStream);
    } catch (FileNotFoundException e) {
View Full Code Here

   * (non-Javadoc)
   *
   * @see javax.mail.Part#getInputStream()
   */
  public InputStream getInputStream() throws IOException, MessagingException {
    Part part = getPartOnFile();
    return part.getInputStream();
  }
View Full Code Here

        Object content = message.getContent();
        if (content instanceof Multipart) {
            // mail with attachment
            Multipart mp = (Multipart)content;
            for (int i = 0; i < mp.getCount(); i++) {
                Part part = mp.getBodyPart(i);
                String disposition = part.getDisposition();
                if (disposition != null) {
                    if (disposition.equalsIgnoreCase(Part.ATTACHMENT) || disposition.equalsIgnoreCase(Part.INLINE)) {
                        // only add named attachments
                        if (part.getFileName() != null) {
                            // Parts marked with a disposition of Part.ATTACHMENT are clearly attachments
                            CollectionHelper.appendValue(map, part.getFileName(), part.getDataHandler());
                        }
                    }
                }
            }
        }
View Full Code Here

    mail.setSubject(message.getSubject());

    if (message instanceof MimeMessage) {
      MimeMessage mimeMessage = (MimeMessage) message;
      Object content = mimeMessage.getContent();
      Part part = message;

      if (content instanceof Multipart) {
        Multipart multipart = (Multipart) content;
        part = multipart.getBodyPart(0);

        if (multipart.getCount() > 1) {
          for (int i = 1; i < multipart.getCount(); i++) {
            Part subPart = multipart.getBodyPart(i);
            byte[] bytes = IOUtils.toByteArray(subPart.getInputStream());
            String name = subPart.getFileName();
            Attachment attachment = new ByteArrayAttachment(name, subPart.getContentType(), bytes);
            mail.getAttach().add(attachment);
          }
        }
      }
View Full Code Here

    mail.setSubject(message.getSubject());

    if (message instanceof MimeMessage) {
      MimeMessage mimeMessage = (MimeMessage) message;
      Object content = mimeMessage.getContent();
      Part part = message;

      if (content instanceof Multipart) {
        Multipart multipart = (Multipart) content;
        part = multipart.getBodyPart(0);

        if (multipart.getCount() > 1) {
          for (int i = 1; i < multipart.getCount(); i++) {
            Part subPart = multipart.getBodyPart(i);
            byte[] bytes = IO.toByteArray(subPart.getInputStream());
            String name = subPart.getFileName();
            Attachment attachment = new ByteArrayAttachment(name, subPart.getContentType(), bytes);
            mail.getAttach().add(attachment);
          }
        }
      }
View Full Code Here

                Object content = ((Part) msg).getContent();
                if (content instanceof Multipart) {
                    Multipart mp = (Multipart) content;
                    int attachmentCount = mp.getCount();
                    for (int a = 0; a < attachmentCount; a++) {
                        Part p = mp.getBodyPart(a);
                        String disposition = p.getDisposition();
                        if ((disposition != null) && (p.getFileName() != null)) {
                            String fileName = attachment_prefix + p.getFileName();
                            dumpAttachmentToDisk(p, baseDir, fileName);
                            ret.setProperty(FILE_PROPERTY_PREFIX + a, fileName);
                        }
                    }
                }
View Full Code Here

        if (p.isMimeType("multipart/alternative")) {
            // prefer html text over plain text
            Multipart mp = (Multipart)p.getContent();
            String text = null;
            for (int i = 0; i < mp.getCount(); i++) {
                Part bp = mp.getBodyPart(i);
                if (bp.isMimeType("text/plain")) {
                    if (text == null)
                        text = getText(bp);
                    continue;
                } else if (bp.isMimeType("text/html")) {
                    String s = getText(bp);
                    if (s != null)
                        return s;
                } else {
                    return getText(bp);
View Full Code Here

TOP

Related Classes of javax.mail.Part

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.