Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Commit

Permalink
NotificationMail: Add hiding-address option
Browse files Browse the repository at this point in the history
Yobi have hid users' email addresses when sent a notification email. But
this commit allows site Administrator set whether to hide recipients in
notification emails by application.notification.bymail.hideAddress.
  • Loading branch information
Yi EungJun committed Aug 21, 2014
1 parent 986253d commit 3ffd70f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
23 changes: 19 additions & 4 deletions app/models/NotificationMail.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import models.enumeration.UserState;
import models.resource.Resource;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.mail.HtmlEmail;
import org.joda.time.DateTime;
import org.jsoup.Jsoup;
Expand Down Expand Up @@ -53,6 +52,7 @@
@Entity
public class NotificationMail extends Model {
private static final long serialVersionUID = 1L;
static boolean hideAddress = true;

@Id
public Long id;
Expand All @@ -64,6 +64,9 @@ public class NotificationMail extends Model {
NotificationMail.class);

public static void onStart() {
hideAddress = play.Configuration.root().getBoolean(
"application.notification.bymail.hideAddress", true);

if (notificationEnabled()) {
NotificationMail.startSchedule();
}
Expand Down Expand Up @@ -179,11 +182,23 @@ private static void sendNotification(NotificationEvent event) {
final HtmlEmail email = new HtmlEmail();

try {
email.setFrom(Config.getEmailFromSmtp(), event.getSender().name);
email.addTo(Config.getEmailFromSmtp(), utils.Config.getSiteName());
if (hideAddress) {
email.setFrom(Config.getEmailFromSmtp(), event.getSender().name);
email.addTo(Config.getEmailFromSmtp(), utils.Config.getSiteName());
} else {
email.setFrom(event.getSender().email, event.getSender().name);
}

for (User receiver : usersByLang.get(langCode)) {
email.addBcc(receiver.email, receiver.name);
if (hideAddress) {
email.addBcc(receiver.email, receiver.name);
} else {
email.addTo(receiver.email, receiver.name);
}
}

if (email.getToAddresses().isEmpty()) {
continue;
}

Lang lang = Lang.apply(langCode);
Expand Down
2 changes: 2 additions & 0 deletions conf/application.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ smtp.archive.size = 5
application.notification.bymail.interval = 60s
# Sending a notification mail delays this seconds.
application.notification.bymail.delay = 180s
# Hide recipients of notification email by using bcc. (default: true)
application.notification.bymail.hideAddress = true
# A new event notification can be merged if possible with previous one which is
# not older than this seconds.
application.notification.draft-time = 30s
Expand Down

0 comments on commit 3ffd70f

Please sign in to comment.