private String computeGatewayUser(MailetConfig mailetConfig) { // backward compatibility with 2.3.x String user = mailetConfig.getInitParameter(GATEWAY_USERNAME); if (user == null) { return mailetConfig.getInitParameter(GATEWAY_USERNAME_COMPATIBILITY); } return user; }
@Override public String[] getMailetParameters() { List<String> parameterList = new ArrayList<>(); Iterator<String> iterator = config.getInitParameterNames(); while (iterator.hasNext()) { String name = iterator.next(); String value = config.getInitParameter(name); parameterList.add(name + "=" + value); } return parameterList.toArray(new String[parameterList.size()]); }
/** * Returns a String containing the value of the named initialization * parameter, or null if the parameter does not exist. * <p> * This method is supplied for convenience. It gets the value of the * named parameter from the mailet's MailetConfig object. * * @param name - a String specifying the name of the initialization parameter * @return a String containing the value of the initalization parameter */ @Override public String getInitParameter(String name) { return config.getInitParameter(name); }
private Properties computeJavaxProperties(MailetConfig mailetConfig) { Properties result = new Properties(); // deal with <mail.*> attributes, passing them to javamail result.putAll( ImmutableList.copyOf(mailetConfig.getInitParameterNames()) .stream() .filter(propertyName -> propertyName.startsWith(JAVAX_PREFIX)) .map(propertyName -> Pair.of(propertyName, mailetConfig.getInitParameter(propertyName))) .collect(Guavate.toImmutableMap(Pair::getKey, Pair::getValue))); return result; }
/** * Returns a String containing the value of the named initialization * parameter, or defValue if the parameter does not exist. * <p> * This method is supplied for convenience. It gets the value of the * named parameter from the mailet's MailetConfig object. * * @param name - a String specifying the name of the initialization parameter * @param defValue - a String specifying the default value when the parameter * is not present * @return a String containing the value of the initalization parameter */ public String getInitParameter(String name, String defValue) { String res = config.getInitParameter(name); if (res == null) { return defValue; } else { return res; } }
@SuppressWarnings("unchecked") public String[] getMailetParameters() { List<String> parameterList = new ArrayList<String>(); MailetConfig mailetConfig = getMailet().getMailetConfig(); Iterator<String> iterator = mailetConfig.getInitParameterNames(); while (iterator.hasNext()) { String name = (String) iterator.next(); String value = mailetConfig.getInitParameter(name); parameterList.add(name + "=" + value); } String[] result = (String[]) parameterList.toArray(new String[] {}); return result; }
private long computeSmtpTimeout(MailetConfig mailetConfig) { try { if (mailetConfig.getInitParameter(TIMEOUT) != null) { return Integer.valueOf(mailetConfig.getInitParameter(TIMEOUT)); } else { return DEFAULT_SMTP_TIMEOUT; } } catch (Exception e) { LOGGER.warn("Invalid timeout setting: {}", mailetConfig.getInitParameter(TIMEOUT)); return DEFAULT_SMTP_TIMEOUT; } }
private int computeDnsProblemRetry(MailetConfig mailetConfig) { String dnsRetry = mailetConfig.getInitParameter(MAX_DNS_PROBLEM_RETRIES); if (!Strings.isNullOrEmpty(dnsRetry)) { return Integer.valueOf(dnsRetry); } else { return DEFAULT_DNS_RETRY_PROBLEM; } }
private int computeConnectionTimeout(MailetConfig mailetConfig) { try { return Integer.valueOf( Optional.ofNullable(mailetConfig.getInitParameter(CONNECTIONTIMEOUT)) .orElse(String.valueOf(DEFAULT_CONNECTION_TIMEOUT))); } catch (Exception e) { LOGGER.warn("Invalid timeout setting: {}", mailetConfig.getInitParameter(TIMEOUT)); return DEFAULT_CONNECTION_TIMEOUT; } }
private DelaysAndMaxRetry computeDelaysAndMaxRetry(MailetConfig mailetConfig) { try { int intendedMaxRetries = Integer.valueOf( Optional.ofNullable(mailetConfig.getInitParameter(MAX_RETRIES)) .orElse(String.valueOf(DEFAULT_MAX_RETRY))); return DelaysAndMaxRetry.from(intendedMaxRetries, mailetConfig.getInitParameter(DELAY_TIME)); } catch (Exception e) { LOGGER.warn("Invalid maxRetries setting: {}", mailetConfig.getInitParameter(MAX_RETRIES)); return DelaysAndMaxRetry.defaults(); } }
/** * <p>Gets a boolean valued init parameter.</p> * @param config not null * @param name name of the init parameter to be queried * @return true when the init parameter is <code>true</code> (ignoring case); * false when the init parameter is <code>false</code> (ignoring case); * otherwise the default value */ public static Optional<Boolean> getInitParameter(MailetConfig config, String name) { String value = config.getInitParameter(name); if ("true".equalsIgnoreCase(value)) { return Optional.of(true); } if ("false".equalsIgnoreCase(value)) { return Optional.of(false); } return Optional.empty(); }
public String getOnMatchException() { return mailet.getMailetConfig() .getInitParameter("onMatchException"); }
MailetConfig config = getMailetConfig(); String stripSignatureConf = config.getInitParameter("strip"); if (stripSignatureConf != null) { stripSignature = Boolean.valueOf(stripSignatureConf); String onlyTrustedConf = config.getInitParameter("onlyTrusted"); if (onlyTrustedConf != null) { onlyTrusted = Boolean.valueOf(onlyTrustedConf); String mailAttributeConf = config.getInitParameter("mailAttribute"); if (mailAttributeConf != null) { mailAttribute = mailAttributeConf; String type = config.getInitParameter("keyStoreType"); String file = config.getInitParameter("keyStoreFileName"); String password = config.getInitParameter("keyStorePassword");
@Override public void init() throws MessagingException { super.init(); MailetConfig config = getMailetConfig(); String privateStoreType = config.getInitParameter("keyStoreType"); String privateStoreFile = config.getInitParameter("keyStoreFileName"); if (privateStoreFile == null) { throw new MessagingException("No keyStoreFileName specified"); } String privateStorePass = config.getInitParameter("keyStorePassword"); String keyAlias = config.getInitParameter("keyAlias"); String keyPass = config.getInitParameter("keyAliasPassword"); String mailAttributeConf = config.getInitParameter("mailAttribute"); if (mailAttributeConf != null) { mailAttribute = mailAttributeConf; } try { keyHolder = new SMIMEKeyHolder(privateStoreFile, privateStorePass, keyAlias, keyPass, privateStoreType); } catch (IOException | GeneralSecurityException e) { throw new MessagingException("Error loading keystore", e); } certificateHolder = from(keyHolder.getCertificate()); }
public RemoteDeliveryConfiguration(MailetConfig mailetConfig, DomainList domainList) { isDebug = MailetUtil.getInitParameter(mailetConfig, DEBUG).orElse(false); startTLS = MailetUtil.getInitParameter(mailetConfig, START_TLS).orElse(false); isSSLEnable = MailetUtil.getInitParameter(mailetConfig, SSL_ENABLE).orElse(false); usePriority = MailetUtil.getInitParameter(mailetConfig, USE_PRIORITY).orElse(false); sendPartial = MailetUtil.getInitParameter(mailetConfig, SENDPARTIAL).orElse(false); outGoingQueueName = Optional.ofNullable(mailetConfig.getInitParameter(OUTGOING)).orElse(DEFAULT_OUTGOING_QUEUE_NAME); bounceProcessor = mailetConfig.getInitParameter(BOUNCE_PROCESSOR); bindAddress = mailetConfig.getInitParameter(BIND); DelaysAndMaxRetry delaysAndMaxRetry = computeDelaysAndMaxRetry(mailetConfig); maxRetries = delaysAndMaxRetry.getMaxRetries(); delayTimes = delaysAndMaxRetry.getExpandedDelays(); smtpTimeout = computeSmtpTimeout(mailetConfig); connectionTimeout = computeConnectionTimeout(mailetConfig); dnsProblemRetry = computeDnsProblemRetry(mailetConfig); heloNameProvider = new HeloNameProvider(mailetConfig.getInitParameter(HELO_NAME), domainList); workersThreadCount = Integer.valueOf(mailetConfig.getInitParameter(DELIVERY_THREADS)); String gatewayPort = mailetConfig.getInitParameter(GATEWAY_PORT); String gateway = mailetConfig.getInitParameter(GATEWAY); gatewayServer = computeGatewayServers(gatewayPort, gateway); if (gateway != null) { authUser = computeGatewayUser(mailetConfig); authPass = mailetConfig.getInitParameter(GATEWAY_PASSWORD); } else { authUser = null; authPass = null; } isBindUsed = bindAddress != null; javaxAdditionalProperties = computeJavaxProperties(mailetConfig); }
@Override public void service(Mail mail) throws MessagingException { String state = config.getInitParameter("state"); mail.setState(state); } }
@Test public void initShouldNotThrowWhenInvalidPassThrough() throws Exception { MailetConfig mockedMailetConfig = mock(MailetConfig.class); when(mockedMailetConfig.getInitParameter("passThrough")).thenThrow(new RuntimeException()); when(mockedMailetConfig.getInitParameter("repositoryPath")).thenReturn(REPOSITORY_PATH); mailet.init(mockedMailetConfig); }
/** * Gets the configuration parameter requested. The mailet init parameters are checked first, then the OptionsManager. * @param param The parameter to get the value of. * @param mailet The mailet to search. May be null * @return If found, returns, the value of the configured value. Otherwise, the default value is returned */ public static final String getConfigurationParam(String param, Mailet mailet, String defaultValue) { // get from the mailet init parameter first String paramValue = (mailet == null) ? null : mailet.getMailetConfig().getInitParameter(param); if (paramValue == null || paramValue.isEmpty()) { // if not in the mailet config, then try the // Options manager OptionsParameter optionsParam = OptionsManager.getInstance().getParameter(param); if (optionsParam != null) paramValue = optionsParam.getParamValue(); } return (paramValue == null) ? defaultValue : paramValue; }
onMailetException = mailetConfig.getInitParameter("onMailetException");