|
|
|
@ -40,8 +40,11 @@ public class MailingList implements MessageHandler {
@@ -40,8 +40,11 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
private static final int STATE_PUBLIC = 2; |
|
|
|
|
public static final int STATE_FORWARD_FROM = 4; |
|
|
|
|
public static final int STATE_FORWARD_ATTACHED = 8; |
|
|
|
|
public static final int STATE_HIDE_RECEIVERS = 16; |
|
|
|
|
public static final int STATE_REPLY_TO_LIST = 32; |
|
|
|
|
private static final int VISIBLE = 1; |
|
|
|
|
private static final int HIDDEN = 0; |
|
|
|
|
private static final int DEFAULT_STATE = STATE_PENDING|STATE_HIDE_RECEIVERS; |
|
|
|
|
private final String name; |
|
|
|
|
private final String email; |
|
|
|
|
private int state; |
|
|
|
@ -88,7 +91,7 @@ public class MailingList implements MessageHandler {
@@ -88,7 +91,7 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
* @throws SQLException |
|
|
|
|
*/ |
|
|
|
|
public static MailingList create(String email, String name, String imapHost, int imapPort, String imapUser, String imapPass, String inbox, String smtpHost, int smtpPort, String smtpUser, String smtpPass) throws SQLException { |
|
|
|
|
return new MailingList(email, name, imapHost, imapPort, imapUser, imapPass, inbox, smtpHost, smtpPort, smtpUser, smtpPass, STATE_PENDING).save(); |
|
|
|
|
return new MailingList(email, name, imapHost, imapPort, imapUser, imapPass, inbox, smtpHost, smtpPort, smtpUser, smtpPass, DEFAULT_STATE).save(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -143,9 +146,17 @@ public class MailingList implements MessageHandler {
@@ -143,9 +146,17 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
|
|
|
|
|
private void forward(Message message) throws MessagingException { |
|
|
|
|
try { |
|
|
|
|
var emails = members().stream().map(ListMember::user).map(User::email).toList(); |
|
|
|
|
String sender = (state & STATE_FORWARD_FROM) > 0 ? message.getFrom()[0].toString() : email(); |
|
|
|
|
smtp.bccForward(sender,message,emails); |
|
|
|
|
String newSender = !hasState(STATE_FORWARD_FROM) ? email() : null; |
|
|
|
|
var receivers = members() |
|
|
|
|
.stream() |
|
|
|
|
.map(ListMember::user) |
|
|
|
|
.map(User::email) |
|
|
|
|
.toList(); |
|
|
|
|
var subject = message.getSubject(); |
|
|
|
|
// TODO: remove '(from …)' from subject
|
|
|
|
|
if (!subject.contains(stamp())) subject = stamp()+" "+subject; |
|
|
|
|
var replyTo = (newSender == null && hasState(STATE_REPLY_TO_LIST)) ? email() : null; |
|
|
|
|
smtp.forward(newSender,receivers,message,subject,hasState(STATE_FORWARD_ATTACHED),hasState(STATE_HIDE_RECEIVERS),replyTo); |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
LOG.error("Failed to read list members of {} from database. Cannot forward message!",email(),e); |
|
|
|
|
} |
|
|
|
@ -194,6 +205,10 @@ public class MailingList implements MessageHandler {
@@ -194,6 +205,10 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
setFlag(STATE_PUBLIC,!hide); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void hideReceivers(boolean hide) throws SQLException { |
|
|
|
|
setFlag(STATE_HIDE_RECEIVERS,hide); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* test, whether the current ML is subscribable by a given user |
|
|
|
|
* @param user |
|
|
|
@ -235,7 +250,7 @@ public class MailingList implements MessageHandler {
@@ -235,7 +250,7 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
public boolean mayBeAlteredBy(User user) { |
|
|
|
|
if (user.hashPermission(PERMISSION_ADMIN)) return true; |
|
|
|
|
try { |
|
|
|
|
if (ListMember.load(this,user).hasState(ListMember.STATE_OWNER)) return true; |
|
|
|
|
if (ListMember.load(this,user).isOwner()) return true; |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
LOG.debug("Error loading list member for ({}, {})",user.email(),email()); |
|
|
|
|
} |
|
|
|
@ -245,7 +260,7 @@ public class MailingList implements MessageHandler {
@@ -245,7 +260,7 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
public boolean mayBeTestedBy(User user) { |
|
|
|
|
if (user.hashPermission(PERMISSION_ADMIN)) return true; |
|
|
|
|
try { |
|
|
|
|
if (ListMember.load(this,user).hasState(ListMember.STATE_OWNER)) return true; |
|
|
|
|
if (ListMember.load(this,user).isOwner()) return true; |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
LOG.debug("Error loading list member for ({}, {})",user.email(),email()); |
|
|
|
|
} |
|
|
|
@ -259,7 +274,7 @@ public class MailingList implements MessageHandler {
@@ -259,7 +274,7 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
public boolean membersMayBeListedBy(User user) { |
|
|
|
|
if (user.hashPermission(PERMISSION_ADMIN)) return true; |
|
|
|
|
try { |
|
|
|
|
if (ListMember.load(this,user).hasState(ListMember.STATE_OWNER)) return true; |
|
|
|
|
if (ListMember.load(this,user).isOwner()) return true; |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
LOG.debug("Error loading list member for ({}, {})",user.email(),email()); |
|
|
|
|
} |
|
|
|
@ -287,8 +302,18 @@ public class MailingList implements MessageHandler {
@@ -287,8 +302,18 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
@Override |
|
|
|
|
public void onMessageReceived(Message message) throws MessagingException { |
|
|
|
|
LOG.debug("Message received: {}",message.getFrom()); |
|
|
|
|
storeMessage(message); |
|
|
|
|
forward(message); |
|
|
|
|
String subject = message.getSubject(); |
|
|
|
|
if (subject.toLowerCase().contains("undelivered")){ |
|
|
|
|
try { |
|
|
|
|
var receivers = members().stream().filter(ListMember::isOwner).map(ListMember::user).map(User::email).toList(); |
|
|
|
|
smtp.forward(email(), receivers, message, message.getSubject(), false,false,null); |
|
|
|
|
} catch (SQLException e){ |
|
|
|
|
LOG.error("Was not able to load members of {}; Non-Delivery notification dropped!",this.email(),e); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
storeMessage(message); |
|
|
|
|
forward(message); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -311,6 +336,10 @@ public class MailingList implements MessageHandler {
@@ -311,6 +336,10 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
return list; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void replyToList(boolean on) throws SQLException { |
|
|
|
|
setFlag(STATE_REPLY_TO_LIST,on); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* creates a map of the current ML containing all fields but passwords. |
|
|
|
@ -441,6 +470,11 @@ public class MailingList implements MessageHandler {
@@ -441,6 +470,11 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String stamp() { |
|
|
|
|
return "["+name+"]"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void storeMessage(Message message){ |
|
|
|
|
// TODO: implement
|
|
|
|
|
} |
|
|
|
|