|
|
@ -7,6 +7,7 @@ import de.srsoftware.widerhall.mail.ProblemListener; |
|
|
|
import de.srsoftware.widerhall.mail.SmtpClient; |
|
|
|
import de.srsoftware.widerhall.mail.SmtpClient; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
import org.stringtemplate.v4.ST; |
|
|
|
|
|
|
|
|
|
|
|
import javax.mail.*; |
|
|
|
import javax.mail.*; |
|
|
|
import javax.mail.internet.AddressException; |
|
|
|
import javax.mail.internet.AddressException; |
|
|
@ -60,6 +61,7 @@ public class MailingList implements MessageHandler, ProblemListener { |
|
|
|
private static final int DEFAULT_STATE = STATE_PENDING|STATE_HIDE_RECEIVERS|STATE_PUBLIC_ARCHIVE; |
|
|
|
private static final int DEFAULT_STATE = STATE_PENDING|STATE_HIDE_RECEIVERS|STATE_PUBLIC_ARCHIVE; |
|
|
|
private static final String RETAINED_FOLDER = "retained"; |
|
|
|
private static final String RETAINED_FOLDER = "retained"; |
|
|
|
private static final String LAST_ERROR = "last_error"; |
|
|
|
private static final String LAST_ERROR = "last_error"; |
|
|
|
|
|
|
|
private static final String LIST_NAME = "list_name"; |
|
|
|
private String email, name, lastError; |
|
|
|
private String email, name, lastError; |
|
|
|
private int state; |
|
|
|
private int state; |
|
|
|
private SmtpClient smtp; |
|
|
|
private SmtpClient smtp; |
|
|
@ -532,21 +534,6 @@ public class MailingList implements MessageHandler, ProblemListener { |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* send an email to a potential subscriber asking for confirmation |
|
|
|
|
|
|
|
* @param user |
|
|
|
|
|
|
|
* @param token |
|
|
|
|
|
|
|
* @throws MessagingException |
|
|
|
|
|
|
|
* @throws UnsupportedEncodingException |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private void sendConfirmationRequest(User user, String token) throws MessagingException, UnsupportedEncodingException { |
|
|
|
|
|
|
|
var subject = t("Please confirm your list subscription"); |
|
|
|
|
|
|
|
var config = Configuration.instance(); |
|
|
|
|
|
|
|
var url = new StringBuilder(config.baseUrl()).append("/web/confirm?token=").append(token); |
|
|
|
|
|
|
|
var text = t("Please go to {} in order to complete your list subscription!",url); |
|
|
|
|
|
|
|
smtp.send(email(),name(),user.email(),subject,text); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void sentRetentionNotification(String senderEmail) { |
|
|
|
private void sentRetentionNotification(String senderEmail) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
var receivers = members() |
|
|
|
var receivers = members() |
|
|
@ -641,17 +628,24 @@ public class MailingList implements MessageHandler, ProblemListener { |
|
|
|
* @throws SQLException |
|
|
|
* @throws SQLException |
|
|
|
* @throws MessagingException |
|
|
|
* @throws MessagingException |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void requestSubscription(User user, boolean skipConfirmation) throws SQLException, MessagingException { |
|
|
|
public void requestSubscription(User user, boolean skipConfirmation, ST template) throws SQLException, MessagingException { |
|
|
|
var state = skipConfirmation ? ListMember.STATE_SUBSCRIBER : ListMember.STATE_AWAITING_CONFIRMATION; |
|
|
|
var state = skipConfirmation ? ListMember.STATE_SUBSCRIBER : ListMember.STATE_AWAITING_CONFIRMATION; |
|
|
|
var member = ListMember.create(this,user,state); |
|
|
|
var member = ListMember.create(this,user,state); |
|
|
|
if (skipConfirmation) return; |
|
|
|
if (skipConfirmation) return; |
|
|
|
try { |
|
|
|
try { |
|
|
|
sendConfirmationRequest(user, member.token()); |
|
|
|
var config = Configuration.instance(); |
|
|
|
|
|
|
|
var url = new StringBuilder(config.baseUrl()).append("/web/confirm?token=").append(member.token()).toString(); |
|
|
|
|
|
|
|
var subject = t("[{}] Please confirm your list subscription",name()); |
|
|
|
|
|
|
|
var text = template.add(URL,url).add(LIST_NAME,name()).render(); |
|
|
|
|
|
|
|
smtp.send(email(),name(),user.email(),subject,text); |
|
|
|
} catch (UnsupportedEncodingException e) { |
|
|
|
} catch (UnsupportedEncodingException e) { |
|
|
|
throw new MessagingException(t("Failed to send email to {}",user.email()),e); |
|
|
|
throw new MessagingException(t("Failed to send email to {}",user.email()),e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected SmtpClient smtp(){ |
|
|
|
|
|
|
|
return smtp; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String stamp() { |
|
|
|
private String stamp() { |
|
|
|
return "["+name+"]"; |
|
|
|
return "["+name+"]"; |
|
|
|