|
|
|
@ -28,6 +28,13 @@ import static de.srsoftware.widerhall.data.User.PERMISSION_ADMIN;
@@ -28,6 +28,13 @@ import static de.srsoftware.widerhall.data.User.PERMISSION_ADMIN;
|
|
|
|
|
* this class encapsulates a MailingList db object |
|
|
|
|
*/ |
|
|
|
|
public class MailingList implements MessageHandler { |
|
|
|
|
public static final String KEY_FORWARD_FROM = "forward_from"; |
|
|
|
|
public static final String KEY_FORWARD_ATTACHED = "forward_attached"; |
|
|
|
|
public static final String KEY_HIDE_RECEIVERS = "hide_receivers"; |
|
|
|
|
public static final String KEY_REPLY_TO_LIST = "reply_to_list"; |
|
|
|
|
public static final String KEY_OPEN_FOR_GUESTS = "open_for_guests"; |
|
|
|
|
public static final String KEY_OPEN_FOR_SUBSCRIBERS = "open_for_subscribers"; |
|
|
|
|
public static final String KEY_ARCHIVE = "archive"; |
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(MailingList.class); |
|
|
|
|
private static final String IMAP_HOST = "imap_host"; |
|
|
|
|
private static final String IMAP_PORT = "imap_port"; |
|
|
|
@ -47,10 +54,11 @@ public class MailingList implements MessageHandler {
@@ -47,10 +54,11 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
public static final int STATE_REPLY_TO_LIST = 32; // set REPLY TO field to list address?
|
|
|
|
|
public static final int STATE_OPEN_FOR_GUESTS = 64; // allow anyone to send via this list?
|
|
|
|
|
public static final int STATE_PUBLIC_ARCHIVE = 128; // save received messages in archive?
|
|
|
|
|
public static final int STATE_OPEN_FOR_MODS = 256; // allow mods to send via this list?
|
|
|
|
|
public static final int STATE_OPEN_FOR_SUBSCRIBERS = 256; // allow mods to send via this list?
|
|
|
|
|
public static final int STATE_MODS_CAN_CREATE_MODS = 512; // allow mods to make subscribers to mods?
|
|
|
|
|
private static final int VISIBLE = 1; |
|
|
|
|
private static final int HIDDEN = 0; |
|
|
|
|
private static final int DEFAULT_STATE = STATE_PENDING|STATE_HIDE_RECEIVERS|STATE_PUBLIC_ARCHIVE|STATE_OPEN_FOR_MODS; |
|
|
|
|
private static final int DEFAULT_STATE = STATE_PENDING|STATE_HIDE_RECEIVERS|STATE_PUBLIC_ARCHIVE; |
|
|
|
|
private static final String RETAINED_FOLDER = "retained"; |
|
|
|
|
private final String name; |
|
|
|
|
private final String email; |
|
|
|
@ -227,6 +235,20 @@ public class MailingList implements MessageHandler {
@@ -227,6 +235,20 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
return setFlag(STATE_HIDE_RECEIVERS,hide); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean isAllowedSender(String senderEmail){ |
|
|
|
|
if (senderEmail == null || senderEmail.isBlank()) return false; |
|
|
|
|
try { |
|
|
|
|
var user = User.load(senderEmail); |
|
|
|
|
if (user == null) return this.isOpenForGuests(); |
|
|
|
|
var member = ListMember.load(this,user); |
|
|
|
|
if (member == null) return this.isOpenForGuests(); |
|
|
|
|
if (member.isModerator()) return true; |
|
|
|
|
if (member.isSubscriber()) return this.isOpenForSubscribers(); |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
LOG.warn("Failed to load User for {}",senderEmail,e); |
|
|
|
|
} |
|
|
|
|
return this.isOpenForGuests(); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* test, whether the current ML is subscribable by a given user |
|
|
|
|
* @param user |
|
|
|
@ -244,6 +266,14 @@ public class MailingList implements MessageHandler {
@@ -244,6 +266,14 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean isOpenForGuests(){ |
|
|
|
|
return hasState(STATE_OPEN_FOR_GUESTS); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean isOpenForSubscribers(){ |
|
|
|
|
return hasState(STATE_OPEN_FOR_GUESTS|STATE_OPEN_FOR_SUBSCRIBERS); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Load a ML object by it's identifying email address. |
|
|
|
|
* This is a cached method: if the ML has been loaded before, the already-loaded object will be returned. |
|
|
|
@ -334,7 +364,7 @@ public class MailingList implements MessageHandler {
@@ -334,7 +364,7 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
Address from = message.getFrom()[0]; |
|
|
|
|
if (from instanceof InternetAddress internetAddress){ |
|
|
|
|
var senderEmail = ((InternetAddress) from).getAddress(); |
|
|
|
|
if (!hasState(STATE_OPEN_FOR_GUESTS) && !this.hashMember(senderEmail)){ |
|
|
|
|
if (!isAllowedSender(senderEmail)) { |
|
|
|
|
retainMessage(message); |
|
|
|
|
sentRetentionNotification(senderEmail); |
|
|
|
|
return; |
|
|
|
@ -344,10 +374,14 @@ public class MailingList implements MessageHandler {
@@ -344,10 +374,14 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
forward(message); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public MailingList open(boolean open) throws SQLException { |
|
|
|
|
public MailingList openForGuests(boolean open) throws SQLException { |
|
|
|
|
return setFlag(STATE_OPEN_FOR_GUESTS,open); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public MailingList openForSubscribers(boolean open) throws SQLException { |
|
|
|
|
return setFlag(STATE_OPEN_FOR_SUBSCRIBERS,open); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* provide the set of mailing lists that are publicy open to subscriptions |
|
|
|
|
* @return |
|
|
|
@ -490,7 +524,8 @@ public class MailingList implements MessageHandler {
@@ -490,7 +524,8 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
if (hasState(STATE_FORWARD_ATTACHED)) map.put("forward_attached",HIDDEN); |
|
|
|
|
if (hasState(STATE_HIDE_RECEIVERS)) map.put("hide_receivers",HIDDEN); |
|
|
|
|
if (hasState(STATE_REPLY_TO_LIST)) map.put("reply_to_list",HIDDEN); |
|
|
|
|
if (hasState(STATE_OPEN_FOR_GUESTS)) map.put("open",VISIBLE); |
|
|
|
|
if (hasState(STATE_OPEN_FOR_GUESTS)) map.put("open_for_guests",HIDDEN); |
|
|
|
|
if (hasState(STATE_OPEN_FOR_SUBSCRIBERS)) map.put("open_for_subscribers",HIDDEN); |
|
|
|
|
if (hasState(STATE_PUBLIC_ARCHIVE)) map.put("archive",VISIBLE); |
|
|
|
|
return map; |
|
|
|
|
} |
|
|
|
|