vttranlina commented on a change in pull request #880: URL: https://github.com/apache/james-project/pull/880#discussion_r801219917
########## File path: server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RequeueMailet.java ########## @@ -0,0 +1,80 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.transport.mailets; + +import java.time.Duration; +import java.time.temporal.ChronoUnit; +import java.util.Optional; + +import javax.inject.Inject; +import javax.mail.MessagingException; + +import org.apache.james.lifecycle.api.LifecycleUtil; +import org.apache.james.queue.api.MailQueue; +import org.apache.james.queue.api.MailQueueFactory; +import org.apache.james.queue.api.MailQueueName; +import org.apache.james.util.DurationParser; +import org.apache.mailet.Mail; +import org.apache.mailet.base.GenericMailet; + +public class RequeueMailet extends GenericMailet { + private static final MailQueueName DEFAULT_MAIL_QUEUE_NAME = MailQueueFactory.SPOOL; + private static final String DEFAULT_PROCESSOR = Mail.TRANSPORT; + private static final Duration DEFAULT_DELAY_DURATION = Duration.ofHours(2); + + private final MailQueueFactory<?> mailQueueFactory; + + private MailQueue mailQueue; + private Duration delayDuration; + private String processor; + + @Inject + public RequeueMailet(MailQueueFactory<?> mailQueueFactory) { + this.mailQueueFactory = mailQueueFactory; + } + + @Override + public void init() throws MessagingException { + MailQueueName mailQueueName = Optional.ofNullable(getInitParameter("queue")) + .map(MailQueueName::of).orElse(DEFAULT_MAIL_QUEUE_NAME); + + mailQueue = mailQueueFactory.getQueue(mailQueueName) + .orElseThrow(() -> new RuntimeException("Can not find queue " + mailQueueName.asString())); + + delayDuration = Optional.ofNullable(getInitParameter("delay")) + .map(delayValue -> DurationParser.parse(delayValue, ChronoUnit.SECONDS)) + .orElse(DEFAULT_DELAY_DURATION); Review comment: "No delay", IMO, it doesn't make sense. (at least in rate-limiting case) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
