Package javax.mail.internet

Examples of javax.mail.internet.MimePart


   */
  public static List<MimePart> attachmentsFromPart( Part part ) throws MessagingException, IOException {

    List<MimePart> attachmentParts = new ArrayList<MimePart>();
    if ( part instanceof MimePart ) {
      MimePart mimePart = (MimePart) part;

      if ( part.isMimeType( "multipart/*" ) ) {
        Multipart mp = (Multipart) mimePart.getContent();
        for (int i = 0; i < mp.getCount(); i++) {
          MimeBodyPart bodyPart = (MimeBodyPart) mp.getBodyPart( i );
          if ( Part.ATTACHMENT.equals( bodyPart.getDisposition() )
              || Part.INLINE.equals( bodyPart.getDisposition() ) ) {
            attachmentParts.add( bodyPart );
View Full Code Here


   * HTML mail, using default content type ("text/plain") else
   * @throws MessagingException in case of errors
   */
  public void setText(String text, boolean html) throws MessagingException {
    Assert.notNull(text, "Text must not be null");
    MimePart partToUse;
    if (isMultipart()) {
      partToUse = getMainPart();
    }
    else {
      partToUse = this.mimeMessage;
View Full Code Here

        if ( isThumbnail ) {
          List<MimePart> attachmentList = MessageUtils.attachmentsFromPart( msg );
          int index = Integer.valueOf( attachmentIndex );

          MimePart retrievePart = attachmentList.get( index );

          ContentType contentType = new ContentType( retrievePart.getContentType() );
          response.setContentType( contentType.getBaseType() );

          BufferedInputStream bufInputStream = new BufferedInputStream( retrievePart.getInputStream() );
          OutputStream outputStream = response.getOutputStream();

          writeScaledImage( bufInputStream, outputStream );

          bufInputStream.close();
View Full Code Here

        Message msg = mailbox.getCurrentFolder().getMessageById( Long.parseLong( messageId ) );

        List<MimePart> attachmentList = MessageUtils.attachmentsFromPart( msg );
        int index = Integer.valueOf( attachmentIndex );

        MimePart retrievePart = attachmentList.get( index );

        ContentType contentType = new ContentType( retrievePart.getContentType() );

        String fileName = retrievePart.getFileName();
        if ( StringUtils.isEmpty( fileName ) ) {
          fileName = context
              .getMessage( "message.unknown.attachment", null, SessionManager.get().getLocale() );
        }
        StringBuffer contentDisposition = new StringBuffer();
        if ( !view ) {
          contentDisposition.append( "attachment; filename=\"" );
          contentDisposition.append( fileName ).append( "\"" );
        }

        response.setHeader( "cache-control", "no-store" );
        response.setHeader( "pragma", "no-cache" );
        response.setIntHeader( "max-age", 0 );
        response.setIntHeader( "expires", 0 );

        if ( !StringUtils.isEmpty( contentDisposition.toString() ) ) {
          response.setHeader( "Content-disposition", contentDisposition.toString() );
        }
        response.setContentType( contentType.getBaseType() );
        // response.setContentLength(
        // MessageUtils.calculateSizeFromPart( retrievePart ) );

        BufferedInputStream bufInputStream = new BufferedInputStream( retrievePart.getInputStream() );
        OutputStream outputStream = response.getOutputStream();

        byte[] inBuf = new byte[1024];
        int len = 0;
        int total = 0;
View Full Code Here

   */
  public static List<MimePart> attachmentsFromPart( Part part ) throws MessagingException, IOException {

    List<MimePart> attachmentParts = new ArrayList<MimePart>();
    if ( part instanceof MimePart ) {
      MimePart mimePart = (MimePart) part;

      if ( part.isMimeType( "multipart/*" ) ) {
        Multipart mp = (Multipart) mimePart.getContent();
        for (int i = 0; i < mp.getCount(); i++) {
          MimeBodyPart bodyPart = (MimeBodyPart) mp.getBodyPart( i );
          if ( Part.ATTACHMENT.equals( bodyPart.getDisposition() )
              || Part.INLINE.equals( bodyPart.getDisposition() ) ) {
            attachmentParts.add( bodyPart );
View Full Code Here

     * @throws IOException
     */
    private BodyPart handleMultiPart(Multipart body) throws IOException, MessagingException {
        BodyPart bodyPart = null;
        for (int i = 0; i < body.getCount(); i++) {
            MimePart entity = (MimePart) body.getBodyPart(i);

            if (bodyPart == null) {
                bodyPart = handlePart(entity);
            } else {
                BodyPart attachment = handlePart(entity);
                bodyPart.addPart(new AttachmentPart(attachment.getContent(), parseContentType(attachment.getContentType()), entity.getFileName()));
            }
        }

        return bodyPart;
    }
View Full Code Here

         */
        if (part.getContent() instanceof String && (part.isMimeType("text/plain"))) {
            characters((String) part.getContent());
        } else if (part.isMimeType("multipart/alternative")) {
            MimeMultipart mp = (MimeMultipart) part.getContent();
            MimePart bestPart = null;
            int ctMax = 0;
            for (int i = 0; i < mp.getCount(); i++) {
                MimePart p = (MimePart) mp.getBodyPart(i);
                int ctPrefN = alternativeMailCtPref.preference(p);
                if (ctPrefN > ctMax) {
                    ctMax = ctPrefN;
                    bestPart = p;
                }
View Full Code Here

        {
            contentBytes = (byte[])content;
        }
        else if (content instanceof MimePart)
        {
            MimePart part = (MimePart)content;
            ByteArrayOutputStream out;
           
            if (part.getSize() > 0)
            {
                out = new ByteArrayOutputStream(part.getSize());
            }
            else
            {
                out = new ByteArrayOutputStream();
            }
           
            part.writeTo(out);
            contentBytes = out.toByteArray();
        }
        else
        {
            String type = "<null>";
View Full Code Here

         */
        if (part.getContent() instanceof String && (part.isMimeType("text/plain"))) {
            characters((String) part.getContent());
        } else if (part.isMimeType("multipart/alternative")) {
            MimeMultipart mp = (MimeMultipart) part.getContent();
            MimePart bestPart = null;
            int ctMax = 0;
            for (int i = 0; i < mp.getCount(); i++) {
                MimePart p = (MimePart) mp.getBodyPart(i);
                int ctPrefN = alternativeMailCtPref.preference(p);
                if (ctPrefN > ctMax) {
                    ctMax = ctPrefN;
                    bestPart = p;
                }
View Full Code Here

        if (subject != null) {
          message.setSubject(subject);
        }

        //
        MimePart bodyPart;
        if (attachments != null && attachments.length > 0) {
          Multipart multipart = new MimeMultipart();
          bodyPart = new MimeBodyPart();
          bodyPart.setContent(body, type);
          for (DataSource attachment : attachments) {
            MimeBodyPart attachmentPart = new MimeBodyPart();
            attachmentPart.setDataHandler(new DataHandler(attachment));
            attachmentPart.setFileName(attachment.getName());
            multipart.addBodyPart(attachmentPart);
          }
          message.setContent(multipart);
        } else {
          bodyPart = message;
        }

        //
        if (type != null) {
          bodyPart.setContent(body, type);
        } else {
          bodyPart.setText(body.toString());
        }

        //
        try {
          Transport.send(message);
View Full Code Here

TOP

Related Classes of javax.mail.internet.MimePart

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.