This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git


The following commit(s) were added to refs/heads/master by this push:
     new 3388bfce19 JAMES-3898 VacationMailet should Q-Encode special 
characters (#1508)
3388bfce19 is described below

commit 3388bfce19bac94ae2fe29f281af4ef863313310
Author: Benoit TELLIER <[email protected]>
AuthorDate: Fri Mar 31 23:01:20 2023 +0700

    JAMES-3898 VacationMailet should Q-Encode special characters (#1508)
---
 .../james/transport/mailets/VacationReply.java     |  2 +-
 .../transport/util/MimeMessageBodyGenerator.java   |  2 +-
 .../james/transport/mailets/VacationReplyTest.java | 27 +++++++++++++++++-----
 3 files changed, 23 insertions(+), 8 deletions(-)

diff --git 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/VacationReply.java
 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/VacationReply.java
index 999ec9bcf6..36815a1c42 100644
--- 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/VacationReply.java
+++ 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/VacationReply.java
@@ -74,7 +74,7 @@ public class VacationReply {
 
         private MimeMessage generateMimeMessage(MimeMessageBodyGenerator 
mimeMessageBodyGenerator) throws MessagingException {
             MimeMessage reply = (MimeMessage) 
originalMail.getMessage().reply(NOT_REPLY_TO_ALL);
-            vacation.getSubject().ifPresent(Throwing.consumer(subjectString -> 
reply.setHeader("subject", subjectString)));
+            vacation.getSubject().ifPresent(Throwing.consumer(subjectString -> 
reply.setSubject(subjectString)));
             reply.setHeader(FROM_HEADER, mailRecipient.toString());
             reply.setHeader(TO_HEADER, 
originalMail.getMaybeSender().get().asString());
             
reply.setHeader(AutomaticallySentMailDetector.AUTO_SUBMITTED_HEADER, 
AutomaticallySentMailDetector.AUTO_REPLIED_VALUE);
diff --git 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/util/MimeMessageBodyGenerator.java
 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/util/MimeMessageBodyGenerator.java
index 5673b4aa9b..e54ba6f82b 100644
--- 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/util/MimeMessageBodyGenerator.java
+++ 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/util/MimeMessageBodyGenerator.java
@@ -45,7 +45,7 @@ public class MimeMessageBodyGenerator {
 
     @Inject
     @VisibleForTesting
-    MimeMessageBodyGenerator(HtmlTextExtractor htmlTextExtractor) {
+    public MimeMessageBodyGenerator(HtmlTextExtractor htmlTextExtractor) {
         this.htmlTextExtractor = htmlTextExtractor;
     }
 
diff --git 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/VacationReplyTest.java
 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/VacationReplyTest.java
index c1703c814a..85b89e0aeb 100644
--- 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/VacationReplyTest.java
+++ 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/VacationReplyTest.java
@@ -22,6 +22,7 @@ package org.apache.james.transport.mailets;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 import static org.mockito.hamcrest.MockitoHamcrest.argThat;
@@ -33,8 +34,9 @@ import javax.mail.internet.MimeMessage;
 
 import org.apache.james.core.MailAddress;
 import org.apache.james.transport.util.MimeMessageBodyGenerator;
-import org.apache.james.vacation.api.Vacation;
 import org.apache.james.util.MimeMessageUtil;
+import org.apache.james.util.html.HtmlTextExtractor;
+import org.apache.james.vacation.api.Vacation;
 import org.apache.mailet.base.test.FakeMail;
 import org.hamcrest.BaseMatcher;
 import org.hamcrest.Description;
@@ -65,9 +67,11 @@ public class VacationReplyTest {
                 .sender(originalSender)
                 .build();
 
-        mimeMessageBodyGenerator = mock(MimeMessageBodyGenerator.class);
+        HtmlTextExtractor htmlTextExtractor = mock(HtmlTextExtractor.class);
+        when(htmlTextExtractor.toPlainText(any())).thenReturn("HTML");
+
+        mimeMessageBodyGenerator = spy(new 
MimeMessageBodyGenerator(htmlTextExtractor));
         generatedBody = MimeMessageUtil.defaultMimeMessage();
-        when(mimeMessageBodyGenerator.from(any(MimeMessage.class), any(), 
any())).thenReturn(generatedBody);
     }
 
     @Test
@@ -84,7 +88,6 @@ public class VacationReplyTest {
 
         
assertThat(vacationReply.getRecipients()).containsExactly(originalSender);
         assertThat(vacationReply.getSender()).isEqualTo(originalRecipient);
-        assertThat(vacationReply.getMimeMessage()).isEqualTo(generatedBody);
     }
 
     @Test
@@ -100,7 +103,20 @@ public class VacationReplyTest {
         
verify(mimeMessageBodyGenerator).from(argThat(createSubjectMatcher("Re: 
Original subject")), any(), any());
         
assertThat(vacationReply.getRecipients()).containsExactly(originalSender);
         assertThat(vacationReply.getSender()).isEqualTo(originalRecipient);
-        assertThat(vacationReply.getMimeMessage()).isEqualTo(generatedBody);
+    }
+
+    @Test
+    public void subjectShouldBeQEncodedWhenSpecialCharacters() throws 
Exception {
+        VacationReply vacationReply = VacationReply.builder(mail)
+            .vacation(Vacation.builder()
+                .enabled(true)
+                .subject(Optional.of("Nghiêm Thị Tuyết Nhung"))
+                .textBody(REASON)
+                .build())
+            .receivedMailRecipient(originalRecipient)
+            .build(mimeMessageBodyGenerator);
+
+        
assertThat(vacationReply.getMimeMessage().getHeader("subject")).containsOnly("=?UTF-8?Q?Nghi=C3=AAm_Th=E1=BB=8B_Tuy=E1=BA=BFt_Nhung?=");
     }
 
     @Test
@@ -117,7 +133,6 @@ public class VacationReplyTest {
         
verify(mimeMessageBodyGenerator).from(argThat(createSubjectMatcher(SUBJECT)), 
any(), any());
         
assertThat(vacationReply.getRecipients()).containsExactly(originalSender);
         assertThat(vacationReply.getSender()).isEqualTo(originalRecipient);
-        assertThat(vacationReply.getMimeMessage()).isEqualTo(generatedBody);
     }
 
     @Test(expected = NullPointerException.class)


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to