|
|
|
@ -40,6 +40,9 @@ public class MailingList implements MessageHandler {
@@ -40,6 +40,9 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
private static final int STATE_PENDING = 0; |
|
|
|
|
private static final int STATE_ENABLED = 1; |
|
|
|
|
private static final int STATE_PUBLIC = 2; |
|
|
|
|
public static final int STATE_FORWARD_FROM = 4; |
|
|
|
|
private static final int VISIBLE = 1; |
|
|
|
|
private static final int HIDDEN = 0; |
|
|
|
|
private final String name; |
|
|
|
|
private final String email; |
|
|
|
|
private int state; |
|
|
|
@ -143,7 +146,8 @@ public class MailingList implements MessageHandler {
@@ -143,7 +146,8 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
private void forward(Message message) throws MessagingException { |
|
|
|
|
try { |
|
|
|
|
var emails = members().stream().map(User::email).toList(); |
|
|
|
|
smtp.bccForward(email(),message,emails); |
|
|
|
|
String sender = (state & STATE_FORWARD_FROM) > 0 ? message.getFrom()[0].toString() : email(); |
|
|
|
|
smtp.bccForward(sender,message,emails); |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
LOG.error("Failed to read list members of {} from database. Cannot forward message!",email(),e); |
|
|
|
|
} |
|
|
|
@ -175,6 +179,10 @@ public class MailingList implements MessageHandler {
@@ -175,6 +179,10 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
return ml; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean hasState(int test){ |
|
|
|
|
return (state & test) > 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void hide(boolean hide) throws SQLException { |
|
|
|
|
state = hide ? state ^ (state & STATE_PUBLIC) : state | STATE_PUBLIC; |
|
|
|
|
Database.open().update(TABLE_NAME).set(STATE,state).where(EMAIL, email()).compile().run(); |
|
|
|
@ -231,7 +239,7 @@ public class MailingList implements MessageHandler {
@@ -231,7 +239,7 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
String[] parts = email.split("@", 2); |
|
|
|
|
map.put(EMAIL,Map.of(PREFIX,parts[0],DOMAIN,parts[1])); |
|
|
|
|
map.put(NAME, name); |
|
|
|
|
map.put(STATE, stateString(state)); |
|
|
|
|
map.put(STATE, stateMap()); |
|
|
|
|
return map; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -280,7 +288,7 @@ public class MailingList implements MessageHandler {
@@ -280,7 +288,7 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
if (smtp.host() != null) map.put(SMTP_HOST, smtp.host()); |
|
|
|
|
if (smtp.port() != 0) map.put(SMTP_PORT, smtp.port()); |
|
|
|
|
if (smtp.username() != null) map.put(SMTP_USER, smtp.username()); |
|
|
|
|
map.put(STATE,stateString(state)); |
|
|
|
|
map.put(STATE,stateMap()); |
|
|
|
|
return map; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -325,16 +333,12 @@ public class MailingList implements MessageHandler {
@@ -325,16 +333,12 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
smtp.login().send(email(),name(),user.email(),subject,text); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* convert state to readable string |
|
|
|
|
* @param state |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private static String stateString(int state) { |
|
|
|
|
var states = new ArrayList<String>(); |
|
|
|
|
states.add((state & STATE_ENABLED) == STATE_ENABLED ? "enabled" : "disabled"); |
|
|
|
|
states.add((state & STATE_PUBLIC) == STATE_PUBLIC ? "public" : "hidden"); |
|
|
|
|
return String.join(", ", states); |
|
|
|
|
public Map<String,Integer> stateMap(){ |
|
|
|
|
var map = new HashMap<String,Integer>(); |
|
|
|
|
if (hasState(STATE_ENABLED)) map.put("enabled",VISIBLE); |
|
|
|
|
if (hasState(STATE_PUBLIC)) map.put("public",VISIBLE); |
|
|
|
|
if (hasState(STATE_FORWARD_FROM)) map.put("original_from",HIDDEN); |
|
|
|
|
return map; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|