quantranhong1999 commented on code in PR #2490: URL: https://github.com/apache/james-project/pull/2490#discussion_r1830500881
########## docs/modules/servers/partials/FoldLongLines.adoc: ########## @@ -0,0 +1,7 @@ +=== FoldLongLines + +This mailet fold (wrap) any header lines of the mail that exceed the maximum number of characters. + +It takes only one parameter: + +* maxCharacters: maximum number of characters. Default to 998. Review Comment: `maximum number of characters per line`? Can we note why it is 998 BTW?) ########## mailet/standard/src/main/java/org/apache/james/transport/mailets/MimeUtil.java: ########## @@ -0,0 +1,79 @@ +/**************************************************************** + * 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; + +public class MimeUtil { + /** + * Splits the specified string into a multiple-line representation with + * lines no longer than the maximum number of characters (because the line might contain + * encoded words; see <a href='http://www.faqs.org/rfcs/rfc2047.html'>RFC + * 2047</a> section 2). If the string contains non-whitespace sequences + * longer than the maximum number of characters a line break is inserted at the whitespace + * character following the sequence resulting in a line longer than 76 + * characters. Review Comment: not 76 chars anymore? ########## mailet/standard/src/main/java/org/apache/james/transport/mailets/FoldLongLines.java: ########## @@ -0,0 +1,56 @@ +/**************************************************************** + * 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.util.List; + +import jakarta.mail.Header; +import jakarta.mail.MessagingException; + +import org.apache.commons.lang3.stream.Streams; +import org.apache.mailet.Mail; +import org.apache.mailet.base.GenericMailet; + +import com.github.fge.lambdas.Throwing; + +public class FoldLongLines extends GenericMailet { Review Comment: Can we have a little JavaDoc too? ########## mailet/standard/src/test/java/org/apache/james/transport/mailets/FoldLongLinesTest.java: ########## @@ -0,0 +1,98 @@ +/**************************************************************** + * 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 static org.apache.james.transport.mailets.FoldLongLines.MAX_CHARACTERS_PARAMETER_NAME; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; + +import jakarta.mail.MessagingException; + +import org.apache.commons.lang3.stream.Streams; +import org.apache.james.core.builder.MimeMessageBuilder; +import org.apache.mailet.Mail; +import org.apache.mailet.Mailet; +import org.apache.mailet.MailetContext; +import org.apache.mailet.base.test.FakeMail; +import org.apache.mailet.base.test.FakeMailContext; +import org.apache.mailet.base.test.FakeMailetConfig; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; + +public class FoldLongLinesTest { + static final String HEADER_NAME = "References"; + static final String HEADER_VALUE = "<a1@gmailcom> <a2@gmailcom> <a3@gmailcom>"; + static final String FOLDED_LINE = "<a1@gmailcom>\r\n" + + " <a2@gmailcom> <a3@gmailcom>"; + + private Mailet foldMailet; + private MailetContext mailetContext; + + @BeforeEach + void beforeEach() throws MessagingException { + foldMailet = new FoldLongLines(); + mailetContext = FakeMailContext.builder() + .logger(mock(Logger.class)) + .build(); + FakeMailetConfig mailetConfig = FakeMailetConfig.builder() + .mailetName("Test") + .mailetContext(mailetContext) + .setProperty(MAX_CHARACTERS_PARAMETER_NAME, "30") + .build(); + foldMailet.init(mailetConfig); + } + + @Test + void serviceShouldFoldLinesWhenTheyExceedMaxCharacters() throws MessagingException { + FakeMailetConfig mailetConfig = FakeMailetConfig.builder() + .mailetName("Test") + .mailetContext(mailetContext) + .setProperty(MAX_CHARACTERS_PARAMETER_NAME, "30") + .build(); + foldMailet.init(mailetConfig); + + Mail mail = FakeMail.builder() + .name("mail").mimeMessage(MimeMessageBuilder.mimeMessageBuilder().addHeader(HEADER_NAME, HEADER_VALUE).build()) + .build(); + foldMailet.service(mail); + + String actual = Streams.of(mail.getMessage().getAllHeaders()).filter(header -> header.getName().equals(HEADER_NAME)).findFirst().get().getValue(); + assertThat(actual).isEqualTo(FOLDED_LINE); + } + + @Test + void serviceShouldNotFoldLinesWhenTheyExceedMaxCharacters() throws MessagingException { Review Comment: ```suggestion void serviceShouldNotFoldLinesWhenTheyNotExceedMaxCharacters() throws MessagingException { ``` -- 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: notifications-unsubscr...@james.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org For additional commands, e-mail: notifications-h...@james.apache.org