Skip to content

Commit 33e9521

Browse files
committed
Merge pull request #29 from ArcBees/rl_replyTo_mail
Added reply-to address for appengine mail #26
2 parents 957dc09 + 6331821 commit 33e9521

14 files changed

+194
-42
lines changed

appengine-mail/src/main/java/com/arcbees/appengine/mail/Email.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2013 ArcBees Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
@@ -28,4 +28,6 @@ public interface Email extends Serializable {
2828
String getSubject();
2929

3030
String getBody();
31+
32+
String getReplyToAddress();
3133
}

appengine-mail/src/main/java/com/arcbees/appengine/mail/EmailBuilder.java

+25-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2013 ArcBees Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
@@ -34,6 +34,8 @@ public MailBuilderFromAddress fromAddress(String from) {
3434
public static class MailBuilderFromAddress {
3535
private final String fromAddress;
3636
private final MailBuilderTo mailBuilderTo;
37+
38+
private String replyToAddress;
3739
private String subject;
3840
private String body;
3941
private String fromPersonal;
@@ -44,6 +46,7 @@ private MailBuilderFromAddress(String fromAddress,
4446
this.subject = "";
4547
this.fromAddress = fromAddress;
4648
this.fromPersonal = DEFAULT_PERSONAL;
49+
this.replyToAddress = "";
4750
this.mailBuilderTo = mailBuilderTo;
4851
}
4952

@@ -65,8 +68,14 @@ public MailBuilderFromAddress fromPersonal(String fromPersonal) {
6568
return this;
6669
}
6770

71+
public MailBuilderFromAddress replyToAddress(String replyToAddress) {
72+
this.replyToAddress = replyToAddress;
73+
74+
return this;
75+
}
76+
6877
public Email build() {
69-
return new EmailImpl(mailBuilderTo.to, fromAddress, fromPersonal, subject, body);
78+
return new EmailImpl(this);
7079
}
7180
}
7281

@@ -76,13 +85,15 @@ private static class EmailImpl implements Email {
7685
private final String fromAddress;
7786
private final String fromPersonal;
7887
private final String body;
79-
80-
private EmailImpl(String to, String fromAddress, String fromPersonal, String subject, String body) {
81-
this.to = to;
82-
this.fromAddress = fromAddress;
83-
this.subject = subject;
84-
this.fromPersonal = fromPersonal;
85-
this.body = body;
88+
private final String replyToAddress;
89+
90+
private EmailImpl(MailBuilderFromAddress builder) {
91+
this.to = builder.mailBuilderTo.to;
92+
this.fromAddress = builder.fromAddress;
93+
this.subject = builder.subject;
94+
this.fromPersonal = builder.fromPersonal;
95+
this.body = builder.body;
96+
this.replyToAddress = builder.replyToAddress;
8697
}
8798

8899
@Override
@@ -109,6 +120,11 @@ public String getSubject() {
109120
public String getBody() {
110121
return body;
111122
}
123+
124+
@Override
125+
public String getReplyToAddress() {
126+
return replyToAddress;
127+
}
112128
}
113129

114130
public static MailBuilderTo to(String to) {

appengine-mail/src/main/java/com/arcbees/appengine/mail/EmailSender.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2013 ArcBees Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not

appengine-mail/src/main/java/com/arcbees/appengine/mail/EmailSenderImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2013 ArcBees Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not

appengine-mail/src/main/java/com/arcbees/appengine/mail/EmailService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2013 ArcBees Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not

appengine-mail/src/main/java/com/arcbees/appengine/mail/SendEmailTask.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2013 ArcBees Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
@@ -21,13 +21,15 @@
2121
import java.util.logging.Level;
2222
import java.util.logging.Logger;
2323

24+
import javax.mail.Address;
2425
import javax.mail.Message;
2526
import javax.mail.MessagingException;
2627
import javax.mail.Session;
2728
import javax.mail.internet.InternetAddress;
2829
import javax.mail.internet.MimeMessage;
2930

3031
import com.google.appengine.api.taskqueue.DeferredTask;
32+
import com.google.common.base.Strings;
3133

3234
public class SendEmailTask implements DeferredTask {
3335
private static final String CONTENT_TYPE = "text/html";
@@ -58,6 +60,12 @@ public void run() {
5860
message.setSubject(email.getSubject());
5961
message.setContent(email.getBody(), CONTENT_TYPE);
6062

63+
if (Strings.isNullOrEmpty(email.getReplyToAddress())) {
64+
message.setReplyTo(new Address[] {
65+
new InternetAddress(email.getReplyToAddress())
66+
});
67+
}
68+
6169
transport.send(message);
6270
} catch (MessagingException e) {
6371
logger.log(Level.WARNING, e.getMessage());

appengine-mail/src/main/java/com/arcbees/appengine/mail/TaskOptionsBuilder.java

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2013 ArcBees Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
117
package com.arcbees.appengine.mail;
218

319
import com.google.appengine.api.taskqueue.DeferredTask;

appengine-mail/src/main/java/com/arcbees/appengine/mail/TaskOptionsWithPayloadBuilder.java

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2013 ArcBees Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
117
package com.arcbees.appengine.mail;
218

319
import com.google.appengine.api.taskqueue.DeferredTask;

appengine-mail/src/main/java/com/arcbees/appengine/mail/Transport.java

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2013 ArcBees Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
117
package com.arcbees.appengine.mail;
218

319
import java.io.Serializable;

appengine-mail/src/main/java/com/arcbees/appengine/mail/TransportImpl.java

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2013 ArcBees Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
117
package com.arcbees.appengine.mail;
218

319
import javax.mail.Message;

appengine-mail/src/test/java/com/arcbees/appengine/mail/EmailSenderTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2013 ArcBees Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not

appengine-mail/src/test/java/com/arcbees/appengine/mail/EmailServiceTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2013 ArcBees Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2013 ArcBees Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
@@ -21,71 +21,116 @@
2121
import static org.junit.Assert.assertEquals;
2222

2323
public class MailBuilderFromTest {
24+
public static final String TO = "to";
25+
public static final String FROM_ADDRESS = "fromAddress";
26+
public static final String FROM_PERSONAL = "fromPersonal";
27+
public static final String BODY = "body";
28+
public static final String SUBJECT = "subject";
29+
public static final String REPLY_TO_ADDRESS = "replyToAddress";
30+
2431
@Test
2532
public void build_allFieldsFilled_emailIsWellBuilt() {
2633
//given
27-
EmailBuilder.MailBuilderFromAddress mailBuilderFromAddress = EmailBuilder.to("to").fromAddress("fromAddress").fromPersonal
28-
("fromPersonal").body("body").subject("subject");
34+
EmailBuilder.MailBuilderFromAddress mailBuilderFromAddress = EmailBuilder.to(TO)
35+
.fromAddress(FROM_ADDRESS)
36+
.fromPersonal(FROM_PERSONAL)
37+
.body(BODY)
38+
.subject(SUBJECT)
39+
.replyToAddress(REPLY_TO_ADDRESS);
2940

3041
//when
3142
Email email = mailBuilderFromAddress.build();
3243

3344
//then
34-
assertEquals("to", email.getTo());
35-
assertEquals("fromAddress", email.getFromAddress());
36-
assertEquals("fromPersonal", email.getFromPersonal());
37-
assertEquals("body", email.getBody());
38-
assertEquals("subject", email.getSubject());
45+
assertEquals(TO, email.getTo());
46+
assertEquals(FROM_ADDRESS, email.getFromAddress());
47+
assertEquals(FROM_PERSONAL, email.getFromPersonal());
48+
assertEquals(BODY, email.getBody());
49+
assertEquals(SUBJECT, email.getSubject());
50+
assertEquals(REPLY_TO_ADDRESS, email.getReplyToAddress());
3951
}
4052

4153
@Test
4254
public void build_missingBody_emailIsWellBuilt() {
4355
//given
44-
EmailBuilder.MailBuilderFromAddress mailBuilderFromAddress = EmailBuilder.to("to").fromAddress("fromAddress").fromPersonal
45-
("fromPersonal").subject("subject");
56+
EmailBuilder.MailBuilderFromAddress mailBuilderFromAddress = EmailBuilder.to(TO)
57+
.fromAddress(FROM_ADDRESS)
58+
.fromPersonal(FROM_PERSONAL)
59+
.subject(SUBJECT)
60+
.replyToAddress(REPLY_TO_ADDRESS);
4661

4762
//when
4863
Email email = mailBuilderFromAddress.build();
4964

5065
//then
51-
assertEquals("to", email.getTo());
52-
assertEquals("fromAddress", email.getFromAddress());
53-
assertEquals("fromPersonal", email.getFromPersonal());
66+
assertEquals(TO, email.getTo());
67+
assertEquals(FROM_ADDRESS, email.getFromAddress());
68+
assertEquals(FROM_PERSONAL, email.getFromPersonal());
5469
assertEquals("", email.getBody());
55-
assertEquals("subject", email.getSubject());
70+
assertEquals(SUBJECT, email.getSubject());
71+
assertEquals(REPLY_TO_ADDRESS, email.getReplyToAddress());
5672
}
5773

5874
@Test
5975
public void build_missingSubject_emailIsWellBuilt() {
6076
//given
61-
EmailBuilder.MailBuilderFromAddress mailBuilderFromAddress = EmailBuilder.to("to").fromAddress("fromAddress").fromPersonal
62-
("fromPersonal").body("body");
77+
EmailBuilder.MailBuilderFromAddress mailBuilderFromAddress = EmailBuilder.to(TO)
78+
.fromAddress(FROM_ADDRESS)
79+
.fromPersonal(FROM_PERSONAL)
80+
.body(BODY)
81+
.replyToAddress(REPLY_TO_ADDRESS);
6382

6483
//when
6584
Email email = mailBuilderFromAddress.build();
6685

6786
//then
68-
assertEquals("to", email.getTo());
69-
assertEquals("fromAddress", email.getFromAddress());
70-
assertEquals("fromPersonal", email.getFromPersonal());
71-
assertEquals("body", email.getBody());
87+
assertEquals(TO, email.getTo());
88+
assertEquals(FROM_ADDRESS, email.getFromAddress());
89+
assertEquals(FROM_PERSONAL, email.getFromPersonal());
90+
assertEquals(BODY, email.getBody());
7291
assertEquals("", email.getSubject());
92+
assertEquals(REPLY_TO_ADDRESS, email.getReplyToAddress());
7393
}
7494

7595
@Test
7696
public void build_missingPersonal_emailIsWellBuilt() {
7797
//given
78-
EmailBuilder.MailBuilderFromAddress mailBuilderFromAddress = EmailBuilder.to("to").fromAddress("fromAddress").body
79-
("body").subject("subject");
98+
EmailBuilder.MailBuilderFromAddress mailBuilderFromAddress = EmailBuilder.to(TO)
99+
.fromAddress(FROM_ADDRESS)
100+
.body(BODY)
101+
.subject(SUBJECT)
102+
.replyToAddress(REPLY_TO_ADDRESS);
80103

81104
//when
82105
Email email = mailBuilderFromAddress.build();
83106

84107
//then
85-
assertEquals("to", email.getTo());
86-
assertEquals("fromAddress", email.getFromAddress());
108+
assertEquals(TO, email.getTo());
109+
assertEquals(FROM_ADDRESS, email.getFromAddress());
87110
assertEquals(EmailBuilder.DEFAULT_PERSONAL, email.getFromPersonal());
88-
assertEquals("body", email.getBody());
89-
assertEquals("subject", email.getSubject());
111+
assertEquals(BODY, email.getBody());
112+
assertEquals(SUBJECT, email.getSubject());
113+
assertEquals(REPLY_TO_ADDRESS, email.getReplyToAddress());
114+
}
115+
116+
@Test
117+
public void build_missingReplyToAddress_emailIsWellBuilt() {
118+
//given
119+
EmailBuilder.MailBuilderFromAddress mailBuilderFromAddress = EmailBuilder.to(TO)
120+
.fromAddress(FROM_ADDRESS)
121+
.fromPersonal(FROM_PERSONAL)
122+
.body(BODY)
123+
.subject(SUBJECT);
124+
125+
//when
126+
Email email = mailBuilderFromAddress.build();
127+
128+
//then
129+
assertEquals(TO, email.getTo());
130+
assertEquals(FROM_ADDRESS, email.getFromAddress());
131+
assertEquals(FROM_PERSONAL, email.getFromPersonal());
132+
assertEquals(BODY, email.getBody());
133+
assertEquals(SUBJECT, email.getSubject());
134+
assertEquals("", email.getReplyToAddress());
90135
}
91136
}

0 commit comments

Comments
 (0)