@Test void initShouldSetRemoveParameterWhenEqualsMatched() throws MessagingException { StripAttachment mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() .mailetName("Test") .setProperty("remove", "matched") .setProperty("pattern", ".*\\.tmp") .build(); mailet.init(mci); assertThat(mailet.removeAttachments).isEqualTo(StripAttachment.REMOVE_MATCHED); }
@Override public void init() throws MailetException { regExPattern = regExFromParameter(PATTERN_PARAMETER_NAME); notRegExPattern = regExFromParameter(NOTPATTERN_PARAMETER_NAME); mimeType = getInitParameter(MIMETYPE_PARAMETER_NAME); if (regExPattern == null && notRegExPattern == null && Strings.isNullOrEmpty(mimeType)) { throw new MailetException("At least one of '" + PATTERN_PARAMETER_NAME + "', '" + NOTPATTERN_PARAMETER_NAME + "' or '" + MIMETYPE_PARAMETER_NAME + "' parameter should be provided."); } directoryName = getInitParameter(DIRECTORY_PARAMETER_NAME); attributeName = getInitParameterAsOptional(ATTRIBUTE_PARAMETER_NAME).map(AttributeName::of); removeAttachments = getInitParameter(REMOVE_ATTACHMENT_PARAMETER_NAME, REMOVE_NONE).toLowerCase(Locale.US); if (!removeAttachments.equals(REMOVE_MATCHED) && !removeAttachments.equals(REMOVE_ALL) && !removeAttachments.equals(REMOVE_NONE)) { throw new MailetException(String.format("Unknown remove parameter value '%s' waiting for '%s', '%s' or '%s'.", removeAttachments, REMOVE_MATCHED, REMOVE_ALL, REMOVE_NONE)); } if (directoryName != null) { createDirectory(); } decodeFilename = getBooleanParameter(getInitParameter(DECODE_FILENAME_PARAMETER_NAME), DECODE_FILENAME_DEFAULT_VALUE); String replaceFilenamePattern = getInitParameter(REPLACE_FILENAME_PATTERN_PARAMETER_NAME); if (replaceFilenamePattern != null) { filenameReplacingPatterns = new PatternExtractor().getPatternsFromString(replaceFilenamePattern); } else { filenameReplacingPatterns = ImmutableList.of(); } logConfiguration(); }
StripAttachment extends GenericMailet { @Override public void init() throws MailetException { regExPattern = regExFromParameter(PATTERN_PARAMETER_NAME); notRegExPattern = regExFromParameter(NOTPATTERN_PARAMETER_NAME); mimeType = getInitParameter(MIMETYPE_PARAMETER_NAME); if (regExPattern == null && notRegExPattern == null && Strings.isNullOrEmpty(mimeType)) { throw new MailetException("At least one of '" + PATTERN_PARAMETER_NAME + "', '" + NOTPATTERN_PARAMETER_NAME + "' or '" + MIMETYPE_PARAMETER_NAME + "' parameter should be provided."); } directoryName = getInitParameter(DIRECTORY_PARAMETER_NAME); attributeName = getInitParameterAsOptional(ATTRIBUTE_PARAMETER_NAME).map(AttributeName::of); removeAttachments = getInitParameter(REMOVE_ATTACHMENT_PARAMETER_NAME, REMOVE_NONE).toLowerCase(Locale.US); if (!removeAttachments.equals(REMOVE_MATCHED) && !removeAttachments.equals(REMOVE_ALL) && !removeAttachments.equals(REMOVE_NONE)) { throw new MailetException(String.format("Unknown remove parameter value '%s' waiting for '%s', '%s' or '%s'.", removeAttachments, REMOVE_MATCHED, REMOVE_ALL, REMOVE_NONE)); } if (directoryName != null) { createDirectory(); } decodeFilename = getBooleanParameter(getInitParameter(DECODE_FILENAME_PARAMETER_NAME), DECODE_FILENAME_DEFAULT_VALUE); String replaceFilenamePattern = getInitParameter(REPLACE_FILENAME_PATTERN_PARAMETER_NAME); if (replaceFilenamePattern != null) { filenameReplacingPatterns = new PatternExtractor().getPatternsFromString(replaceFilenamePattern); } else { filenameReplacingPatterns = ImmutableList.of(); } logConfiguration(); } }
StripAttachment extends GenericMailet { @Override public void init() throws MailetException { regExPattern = regExFromParameter(PATTERN_PARAMETER_NAME); notRegExPattern = regExFromParameter(NOTPATTERN_PARAMETER_NAME); mimeType = getInitParameter(MIMETYPE_PARAMETER_NAME); if (regExPattern == null && notRegExPattern == null && Strings.isNullOrEmpty(mimeType)) { throw new MailetException("At least one of '" + PATTERN_PARAMETER_NAME + "', '" + NOTPATTERN_PARAMETER_NAME + "' or '" + MIMETYPE_PARAMETER_NAME + "' parameter should be provided."); } directoryName = getInitParameter(DIRECTORY_PARAMETER_NAME); attributeName = getInitParameterAsOptional(ATTRIBUTE_PARAMETER_NAME).map(AttributeName::of); removeAttachments = getInitParameter(REMOVE_ATTACHMENT_PARAMETER_NAME, REMOVE_NONE).toLowerCase(Locale.US); if (!removeAttachments.equals(REMOVE_MATCHED) && !removeAttachments.equals(REMOVE_ALL) && !removeAttachments.equals(REMOVE_NONE)) { throw new MailetException(String.format("Unknown remove parameter value '%s' waiting for '%s', '%s' or '%s'.", removeAttachments, REMOVE_MATCHED, REMOVE_ALL, REMOVE_NONE)); } if (directoryName != null) { createDirectory(); } decodeFilename = getBooleanParameter(getInitParameter(DECODE_FILENAME_PARAMETER_NAME), DECODE_FILENAME_DEFAULT_VALUE); String replaceFilenamePattern = getInitParameter(REPLACE_FILENAME_PATTERN_PARAMETER_NAME); if (replaceFilenamePattern != null) { filenameReplacingPatterns = new PatternExtractor().getPatternsFromString(replaceFilenamePattern); } else { filenameReplacingPatterns = ImmutableList.of(); } logConfiguration(); }  }
StripAttachment extends GenericMailet { @Override public void init() throws MailetException { regExPattern = regExFromParameter(PATTERN_PARAMETER_NAME); notRegExPattern = regExFromParameter(NOTPATTERN_PARAMETER_NAME); mimeType = getInitParameter(MIMETYPE_PARAMETER_NAME); if (regExPattern == null && notRegExPattern == null && Strings.isNullOrEmpty(mimeType)) { throw new MailetException("At least one of '" + PATTERN_PARAMETER_NAME + "', '" + NOTPATTERN_PARAMETER_NAME + "' or '" + MIMETYPE_PARAMETER_NAME + "' parameter should be provided."); } directoryName = getInitParameter(DIRECTORY_PARAMETER_NAME); attributeName = getInitParameterAsOptional(ATTRIBUTE_PARAMETER_NAME).map(AttributeName::of); removeAttachments = getInitParameter(REMOVE_ATTACHMENT_PARAMETER_NAME, REMOVE_NONE).toLowerCase(Locale.US); if (!removeAttachments.equals(REMOVE_MATCHED) && !removeAttachments.equals(REMOVE_ALL) && !removeAttachments.equals(REMOVE_NONE)) { throw new MailetException(String.format("Unknown remove parameter value '%s' waiting for '%s', '%s' or '%s'.", removeAttachments, REMOVE_MATCHED, REMOVE_ALL, REMOVE_NONE)); } if (directoryName != null) { createDirectory(); } decodeFilename = getBooleanParameter(getInitParameter(DECODE_FILENAME_PARAMETER_NAME), DECODE_FILENAME_DEFAULT_VALUE); String replaceFilenamePattern = getInitParameter(REPLACE_FILENAME_PATTERN_PARAMETER_NAME); if (replaceFilenamePattern != null) { filenameReplacingPatterns = new PatternExtractor().getPatternsFromString(replaceFilenamePattern); } else { filenameReplacingPatterns = ImmutableList.of(); } logConfiguration(); }  @Override void init(); @Override void service(Mail mail); @Override String getMailetInfo(); }
StripAttachment extends GenericMailet { @Override public void init() throws MailetException { regExPattern = regExFromParameter(PATTERN_PARAMETER_NAME); notRegExPattern = regExFromParameter(NOTPATTERN_PARAMETER_NAME); mimeType = getInitParameter(MIMETYPE_PARAMETER_NAME); if (regExPattern == null && notRegExPattern == null && Strings.isNullOrEmpty(mimeType)) { throw new MailetException("At least one of '" + PATTERN_PARAMETER_NAME + "', '" + NOTPATTERN_PARAMETER_NAME + "' or '" + MIMETYPE_PARAMETER_NAME + "' parameter should be provided."); } directoryName = getInitParameter(DIRECTORY_PARAMETER_NAME); attributeName = getInitParameterAsOptional(ATTRIBUTE_PARAMETER_NAME).map(AttributeName::of); removeAttachments = getInitParameter(REMOVE_ATTACHMENT_PARAMETER_NAME, REMOVE_NONE).toLowerCase(Locale.US); if (!removeAttachments.equals(REMOVE_MATCHED) && !removeAttachments.equals(REMOVE_ALL) && !removeAttachments.equals(REMOVE_NONE)) { throw new MailetException(String.format("Unknown remove parameter value '%s' waiting for '%s', '%s' or '%s'.", removeAttachments, REMOVE_MATCHED, REMOVE_ALL, REMOVE_NONE)); } if (directoryName != null) { createDirectory(); } decodeFilename = getBooleanParameter(getInitParameter(DECODE_FILENAME_PARAMETER_NAME), DECODE_FILENAME_DEFAULT_VALUE); String replaceFilenamePattern = getInitParameter(REPLACE_FILENAME_PATTERN_PARAMETER_NAME); if (replaceFilenamePattern != null) { filenameReplacingPatterns = new PatternExtractor().getPatternsFromString(replaceFilenamePattern); } else { filenameReplacingPatterns = ImmutableList.of(); } logConfiguration(); }  @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; }