title: Open in outllok using javamail api an attached email containing email as attachment
body: <p>I am able to open attached emails in outlook using javamail api.
  But I have a problem when this attached email contains also an eml as attachment.</p>
  
  <p>In outlook, as below in the pic, the main mail(mail1 left side) contains mail2 as attachment, when opening mail2, we have Re:completion as attachment(right side).
  <img src="https://i.stack.imgur.com/2oliG.png" alt="mail in outlook"></p>
  
  <p>In my application, i am displaying mail1 with its attachments in a specific template, when clicking on the attachment mail2, i am trying to open it with outlook using this code</p>
  
  <pre><code>try {
                  //in case mMail.getPart(iPart) is attachment
                  if (mMail.getPart(iPart).isMimeType("Message/*")) {
                      MimePart mimePart = mMail.getPart(iPart);
  
                      mMail = new Mail(); // class where we set the server and a new MimeMessage
                      mMail.setAllHeaders(mimePart); //we add all headers 
                      mMail.addAllBodyParts(mimePart);// check below
  
                      sCD = mimePart.getDisposition();
                      sCT = mimePart.getContentType();
                      if(sCD.startsWith(Part.ATTACHMENT)){
                          String filename = mimePart.getFileName();
                          filename = MimeUtility.decodeText(filename);
                          sCD = Part.ATTACHMENT + ";filename=" + filename;
                      }
  
                      iPart = -1;
                      bMsg = true;
                  }
  }
  catch (Exception e) {
    e.printStackTrace();
  } 
  </code></pre>
  
  <p>//here continue the code which open the mail</p>
  
  <pre><code>public void addAllBodyParts(Part part) throws Exception {
  
      Object content = part.getContent();
  
      if (content instanceof String) {
          mmMsg.setContent(content, part.getContentType());
  
      } else if (content instanceof Multipart) {
  
          Multipart innerMultiPart = (Multipart) content;
          int count = innerMultiPart.getCount();
  
          for (int i = 0; i &lt; count; i++) {
              BodyPart innerBodyPart = innerMultiPart.getBodyPart(i);
              String sCT = innerBodyPart.getContentType();
              if (sCT != null) {
                  String disposition = innerBodyPart.getDisposition();
                  if (disposition != null &amp;&amp; (disposition.equals(Part.ATTACHMENT))) {
                      Multipart multipart = new MimeMultipart();
                      //multipart.addBodyPart(innerBodyPart);
                      DataHandler handler = innerBodyPart.getDataHandler();
                      BodyPart messageBodyPart = new MimeBodyPart();
  
                      messageBodyPart.setDataHandler(handler);
                      messageBodyPart.setFileName(innerBodyPart.getFileName());
                      messageBodyPart.setContent(innerBodyPart.getContent(), innerBodyPart.getContentType());
                      multipart.addBodyPart(messageBodyPart);
                      //innerMultiPart.addBodyPart(innerBodyPart);
                      mmMsg.setContent(multipart);
  
                  }else{
                      if(content instanceof MimeBodyPart){
  
                          MimeBodyPart mbp = (MimeBodyPart)content;
                          if (mbp.isMimeType("text/plain")) {
                              mmMsg.setContent(mbp.getContent(), sCT);
                          } 
                      }else{
                          addAllBodyParts(innerBodyPart);
                      }
                  }
  
              }else{
                  addAllBodyParts(innerBodyPart);
              }
          }
      } else if (content instanceof MimeMessage){
  
          MimeMessage msg = (MimeMessage) content;
          addAllBodyParts(msg);
      }
  }
  </code></pre>
  
  <p>i got the following when mail2 is opened:(onthe left side, the body is empty, on right side, the header is empty and the text in the body is wrong)
  <img src="https://i.stack.imgur.com/sTKz4.png" alt="Attached mail"></p>
  
  <p>Can anyone help to find what is the error.
  Thank you</p>