james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [11/50] [abbrv] james-project git commit: MAILET-115 Remove abstract setSubjectPrefix implementation
Date Wed, 11 Jan 2017 09:25:59 GMT
MAILET-115 Remove abstract setSubjectPrefix implementation


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

Branch: refs/heads/master
Commit: bc3c5462cc27823243c5fbbc12fdb0353f907f25
Parents: 33deb2e
Author: Antoine Duprat <aduprat@apache.org>
Authored: Wed Oct 5 12:07:05 2016 +0200
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Wed Jan 11 10:03:28 2017 +0700

----------------------------------------------------------------------
 .../apache/james/transport/mailets/Bounce.java  |  6 ++++
 .../james/transport/mailets/DSNBounce.java      |  6 ++++
 .../apache/james/transport/mailets/Forward.java |  8 +++++
 .../transport/mailets/NotifyPostmaster.java     |  6 ++++
 .../james/transport/mailets/NotifySender.java   |  6 ++++
 .../james/transport/mailets/Redirect.java       |  8 +++++
 .../apache/james/transport/mailets/Resend.java  |  9 +++++
 .../mailets/redirect/AbstractRedirect.java      | 37 +++++++++++++++-----
 .../mailets/redirect/AbstractRedirectTest.java  |  4 +++
 9 files changed, 82 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/bc3c5462/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Bounce.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Bounce.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Bounce.java
index 91f3257..9bb8be3 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Bounce.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Bounce.java
@@ -30,6 +30,7 @@ import org.apache.james.transport.mailets.redirect.InitParameters;
 import org.apache.james.transport.mailets.redirect.NotifyMailetInitParameters;
 import org.apache.james.transport.mailets.redirect.NotifyMailetsMessage;
 import org.apache.james.transport.mailets.redirect.SpecialAddress;
+import org.apache.james.transport.mailets.utils.MimeMessageModifier;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 
@@ -162,6 +163,11 @@ public class Bounce extends AbstractRedirect {
     }
 
     @Override
+    protected void setSubjectPrefix(Mail newMail, String subjectPrefix, Mail originalMail)
throws MessagingException {
+        new MimeMessageModifier(originalMail.getMessage()).addSubjectPrefix(subjectPrefix);
+    }
+
+    @Override
     public void service(Mail originalMail) throws MessagingException {
         if (originalMail.getSender() == null) {
             passThrough(originalMail);

http://git-wip-us.apache.org/repos/asf/james-project/blob/bc3c5462/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
index b69a905..08d5378 100755
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
@@ -40,6 +40,7 @@ import org.apache.james.transport.mailets.redirect.NotifyMailetInitParameters;
 import org.apache.james.transport.mailets.redirect.NotifyMailetsMessage;
 import org.apache.james.transport.mailets.redirect.SpecialAddress;
 import org.apache.james.transport.mailets.redirect.TypeCode;
+import org.apache.james.transport.mailets.utils.MimeMessageModifier;
 import org.apache.james.transport.util.Patterns;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
@@ -156,6 +157,11 @@ public class DSNBounce extends AbstractRedirect {
     }
 
     @Override
+    protected void setSubjectPrefix(Mail newMail, String subjectPrefix, Mail originalMail)
throws MessagingException {
+        new MimeMessageModifier(originalMail.getMessage()).addSubjectPrefix(subjectPrefix);
+    }
+
+    @Override
     public void service(Mail originalMail) throws MessagingException {
         if (originalMail.getSender() == null) {
             if (getInitParameters().isDebug()) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/bc3c5462/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Forward.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Forward.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Forward.java
index ecbc9d4..d5e9d13 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Forward.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Forward.java
@@ -177,4 +177,12 @@ public class Forward extends AbstractRedirect {
     protected MailAddress getSender() throws MessagingException {
         return null;
     }
+
+    @Override
+    protected void setSubjectPrefix(Mail newMail, String subjectPrefix, Mail originalMail)
throws MessagingException {
+        Optional<String> newSubject = getNewSubject(subjectPrefix, originalMail);
+        if (newSubject.isPresent()) {
+            changeSubject(newMail.getMessage(), newSubject.get());
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bc3c5462/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifyPostmaster.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifyPostmaster.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifyPostmaster.java
index 153d433..56210a8 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifyPostmaster.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifyPostmaster.java
@@ -31,6 +31,7 @@ import org.apache.james.transport.mailets.redirect.InitParameters;
 import org.apache.james.transport.mailets.redirect.NotifyMailetInitParameters;
 import org.apache.james.transport.mailets.redirect.NotifyMailetsMessage;
 import org.apache.james.transport.mailets.redirect.SpecialAddress;
+import org.apache.james.transport.mailets.utils.MimeMessageModifier;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 import org.apache.mailet.MailetConfig;
@@ -179,4 +180,9 @@ public class NotifyPostmaster extends AbstractRedirect {
         return getSender(originalMail);
     }
 
+    @Override
+    protected void setSubjectPrefix(Mail newMail, String subjectPrefix, Mail originalMail)
throws MessagingException {
+        new MimeMessageModifier(originalMail.getMessage()).addSubjectPrefix(subjectPrefix);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bc3c5462/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifySender.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifySender.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifySender.java
index 0e37607..62a69a5 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifySender.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifySender.java
@@ -32,6 +32,7 @@ import org.apache.james.transport.mailets.redirect.InitParameters;
 import org.apache.james.transport.mailets.redirect.NotifyMailetInitParameters;
 import org.apache.james.transport.mailets.redirect.NotifyMailetsMessage;
 import org.apache.james.transport.mailets.redirect.SpecialAddress;
+import org.apache.james.transport.mailets.utils.MimeMessageModifier;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 import org.apache.mailet.MailetConfig;
@@ -179,4 +180,9 @@ public class NotifySender extends AbstractRedirect {
     protected MailAddress getReversePath(Mail originalMail) throws MessagingException {
         return getSender(originalMail);
     }
+
+    @Override
+    protected void setSubjectPrefix(Mail newMail, String subjectPrefix, Mail originalMail)
throws MessagingException {
+        new MimeMessageModifier(originalMail.getMessage()).addSubjectPrefix(subjectPrefix);
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bc3c5462/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Redirect.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Redirect.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Redirect.java
index dd692f3..125c876 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Redirect.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Redirect.java
@@ -415,4 +415,12 @@ public class Redirect extends AbstractRedirect {
         return reversePath;
     }
 
+    @Override
+    protected void setSubjectPrefix(Mail newMail, String subjectPrefix, Mail originalMail)
throws MessagingException {
+        Optional<String> newSubject = getNewSubject(subjectPrefix, originalMail);
+        if (newSubject.isPresent()) {
+            changeSubject(newMail.getMessage(), newSubject.get());
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bc3c5462/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Resend.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Resend.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Resend.java
index 8d0cb0b..ab61b3e 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Resend.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Resend.java
@@ -31,6 +31,7 @@ import org.apache.james.transport.mailets.redirect.RedirectMailetInitParameters;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 
+import com.google.common.base.Optional;
 import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
 
@@ -351,4 +352,12 @@ public class Resend extends AbstractRedirect {
         return reversePath;
     }
 
+    @Override
+    protected void setSubjectPrefix(Mail newMail, String subjectPrefix, Mail originalMail)
throws MessagingException {
+        Optional<String> newSubject = getNewSubject(subjectPrefix, originalMail);
+        if (newSubject.isPresent()) {
+            changeSubject(newMail.getMessage(), newSubject.get());
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bc3c5462/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AbstractRedirect.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AbstractRedirect.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AbstractRedirect.java
index 6f30633..aa65857 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AbstractRedirect.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AbstractRedirect.java
@@ -42,7 +42,6 @@ import org.apache.james.core.MailImpl;
 import org.apache.james.core.MimeMessageUtil;
 import org.apache.james.dnsservice.api.DNSService;
 import org.apache.james.transport.mailets.Redirect;
-import org.apache.james.transport.mailets.utils.MimeMessageModifier;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 import org.apache.mailet.base.DateFormats;
@@ -475,11 +474,33 @@ public abstract class AbstractRedirect extends GenericMailet {
      * <i>originalMail</i> to <i>subjectPrefix</i>. Is a "setX(Mail,
Tx, Mail)"
      * method.
      */
-    protected void setSubjectPrefix(Mail newMail, String subjectPrefix, Mail originalMail)
throws MessagingException {
-        if (isNotifyMailet()) {
-            new MimeMessageModifier(originalMail.getMessage()).addSubjectPrefix(subjectPrefix);
-        }
-
+    protected abstract void setSubjectPrefix(Mail newMail, String subjectPrefix, Mail originalMail)
throws MessagingException;
+//        if (isNotifyMailet()) {
+//            new MimeMessageModifier(originalMail.getMessage()).addSubjectPrefix(subjectPrefix);
+//        }
+//
+//        String subject = getInitParameters().getSubject();
+//        if (!Strings.isNullOrEmpty(subjectPrefix) || subject != null) {
+//            String newSubject = Strings.nullToEmpty(subject);
+//            if (subject == null) {
+//                newSubject = Strings.nullToEmpty(originalMail.getMessage().getSubject());
+//            } else {
+//                if (getInitParameters().isDebug()) {
+//                    log("subject set to: " + subject);
+//                }
+//            }
+//
+//            if (subjectPrefix != null) {
+//                newSubject = subjectPrefix + newSubject;
+//                if (getInitParameters().isDebug()) {
+//                    log("subjectPrefix set to: " + subjectPrefix);
+//                }
+//            }
+//            changeSubject(newMail.getMessage(), newSubject);
+//        }
+//    }
+
+    protected Optional<String> getNewSubject(String subjectPrefix, Mail originalMail)
throws MessagingException {
         String subject = getInitParameters().getSubject();
         if (!Strings.isNullOrEmpty(subjectPrefix) || subject != null) {
             String newSubject = Strings.nullToEmpty(subject);
@@ -497,10 +518,10 @@ public abstract class AbstractRedirect extends GenericMailet {
                     log("subjectPrefix set to: " + subjectPrefix);
                 }
             }
-            changeSubject(newMail.getMessage(), newSubject);
+            return Optional.of(newSubject);
         }
+        return Optional.absent();
     }
-
     /**
      * Sets the "In-Reply-To:" header of <i>newMail</i> to the "Message-Id:"
of
      * <i>originalMail</i>, if <i>isReply</i> is true.

http://git-wip-us.apache.org/repos/asf/james-project/blob/bc3c5462/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/AbstractRedirectTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/AbstractRedirectTest.java
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/AbstractRedirectTest.java
index c8926fd..8847bfb 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/AbstractRedirectTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/AbstractRedirectTest.java
@@ -84,6 +84,10 @@ public class AbstractRedirectTest {
         protected MailAddress getReversePath(Mail originalMail) throws MessagingException
{
             return null;
         }
+
+        @Override
+        protected void setSubjectPrefix(Mail newMail, String subjectPrefix, Mail originalMail)
throws MessagingException {
+        }
     }
 
     @Test


---------------------------------------------------------------------
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