Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4580 change from and reply to addresses in contact email #4600

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ minute=minute
notification.email.checksumfail.subject={0}: Your upload failed checksum validation
notification.email.import.filesystem.subject=Dataset {0} has been successfully uploaded and verified
notification.email.import.checksum.subject={0}: Your file checksum job has completed
contact.delegation={0} on behalf of {1}

# passwordreset.xhtml
pageTitle.passwdReset.pre=Account Password Reset
Expand Down
32 changes: 23 additions & 9 deletions src/main/java/edu/harvard/iq/dataverse/MailServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javax.annotation.Resource;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.mail.Address;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
Expand Down Expand Up @@ -79,7 +80,7 @@ public class MailServiceBean implements java.io.Serializable {
public MailServiceBean() {
}

public void sendMail(String host, String from, String to, String subject, String messageText) {
public void sendMail(String host, String reply, String to, String subject, String messageText) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see any use of this method in the current source...

Properties props = System.getProperties();
props.put("mail.smtp.host", host);
Session session = Session.getDefaultInstance(props, null);
Expand All @@ -89,7 +90,11 @@ public void sendMail(String host, String from, String to, String subject, String
String[] recipientStrings = to.split(",");
InternetAddress[] recipients = new InternetAddress[recipientStrings.length];
try {
msg.setFrom(new InternetAddress(from, charset));
InternetAddress fromAddress=getSystemAddress();
fromAddress.setPersonal(BundleUtil.getStringFromBundle("contact.delegation", Arrays.asList(
fromAddress.getPersonal(), reply)), charset);
msg.setFrom(fromAddress);
msg.setReplyTo(new Address[] {new InternetAddress(reply, charset)});
for (int i = 0; i < recipients.length; i++) {
recipients[i] = new InternetAddress(recipientStrings[i], "", charset);
}
Expand Down Expand Up @@ -164,16 +169,25 @@ public void sendMail(String from, String to, String subject, String messageText)
sendMail(from, to, subject, messageText, new HashMap<>());
}

public void sendMail(String from, String to, String subject, String messageText, Map<Object, Object> extraHeaders) {
public void sendMail(String reply, String to, String subject, String messageText, Map<Object, Object> extraHeaders) {
try {
MimeMessage msg = new MimeMessage(session);
if (from.matches(EMAIL_PATTERN)) {
msg.setFrom(new InternetAddress(from));
//Always send from system address to avoid email being blocked
InternetAddress fromAddress=getSystemAddress();
try {
fromAddress.setPersonal(BundleUtil.getStringFromBundle("contact.delegation", Arrays.asList(
fromAddress.getPersonal(), reply)), charset);
} catch (UnsupportedEncodingException ex) {
logger.severe(ex.getMessage());
}
msg.setFrom(fromAddress);

if (reply.matches(EMAIL_PATTERN)) {
//But set the reply-to address to direct replies to the requested 'from' party if it is a valid email address
msg.setReplyTo(new Address[] {new InternetAddress(reply)});
} else {
// set fake from address; instead, add it as part of the message
//msg.setFrom(new InternetAddress("invalid.email.address@mailinator.com"));
msg.setFrom(getSystemAddress());
messageText = "From: " + from + "\n\n" + messageText;
//Otherwise include the invalid 'from' address in the message
messageText = "From: " + reply + "\n\n" + messageText;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mheppler you want this "From:" line to go away, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pdurbin Maybe someday, but please it as is for this issue. I will open a new issue to track if there is a problem there. Thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mheppler ok, I see you opened #4601. Thanks.

}
msg.setSentDate(new Date());
msg.setRecipients(Message.RecipientType.TO,
Expand Down