working on tests

This commit is contained in:
2022-04-22 09:35:26 +02:00
parent 655d285946
commit 5710a89b52
5 changed files with 178 additions and 22 deletions

View File

@@ -22,6 +22,7 @@ public class ListMember {
public static final int STATE_OWNER = 1;
public static final int STATE_SUBSCRIBER = 2;
public static final int STATE_AWAITING_CONFIRMATION = 4;
public static final int STATE_MODERATOR = 8;
private static final Logger LOG = LoggerFactory.getLogger(ListMember.class);
private static final String LIST_EMAIL = "list_email";
private static final String USER_EMAIL = "user_email";
@@ -135,11 +136,23 @@ public class ListMember {
return (state & testState) > 0;
}
public boolean isAwaiting(){
return hasState(STATE_AWAITING_CONFIRMATION);
}
public boolean isModerator() {
return hasState(STATE_OWNER|STATE_MODERATOR);
}
public boolean isOwner(){
return hasState(STATE_OWNER);
}
public boolean isSubscriber(){
return hasState(STATE_SUBSCRIBER|STATE_MODERATOR|STATE_OWNER);
}
/**
* return a set of list emails of MailingLists owned by the given user
* @param user
@@ -197,7 +210,7 @@ public class ListMember {
return Map.of(
EMAIL,user.email(),
NAME,user.name(),
STATE,ListMember.stateText(state)
STATE,stateText()
);
}
@@ -219,14 +232,14 @@ public class ListMember {
/**
* convert state flag to readable text
* @param state
* @return
*/
public static String stateText(int state) {
public String stateText() {
var words = new ArrayList<String>();
if ((state & STATE_OWNER) > 0) words.add("owner");
if ((state & STATE_SUBSCRIBER) > 0) words.add("subscriber");
if ((state & STATE_AWAITING_CONFIRMATION) > 0) words.add("awaiting confirmation");
if (isAwaiting()) words.add("awaiting confirmation");
if (isModerator()) words.add("moderator");
if (isOwner()) words.add("owner");
if (isSubscriber()) words.add("subscriber");
return String.join(", ",words);
}

View File

@@ -1,11 +1,9 @@
package de.srsoftware.widerhall.data;
import de.srsoftware.widerhall.Configuration;
import de.srsoftware.widerhall.Util;
import de.srsoftware.widerhall.mail.ImapClient;
import de.srsoftware.widerhall.mail.MessageHandler;
import de.srsoftware.widerhall.mail.SmtpClient;
import org.json.simple.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,17 +39,18 @@ public class MailingList implements MessageHandler {
private static final String SMTP_PASS = "smtp_pass";
public static final String TABLE_NAME = "Lists";
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;
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;
public static final int STATE_OPEN = 64;
public static final int STATE_PUBLIC_ARCHIVE = 128;
private static final int STATE_ENABLED = 1; // do we process incoming messages?
private static final int STATE_PUBLIC = 2; // can guests see this ML?
public static final int STATE_FORWARD_FROM = 4; // set original sender as FROM when forwarding?
public static final int STATE_FORWARD_ATTACHED = 8; // forward messages as attachment?
public static final int STATE_HIDE_RECEIVERS = 16; // send using BCC receivers
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?
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;
private static final int DEFAULT_STATE = STATE_PENDING|STATE_HIDE_RECEIVERS|STATE_PUBLIC_ARCHIVE|STATE_OPEN_FOR_MODS;
private static final String RETAINED_FOLDER = "retained";
private final String name;
private final String email;
@@ -335,7 +334,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) && !this.hashMember(senderEmail)){
if (!hasState(STATE_OPEN_FOR_GUESTS) && !this.hashMember(senderEmail)){
retainMessage(message);
sentRetentionNotification(senderEmail);
return;
@@ -346,7 +345,7 @@ public class MailingList implements MessageHandler {
}
public MailingList open(boolean open) throws SQLException {
return setFlag(STATE_OPEN,open);
return setFlag(STATE_OPEN_FOR_GUESTS,open);
}
/**
@@ -491,7 +490,7 @@ 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)) map.put("open",VISIBLE);
if (hasState(STATE_OPEN_FOR_GUESTS)) map.put("open",VISIBLE);
if (hasState(STATE_PUBLIC_ARCHIVE)) map.put("archive",VISIBLE);
return map;
}

View File

@@ -236,7 +236,7 @@ public class Rest extends HttpServlet {
if (list.hasState(MailingList.STATE_FORWARD_ATTACHED)) map.put("forward_attached",true);
if (list.hasState(MailingList.STATE_HIDE_RECEIVERS)) map.put("hide_receivers",true);
if (list.hasState(MailingList.STATE_REPLY_TO_LIST)) map.put("reply_to_list",true);
if (list.hasState(MailingList.STATE_OPEN)) map.put("open",true);
if (list.hasState(MailingList.STATE_OPEN_FOR_GUESTS)) map.put("open",true);
if (list.hasState(MailingList.STATE_PUBLIC_ARCHIVE)) map.put("archive",true);
return map;
}