Hello all,
Finally was I able to build and test package with my changes to support
Subaddress.
Patch is attached. Can you please review the changes? Any comments and
advices are highly appreciated.

On Wed, May 11, 2016 at 8:58 PM, Sergey Lysenkov <
[email protected]> wrote:

> Hello all,
>
> I have created JIRA issue https://issues.apache.org/jira/browse/MAILET-97
> - Sub-addressing (tagged addressing) support in JAMES.
> I have made changes in "org.apache.james.protocols.smtp.MailAddress.java"
> class and tryed to build JAMES protocol-smtp package, so I can test my
> changes. When I run "mvn clean package" command in folder "protocols/smtp"
> to build package, I'm getting the following error:
>
> [ERROR]
> /home/sergey/workspace/java-projects/contribution/apache/james/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/MailCmdHandler.java:[31,40]
> package org.apache.commons.configuration does not exist
> [ERROR]
> /home/sergey/workspace/java-projects/contribution/apache/james/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/MailCmdHandler.java:[32,40]
> package org.apache.commons.configuration does not exist
>
> Local maven repository ($HOME/.m2/repository) contains the mentioned above
> package "org.apache.commons.configuration". Can you please advise how do
> you build James packages?
>
> On Wed, May 4, 2016 at 6:38 AM, Benoit Tellier <[email protected]> wrote:
>
>> I think you can't deny MailAddress represent the same concept in both
>> mailet and protocols/smtp .
>>
>> Thus, it seems logical to have one object to represent it.
>>
>> I agree the way I proposed to share this code might not be optimal.
>> Maybe some common dependency might be better.
>>
>> Note : MailetMailAddressAdapter converts
>> org.apache.james.protocols.smtp.MailAddress into
>> org.apache.mailet.MailAddress. Both  MailAddress classes are copied and
>> paste from one another and have started to diverge. One is tested not
>> the other.
>>
>> Le 02/05/2016 à 16:22, Matthieu Baechler a écrit :
>> >
>> >
>> > On 04/29/2016 08:32 AM, Benoit Tellier wrote:
>> >> Moreover, we should take advantage of this task to factorize code :
>> >>
>> >> We have two MailAddress classes :
>> >>
>> >> org.apache.mailet.MailAddress
>> >> org.apache.james.protocols.smtp.MailAddress;
>> >>
>> >> These two class have almost the same content (copy and paste ?), and
>> >> tests are only written for the mailet one.
>> >>
>> >> In my opinion, we must make smtp protocol depend on mailet api to reuse
>> >> MailAddress object across our projects and fight code duplication.
>> >>
>> > IMO you overestimate the value of sharing code.
>> >
>> > Why SMTP should depend on mailet from a business point of view ?
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
>
diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/MailAddress.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/MailAddress.java
index 8cdd964..967d21a 100644
--- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/MailAddress.java
+++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/MailAddress.java
@@ -65,6 +65,7 @@ public class MailAddress {
 
     private String localPart = null;
     private String domain = null;
+    private String subaddress = null;
 
     private static final MailAddress NULL_SENDER = new MailAddress() {
 
@@ -186,7 +187,7 @@ public class MailAddress {
             throw new MailAddressException("Out of data at position " + (pos + 1) + " in '" + address + "'",address,pos+1);
         }
 
-        localPart = localPartSB.toString();
+        localPart = parseSubaddress(localPartSB.toString());
         domain = domainSB.toString();
     }
 
@@ -518,4 +519,29 @@ public class MailAddress {
     public boolean isNullSender() {
         return false;
     }
+
+    /**
+     * Extract subaddress part RFC 5233 from local-part portion
+     *
+     * @param localPart the local-part portion. This is a domain dependent string.
+     *        In addresses, it is simply interpreted on the particular host as a
+     *        name of a particular mailbox. per RFC2822 3.4.1. addr-spec specification
+     * @return the local-part of this email address as defined by the
+     *          RFC2822 3.4.1. addr-spec specification without subaddress part if exist (RFC 5233)
+     */
+    public String parseSubaddress (String localPart) {
+
+        int posOfPlus = localPart.indexOf("+");
+
+        if (posOfPlus > 0) {
+
+            if (subaddress == null || subaddress.isEmpty()) {
+                subaddress = localPart.substring((posOfPlus + 1));
+            }
+
+            localPart = localPart.substring(0, posOfPlus);
+        }
+
+        return localPart;
+    }
 }
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to