james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject james-project git commit: JAMES-1717 Vacation should allow user to specify a subject
Date Mon, 23 May 2016 10:52:09 GMT
Repository: james-project
Updated Branches:
  refs/heads/master cc93b6d12 -> 1ed51b587


JAMES-1717 Vacation should allow user to specify a subject


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/1ed51b58
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/1ed51b58
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/1ed51b58

Branch: refs/heads/master
Commit: 1ed51b58720aebfe716ab2ae4da014f539eed4a1
Parents: cc93b6d
Author: Benoit Tellier <btellier@linagora.com>
Authored: Fri Apr 15 11:34:02 2016 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Mon May 23 17:51:40 2016 +0700

----------------------------------------------------------------------
 .../vacation/CassandraVacationDAO.java          |  7 +++-
 .../vacation/CassandraVacationModule.java       |  3 +-
 .../vacation/tables/CassandraVacationTable.java |  1 +
 .../james/jmap/api/vacation/Vacation.java       | 22 ++++++++--
 .../AbstractVacationRepositoryTest.java         | 11 ++++-
 .../integration/GetVacationResponseTest.java    |  8 +++-
 .../integration/SetVacationResponseTest.java    |  5 ++-
 .../apache/james/jmap/mailet/VacationReply.java | 10 +++++
 .../jmap/methods/SetVacationResponseMethod.java |  1 +
 .../james/jmap/model/VacationResponse.java      | 23 +++++++++--
 .../james/jmap/mailet/VacationReplyTest.java    | 43 +++++++++++++++++---
 .../methods/GetVacationResponseMethodTest.java  |  2 +
 .../methods/SetVacationResponseMethodTest.java  |  4 ++
 .../james/jmap/model/VacationResponseTest.java  |  3 ++
 14 files changed, 121 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/1ed51b58/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/vacation/CassandraVacationDAO.java
----------------------------------------------------------------------
diff --git a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/vacation/CassandraVacationDAO.java
b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/vacation/CassandraVacationDAO.java
index cc1c647..3bf5e18 100644
--- a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/vacation/CassandraVacationDAO.java
+++ b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/vacation/CassandraVacationDAO.java
@@ -61,7 +61,8 @@ public class CassandraVacationDAO {
             .value(CassandraVacationTable.IS_ENABLED, bindMarker(CassandraVacationTable.IS_ENABLED))
             .value(CassandraVacationTable.FROM_DATE, bindMarker(CassandraVacationTable.FROM_DATE))
             .value(CassandraVacationTable.TO_DATE, bindMarker(CassandraVacationTable.TO_DATE))
-            .value(CassandraVacationTable.TEXT, bindMarker(CassandraVacationTable.TEXT)));
+            .value(CassandraVacationTable.TEXT, bindMarker(CassandraVacationTable.TEXT))
+            .value(CassandraVacationTable.SUBJECT, bindMarker(CassandraVacationTable.SUBJECT)));
 
         this.readStatement = session.prepare(select()
             .from(CassandraVacationTable.TABLE_NAME)
@@ -76,7 +77,8 @@ public class CassandraVacationDAO {
                 .setBool(CassandraVacationTable.IS_ENABLED, vacation.isEnabled())
                 .setUDTValue(CassandraVacationTable.FROM_DATE, convertToUDTValue(vacation.getFromDate()))
                 .setUDTValue(CassandraVacationTable.TO_DATE, convertToUDTValue(vacation.getToDate()))
-                .setString(CassandraVacationTable.TEXT, vacation.getTextBody()));
+                .setString(CassandraVacationTable.TEXT, vacation.getTextBody())
+                .setString(CassandraVacationTable.SUBJECT, vacation.getSubject().orElse(null)));
     }
 
     public CompletableFuture<Optional<Vacation>> retrieveVacation(AccountId accountId)
{
@@ -87,6 +89,7 @@ public class CassandraVacationDAO {
                 .fromDate(retrieveDate(row, CassandraVacationTable.FROM_DATE))
                 .toDate(retrieveDate(row, CassandraVacationTable.TO_DATE))
                 .textBody(row.getString(CassandraVacationTable.TEXT))
+                .subject(Optional.ofNullable(row.getString(CassandraVacationTable.SUBJECT)))
                 .build()));
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ed51b58/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/vacation/CassandraVacationModule.java
----------------------------------------------------------------------
diff --git a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/vacation/CassandraVacationModule.java
b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/vacation/CassandraVacationModule.java
index dae2451..00233e0 100644
--- a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/vacation/CassandraVacationModule.java
+++ b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/vacation/CassandraVacationModule.java
@@ -49,7 +49,8 @@ public class CassandraVacationModule implements CassandraModule {
                     .addColumn(CassandraVacationTable.IS_ENABLED, cboolean())
                     .addUDTColumn(CassandraVacationTable.FROM_DATE, SchemaBuilder.frozen(CassandraZonedDateTimeModule.ZONED_DATE_TIME))
                     .addUDTColumn(CassandraVacationTable.TO_DATE, SchemaBuilder.frozen(CassandraZonedDateTimeModule.ZONED_DATE_TIME))
-                    .addColumn(CassandraVacationTable.TEXT, text())));
+                    .addColumn(CassandraVacationTable.TEXT, text())
+                    .addColumn(CassandraVacationTable.SUBJECT, text())));
         index = ImmutableList.of();
         types = ImmutableList.of();
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ed51b58/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/vacation/tables/CassandraVacationTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/vacation/tables/CassandraVacationTable.java
b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/vacation/tables/CassandraVacationTable.java
index 7e9b3e2..271820b 100644
--- a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/vacation/tables/CassandraVacationTable.java
+++ b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/vacation/tables/CassandraVacationTable.java
@@ -27,5 +27,6 @@ public interface CassandraVacationTable {
     String TO_DATE = "to_date";
     String IS_ENABLED = "is_enabled";
     String TEXT = "text";
+    String SUBJECT = "subject";
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ed51b58/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/vacation/Vacation.java
----------------------------------------------------------------------
diff --git a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/vacation/Vacation.java
b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/vacation/Vacation.java
index cb0fbfe..9b76409 100644
--- a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/vacation/Vacation.java
+++ b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/vacation/Vacation.java
@@ -38,6 +38,7 @@ public class Vacation {
         private Optional<Boolean> isEnabled = Optional.empty();
         private Optional<ZonedDateTime> fromDate = Optional.empty();
         private Optional<ZonedDateTime> toDate = Optional.empty();
+        private Optional<String> subject = Optional.empty();
         private String textBody = "";
 
         public Builder enabled(boolean enabled) {
@@ -62,30 +63,38 @@ public class Vacation {
             return this;
         }
 
+        public Builder subject(Optional<String> subject) {
+            this.subject = subject;
+            return this;
+        }
+
         public Builder copy(Vacation vacation) {
             this.textBody = vacation.getTextBody();
             this.fromDate = vacation.getFromDate();
             this.toDate = vacation.getToDate();
             this.isEnabled = Optional.of(vacation.isEnabled());
+            this.subject = vacation.getSubject();
             return this;
         }
 
         public Vacation build() {
             Preconditions.checkNotNull(textBody);
-            return new Vacation(isEnabled.orElse(DEFAULT_DISABLED), fromDate, toDate, textBody);
+            return new Vacation(isEnabled.orElse(DEFAULT_DISABLED), fromDate, toDate, textBody,
subject);
         }
     }
 
     private final boolean isEnabled;
     private final Optional<ZonedDateTime> fromDate;
     private final Optional<ZonedDateTime> toDate;
+    private final Optional<String> subject;
     private final String textBody;
 
-    private Vacation(boolean isEnabled, Optional<ZonedDateTime> fromDate, Optional<ZonedDateTime>
toDate, String textBody) {
+    private Vacation(boolean isEnabled, Optional<ZonedDateTime> fromDate, Optional<ZonedDateTime>
toDate, String textBody, Optional<String> subject) {
         this.isEnabled = isEnabled;
         this.fromDate = fromDate;
         this.toDate = toDate;
         this.textBody = textBody;
+        this.subject = subject;
     }
 
 
@@ -105,6 +114,10 @@ public class Vacation {
         return textBody;
     }
 
+    public Optional<String> getSubject() {
+        return subject;
+    }
+
     public boolean isActiveAtDate(ZonedDateTime instant) {
         Preconditions.checkNotNull(instant);
         return isEnabled
@@ -130,12 +143,13 @@ public class Vacation {
         return Objects.equals(this.isEnabled, vacation.isEnabled) &&
             Objects.equals(this.fromDate, vacation.fromDate) &&
             Objects.equals(this.toDate, vacation.toDate) &&
-            Objects.equals(this.textBody, vacation.textBody);
+            Objects.equals(this.textBody, vacation.textBody) &&
+            Objects.equals(this.subject, vacation.subject);
     }
 
     @Override
     public int hashCode() {
-        return Objects.hash(isEnabled, fromDate, toDate, textBody);
+        return Objects.hash(isEnabled, fromDate, toDate, textBody, subject);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ed51b58/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/AbstractVacationRepositoryTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/AbstractVacationRepositoryTest.java
b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/AbstractVacationRepositoryTest.java
index ba15584..4b4c932 100644
--- a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/AbstractVacationRepositoryTest.java
+++ b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/AbstractVacationRepositoryTest.java
@@ -31,8 +31,15 @@ public abstract class AbstractVacationRepositoryTest {
 
     public static final AccountId ACCOUNT_ID = AccountId.fromString("identifier");
     public static final ZonedDateTime ZONED_DATE_TIME = ZonedDateTime.parse("2016-04-03T02:01+07:00[Asia/Vientiane]");
-    public static final Vacation VACATION_1 = Vacation.builder().enabled(true).build();
-    public static final Vacation VACATION_2 = Vacation.builder().fromDate(Optional.of(ZONED_DATE_TIME)).enabled(true).build();
+    public static final Vacation VACATION_1 = Vacation.builder()
+        .enabled(true)
+        .build();
+    public static final Vacation VACATION_2 = Vacation.builder()
+        .fromDate(Optional.of(ZONED_DATE_TIME))
+        .enabled(true)
+        .subject(Optional.of("subject"))
+        .build();
+
 
     private VacationRepository vacationRepository;
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ed51b58/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetVacationResponseTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetVacationResponseTest.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetVacationResponseTest.java
index f2a5498..7e49b56 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetVacationResponseTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetVacationResponseTest.java
@@ -49,6 +49,7 @@ public abstract class GetVacationResponseTest {
     private static final String USERS_DOMAIN = "domain.tld";
     public static final String USER = "username@" + USERS_DOMAIN;
     public static final String PASSWORD = "password";
+    public static final String SUBJECT = "subject";
 
     protected abstract GuiceJamesServer createJmapServer();
 
@@ -98,7 +99,8 @@ public abstract class GetVacationResponseTest {
             .body(ARGUMENTS + ".list[0].fromDate", nullValue())
             .body(ARGUMENTS + ".list[0].toDate", nullValue())
             .body(ARGUMENTS + ".list[0].isEnabled", equalTo(false))
-            .body(ARGUMENTS + ".list[0].textBody", equalTo(""));
+            .body(ARGUMENTS + ".list[0].textBody", equalTo(""))
+            .body(ARGUMENTS + ".list[0].subject", nullValue());
     }
 
     @Test
@@ -109,6 +111,7 @@ public abstract class GetVacationResponseTest {
                 .fromDate(Optional.of(ZonedDateTime.parse("2014-09-30T14:10:00Z")))
                 .toDate(Optional.of(ZonedDateTime.parse("2014-10-30T14:10:00Z")))
                 .textBody("Test explaining my vacations")
+                .subject(Optional.of(SUBJECT))
                 .build());
 
         given()
@@ -131,7 +134,8 @@ public abstract class GetVacationResponseTest {
             .body(ARGUMENTS + ".list[0].fromDate", equalTo("2014-09-30T14:10:00Z"))
             .body(ARGUMENTS + ".list[0].toDate", equalTo("2014-10-30T14:10:00Z"))
             .body(ARGUMENTS + ".list[0].isEnabled", equalTo(true))
-            .body(ARGUMENTS + ".list[0].textBody", equalTo("Test explaining my vacations"));
+            .body(ARGUMENTS + ".list[0].textBody", equalTo("Test explaining my vacations"))
+            .body(ARGUMENTS + ".list[0].subject", equalTo(SUBJECT));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ed51b58/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java
index d74526e..dcf46e7 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java
@@ -48,6 +48,7 @@ public abstract class SetVacationResponseTest {
     private static final String USERS_DOMAIN = "domain.tld";
     public static final String USER = "username@" + USERS_DOMAIN;
     public static final String PASSWORD = "password";
+    public static final String SUBJECT = "subject";
 
     protected abstract GuiceJamesServer createJmapServer();
 
@@ -146,7 +147,8 @@ public abstract class SetVacationResponseTest {
                         "\"isEnabled\": \"true\"," +
                         "\"textBody\": \"Message explaining my wonderful vacations\"," +
                         "\"fromDate\":\"2014-09-30T14:10:00Z[GMT]\"," +
-                        "\"toDate\":\"2014-10-30T14:10:00Z[GMT]\"" +
+                        "\"toDate\":\"2014-10-30T14:10:00Z[GMT]\"," +
+                        "\"subject\":\"" + SUBJECT + "\"" +
                     "}" +
                 "}" +
             "}, " +
@@ -170,6 +172,7 @@ public abstract class SetVacationResponseTest {
         assertThat(vacation.isEnabled()).isTrue();
         assertThat(vacation.getFromDate()).contains(ZonedDateTime.parse("2014-09-30T14:10:00Z[GMT]"));
         assertThat(vacation.getToDate()).contains(ZonedDateTime.parse("2014-10-30T14:10:00Z[GMT]"));
+        assertThat(vacation.getSubject()).contains(SUBJECT);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ed51b58/server/protocols/jmap/src/main/java/org/apache/james/jmap/mailet/VacationReply.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/mailet/VacationReply.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/mailet/VacationReply.java
index bd15641..222644a 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/mailet/VacationReply.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/mailet/VacationReply.java
@@ -20,6 +20,7 @@
 package org.apache.james.jmap.mailet;
 
 import java.util.List;
+import java.util.Optional;
 
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
@@ -27,6 +28,8 @@ import javax.mail.internet.MimeMessage;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 
+import com.github.fge.lambdas.Throwing;
+import com.github.fge.lambdas.consumers.ThrowingConsumer;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 
@@ -42,6 +45,7 @@ public class VacationReply {
         private final Mail originalMail;
         private MailAddress mailRecipient;
         private String reason;
+        private Optional<String> subject = Optional.empty();
 
         private Builder(Mail originalMail) {
             Preconditions.checkNotNull(originalMail, "Origin mail shall not be null");
@@ -60,6 +64,11 @@ public class VacationReply {
             return this;
         }
 
+        public Builder subject(Optional<String> subject) {
+            this.subject = subject;
+            return this;
+        }
+
         public VacationReply build() throws MessagingException {
             Preconditions.checkState(mailRecipient != null, "Original recipient address should
not be null");
             Preconditions.checkState(originalMail.getSender() != null, "Original sender address
should not be null");
@@ -69,6 +78,7 @@ public class VacationReply {
 
         private MimeMessage generateMimeMessage() throws MessagingException {
             MimeMessage reply = (MimeMessage) originalMail.getMessage().reply(NOT_REPLY_TO_ALL);
+            subject.ifPresent(Throwing.consumer(subjectString -> reply.setHeader("subject",
subjectString)));
             reply.setText(reason);
             reply.setHeader("from", mailRecipient.toString());
             reply.setHeader("to", originalMail.getSender().toString());

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ed51b58/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetVacationResponseMethod.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetVacationResponseMethod.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetVacationResponseMethod.java
index dde98f5..cc022c3 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetVacationResponseMethod.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetVacationResponseMethod.java
@@ -118,6 +118,7 @@ public class SetVacationResponseMethod implements Method {
             .fromDate(vacationResponse.getFromDate())
             .toDate(vacationResponse.getToDate())
             .textBody(vacationResponse.getTextBody())
+            .subject(vacationResponse.getSubject())
             .build();
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ed51b58/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/VacationResponse.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/VacationResponse.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/VacationResponse.java
index 6d88e0c..410ab2c 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/VacationResponse.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/VacationResponse.java
@@ -47,6 +47,7 @@ public class VacationResponse {
         private boolean isEnabled;
         private Optional<ZonedDateTime> fromDate = Optional.empty();
         private Optional<ZonedDateTime> toDate = Optional.empty();
+        private Optional<String> subject = Optional.empty();
         private String textBody;
 
         public Builder id(String id) {
@@ -77,18 +78,24 @@ public class VacationResponse {
             return this;
         }
 
+        public Builder subject(Optional<String> subject) {
+            this.subject = subject;
+            return this;
+        }
+
         public Builder fromVacation(Vacation vacation) {
             this.id = Vacation.ID;
             this.isEnabled = vacation.isEnabled();
             this.fromDate = vacation.getFromDate();
             this.toDate = vacation.getToDate();
             this.textBody = vacation.getTextBody();
+            this.subject = vacation.getSubject();
             return this;
         }
 
         public VacationResponse build() {
             Preconditions.checkState(textBody != null, "textBody property of vacationResponse
object should not be null");
-            return new VacationResponse(id, isEnabled, fromDate, toDate, textBody);
+            return new VacationResponse(id, isEnabled, fromDate, toDate, textBody, subject);
         }
     }
 
@@ -96,14 +103,17 @@ public class VacationResponse {
     private final boolean isEnabled;
     private final Optional<ZonedDateTime> fromDate;
     private final Optional<ZonedDateTime> toDate;
+    private final Optional<String> subject;
     private final String textBody;
 
-    private VacationResponse(String id, boolean isEnabled, Optional<ZonedDateTime>
fromDate, Optional<ZonedDateTime> toDate, String textBody) {
+    private VacationResponse(String id, boolean isEnabled, Optional<ZonedDateTime>
fromDate, Optional<ZonedDateTime> toDate,
+                             String textBody, Optional<String> subject) {
         this.id = id;
         this.isEnabled = isEnabled;
         this.fromDate = fromDate;
         this.toDate = toDate;
         this.textBody = textBody;
+        this.subject = subject;
     }
 
     public String getId() {
@@ -129,6 +139,10 @@ public class VacationResponse {
         return textBody;
     }
 
+    public Optional<String> getSubject() {
+        return subject;
+    }
+
     @JsonIgnore
     public boolean isValid() {
         return id.equals(Vacation.ID);
@@ -146,11 +160,12 @@ public class VacationResponse {
             && Objects.equals(this.isEnabled, that.isEnabled)
             && Objects.equals(this.fromDate, that.fromDate)
             && Objects.equals(this.toDate, that.toDate)
-            && Objects.equals(this.textBody, that.textBody);
+            && Objects.equals(this.textBody, that.textBody)
+            && Objects.equals(this.subject, that.subject);
     }
 
     @Override
     public int hashCode() {
-        return Objects.hash(id, isEnabled, fromDate, toDate, textBody);
+        return Objects.hash(id, isEnabled, fromDate, toDate, textBody, subject);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ed51b58/server/protocols/jmap/src/test/java/org/apache/james/jmap/mailet/VacationReplyTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/mailet/VacationReplyTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/mailet/VacationReplyTest.java
index 64bb6bf..93d7ffc 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/mailet/VacationReplyTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/mailet/VacationReplyTest.java
@@ -21,6 +21,7 @@ package org.apache.james.jmap.mailet;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
+import java.util.Optional;
 import java.util.Properties;
 
 import javax.mail.Session;
@@ -29,19 +30,29 @@ import javax.mail.internet.MimeMessage;
 import org.apache.commons.io.IOUtils;
 import org.apache.mailet.MailAddress;
 import org.apache.mailet.base.test.FakeMail;
+import org.junit.Before;
 import org.junit.Test;
 
 public class VacationReplyTest {
 
     public static final String REASON = "I am in vacation dudes !";
+    public static final Optional<String> SUBJECT = Optional.of("Vacation subject specified
by the user!");
+    private MailAddress originalSender;
+    private MailAddress originalRecipient;
+    private FakeMail mail;
 
-    @Test
-    public void vacationReplyShouldGenerateASuitableAnswer() throws Exception {
-        MailAddress originalSender = new MailAddress("distant@apache.org");
-        MailAddress originalRecipient = new MailAddress("benwa@apache.org");
-        FakeMail mail = new FakeMail();
+    @Before
+    public void setUp() throws Exception {
+        originalSender = new MailAddress("distant@apache.org");
+        originalRecipient = new MailAddress("benwa@apache.org");
+
+        mail = new FakeMail();
         mail.setMessage(new MimeMessage(Session.getInstance(new Properties()) ,ClassLoader.getSystemResourceAsStream("spamMail.eml")));
         mail.setSender(originalSender);
+    }
+
+    @Test
+    public void vacationReplyShouldGenerateASuitableAnswer() throws Exception {
 
         VacationReply vacationReply = VacationReply.builder(mail)
             .reason(REASON)
@@ -50,10 +61,30 @@ public class VacationReplyTest {
 
         assertThat(vacationReply.getRecipients()).containsExactly(originalSender);
         assertThat(vacationReply.getSender()).isEqualTo(originalRecipient);
-        assertThat(vacationReply.getMimeMessage().getHeader("subject")).containsExactly("Re:
Original subject");
         assertThat(IOUtils.toString(vacationReply.getMimeMessage().getInputStream())).contains(REASON);
     }
 
+    @Test
+    public void vacationReplyShouldAddReSuffixToSubjectByDefault() throws Exception {
+        VacationReply vacationReply = VacationReply.builder(mail)
+            .reason(REASON)
+            .receivedMailRecipient(originalRecipient)
+            .build();
+
+        assertThat(vacationReply.getMimeMessage().getHeader("subject")).containsExactly("Re:
Original subject");
+    }
+
+    @Test
+    public void aUserShouldBeAbleToSetTheSubjectOfTheGeneratedMimeMessage() throws Exception
{
+        VacationReply vacationReply = VacationReply.builder(mail)
+            .reason(REASON)
+            .subject(SUBJECT)
+            .receivedMailRecipient(originalRecipient)
+            .build();
+
+        assertThat(vacationReply.getMimeMessage().getHeader("subject")).containsExactly(SUBJECT.get());
+    }
+
     @Test(expected = NullPointerException.class)
     public void vacationReplyShouldThrowOnNullMail() {
         VacationReply.builder(null);

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ed51b58/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetVacationResponseMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetVacationResponseMethodTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetVacationResponseMethodTest.java
index a03a844..2bb3902 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetVacationResponseMethodTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetVacationResponseMethodTest.java
@@ -23,6 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+import java.util.Optional;
 import java.util.concurrent.CompletableFuture;
 import java.util.stream.Stream;
 
@@ -81,6 +82,7 @@ public class GetVacationResponseMethodTest {
         Vacation vacation = Vacation.builder()
             .enabled(true)
             .textBody("I am in vacation")
+            .subject(Optional.of("subject"))
             .build();
         when(vacationRepository.retrieveVacation(AccountId.fromString(USERNAME))).thenReturn(CompletableFuture.completedFuture(vacation));
         when(mailboxSession.getUser()).thenReturn(user);

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ed51b58/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetVacationResponseMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetVacationResponseMethodTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetVacationResponseMethodTest.java
index 5244ccd..338430f 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetVacationResponseMethodTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetVacationResponseMethodTest.java
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.when;
 
 import java.util.List;
 import java.util.Locale;
+import java.util.Optional;
 import java.util.concurrent.CompletableFuture;
 import java.util.stream.Stream;
 
@@ -67,6 +68,7 @@ public class SetVacationResponseMethodTest {
             return null;
         }
     };
+    public static final String SUBJECT = "subject";
 
     private SetVacationResponseMethod testee;
     private VacationRepository vacationRepository;
@@ -178,11 +180,13 @@ public class SetVacationResponseMethodTest {
                     .id(Vacation.ID)
                     .enabled(false)
                     .textBody(TEXT_BODY)
+                    .subject(Optional.of(SUBJECT))
                     .build()))
             .build();
         Vacation vacation = Vacation.builder()
             .enabled(false)
             .textBody(TEXT_BODY)
+            .subject(Optional.of(SUBJECT))
             .build();
         AccountId accountId = AccountId.fromString(USERNAME);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ed51b58/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/VacationResponseTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/VacationResponseTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/VacationResponseTest.java
index c4d8aa7..63f68bc 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/VacationResponseTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/VacationResponseTest.java
@@ -32,6 +32,7 @@ public class VacationResponseTest {
     public static final String MESSAGE = "A message explaining I am in vacation";
     public static final ZonedDateTime FROM_DATE = ZonedDateTime.parse("2016-04-15T11:56:32.224+07:00[Asia/Vientiane]");
     public static final ZonedDateTime TO_DATE = ZonedDateTime.parse("2016-04-16T11:56:32.224+07:00[Asia/Vientiane]");
+    public static final String SUBJECT = "subject";
 
     @Test
     public void vacationResponseBuilderShouldBeConstructedWithTheRightInformation() {
@@ -41,6 +42,7 @@ public class VacationResponseTest {
             .fromDate(Optional.of(FROM_DATE))
             .toDate(Optional.of(TO_DATE))
             .textBody(MESSAGE)
+            .subject(Optional.of(SUBJECT))
             .build();
 
         assertThat(vacationResponse.getId()).isEqualTo(IDENTIFIER);
@@ -48,6 +50,7 @@ public class VacationResponseTest {
         assertThat(vacationResponse.getTextBody()).isEqualTo(MESSAGE);
         assertThat(vacationResponse.getFromDate()).contains(FROM_DATE);
         assertThat(vacationResponse.getToDate()).contains(TO_DATE);
+        assertThat(vacationResponse.getSubject()).contains(SUBJECT);
     }
 
     @Test(expected = IllegalStateException.class)


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message