private void addBodyData ( final Email emailWithData , final MimeMessage msgToSet ) throws MessagingException { final List < EmailMessage > messages = emailWithData . messages ( ) ; final int totalMessages = messages . size ( ) ; // Need to use new list since filterEmbeddedAttachments(List) removes attachments from the source List final List < EmailAttachment < ? extends DataSource > > attachments = new ArrayList <> ( emailWithData . attachments ( ) ) ; if ( attachments . isEmpty ( ) && totalMessages == 1 ) { // special case: no attachments and just one content setContent ( messages . get ( 0 ) , msgToSet ) ; } else { final MimeMultipart multipart = new MimeMultipart ( ) ; final MimeMultipart msgMultipart = new MimeMultipart ( ALTERNATIVE ) ; multipart . addBodyPart ( getBaseBodyPart ( msgMultipart ) ) ; for ( final EmailMessage emailMessage : messages ) { msgMultipart . addBodyPart ( getBodyPart ( emailMessage , attachments ) ) ; } addAnyAttachments ( attachments , multipart ) ; msgToSet . setContent ( multipart ) ; } }
Adds message data and attachments .