StripAttachment extends GenericMailet { @VisibleForTesting boolean processMultipartPartMessage(Part part, Mail mail) throws MailetException { if (!isMultipart(part)) { return false; } try { Multipart multipart = (Multipart) part.getContent(); boolean atLeastOneRemoved = false; boolean subpartHasBeenChanged = false; List<BodyPart> bodyParts = MultipartUtil.retrieveBodyParts(multipart); for (BodyPart bodyPart: bodyParts) { if (isMultipart(bodyPart)) { if (processMultipartPartMessage(bodyPart, mail)) { subpartHasBeenChanged = true; } } else { if (shouldBeRemoved(bodyPart, mail)) { multipart.removeBodyPart(bodyPart); atLeastOneRemoved = true; } } } if (atLeastOneRemoved || subpartHasBeenChanged) { updateBodyPart(part, multipart); } return atLeastOneRemoved || subpartHasBeenChanged; } catch (Exception e) { LOGGER.error("Failing while analysing part for attachments (StripAttachment mailet).", e); return false; } }  @Override void init(); @Override void service(Mail mail); @Override String getMailetInfo(); static final String PATTERN_PARAMETER_NAME; static final String NOTPATTERN_PARAMETER_NAME; static final String MIMETYPE_PARAMETER_NAME; static final String ATTRIBUTE_PARAMETER_NAME; static final String DIRECTORY_PARAMETER_NAME; static final String REMOVE_ATTACHMENT_PARAMETER_NAME; static final String DECODE_FILENAME_PARAMETER_NAME; static final String REPLACE_FILENAME_PATTERN_PARAMETER_NAME; static final String REMOVE_NONE; static final String REMOVE_ALL; static final String REMOVE_MATCHED; static final AttributeName REMOVED_ATTACHMENTS; static final AttributeName SAVED_ATTACHMENTS; static final boolean DECODE_FILENAME_DEFAULT_VALUE; }
@Test void processMultipartPartMessageShouldReturnFalseWhenPartIsNotMultipart() throws Exception { StripAttachment mailet = new StripAttachment(); Part part = new MimeBodyPart(new ByteArrayInputStream(new byte[0])); Mail mail = mock(Mail.class); boolean actual = mailet.processMultipartPartMessage(part, mail); assertThat(actual).isFalse(); }