working on mailing list options
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>org.example</groupId>
|
<groupId>org.example</groupId>
|
||||||
<artifactId>Widerhall</artifactId>
|
<artifactId>Widerhall</artifactId>
|
||||||
<version>0.0.17</version>
|
<version>0.0.18</version>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|||||||
@@ -114,4 +114,8 @@ public class Util {
|
|||||||
if (listEmail == null || listEmail.isBlank()) return null;
|
if (listEmail == null || listEmail.isBlank()) return null;
|
||||||
return MailingList.load(listEmail);
|
return MailingList.load(listEmail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean getCheckbox(HttpServletRequest req, String key) {
|
||||||
|
return "on".equals(req.getParameter(key));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ public class MailingList implements MessageHandler {
|
|||||||
private static final int STATE_ENABLED = 1;
|
private static final int STATE_ENABLED = 1;
|
||||||
private static final int STATE_PUBLIC = 2;
|
private static final int STATE_PUBLIC = 2;
|
||||||
public static final int STATE_FORWARD_FROM = 4;
|
public static final int STATE_FORWARD_FROM = 4;
|
||||||
|
public static final int STATE_FORWARD_ATTACHED = 8;
|
||||||
private static final int VISIBLE = 1;
|
private static final int VISIBLE = 1;
|
||||||
private static final int HIDDEN = 0;
|
private static final int HIDDEN = 0;
|
||||||
private final String name;
|
private final String name;
|
||||||
@@ -131,8 +132,7 @@ public class MailingList implements MessageHandler {
|
|||||||
|
|
||||||
|
|
||||||
public void enable(boolean enable) throws SQLException {
|
public void enable(boolean enable) throws SQLException {
|
||||||
state = enable ? state | STATE_ENABLED : state ^ (state & STATE_ENABLED);
|
setFlag(STATE_ENABLED,enable);
|
||||||
Database.open().update(TABLE_NAME).set(STATE,state).where(EMAIL, email()).compile().run();
|
|
||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
imap.start().addListener(this);
|
imap.start().addListener(this);
|
||||||
@@ -151,6 +151,15 @@ public class MailingList implements MessageHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void forwardAttached(boolean forward) throws SQLException {
|
||||||
|
setFlag(STATE_FORWARD_ATTACHED,forward);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void forwardFrom(boolean forward) throws SQLException {
|
||||||
|
setFlag(STATE_FORWARD_FROM,forward);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a mailing list object from a ResultSet.
|
* Create a mailing list object from a ResultSet.
|
||||||
* This is a cached method: if the ML has been loaded before, the already-loaded object will be returned.
|
* This is a cached method: if the ML has been loaded before, the already-loaded object will be returned.
|
||||||
@@ -182,8 +191,7 @@ public class MailingList implements MessageHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void hide(boolean hide) throws SQLException {
|
public void hide(boolean hide) throws SQLException {
|
||||||
state = hide ? state ^ (state & STATE_PUBLIC) : state | STATE_PUBLIC;
|
setFlag(STATE_PUBLIC,!hide);
|
||||||
Database.open().update(TABLE_NAME).set(STATE,state).where(EMAIL, email()).compile().run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -362,6 +370,11 @@ public class MailingList implements MessageHandler {
|
|||||||
smtp.login().send(email(),name(),user.email(),subject,text);
|
smtp.login().send(email(),name(),user.email(),subject,text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setFlag(int flag, boolean on) throws SQLException {
|
||||||
|
state = on ? state | flag : state ^ (state & flag);
|
||||||
|
Database.open().update(TABLE_NAME).set(STATE,state).where(EMAIL, email()).compile().run();
|
||||||
|
}
|
||||||
|
|
||||||
public Map<String,Integer> stateMap(){
|
public Map<String,Integer> stateMap(){
|
||||||
var map = new HashMap<String,Integer>();
|
var map = new HashMap<String,Integer>();
|
||||||
if (hasState(STATE_ENABLED)) map.put("enabled",VISIBLE);
|
if (hasState(STATE_ENABLED)) map.put("enabled",VISIBLE);
|
||||||
|
|||||||
@@ -219,6 +219,7 @@ public class Rest extends HttpServlet {
|
|||||||
if (list == null) return Map.of(ERROR,t("Mailinglist {} unknown",list.email()));
|
if (list == null) return Map.of(ERROR,t("Mailinglist {} unknown",list.email()));
|
||||||
var map = new HashMap<>();
|
var map = new HashMap<>();
|
||||||
if (list.hasState(MailingList.STATE_FORWARD_FROM)) map.put("forward_from",true);
|
if (list.hasState(MailingList.STATE_FORWARD_FROM)) map.put("forward_from",true);
|
||||||
|
if (list.hasState(MailingList.STATE_FORWARD_ATTACHED)) map.put("forward_attached",true);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import de.srsoftware.widerhall.Util;
|
|||||||
import de.srsoftware.widerhall.data.ListMember;
|
import de.srsoftware.widerhall.data.ListMember;
|
||||||
import de.srsoftware.widerhall.data.MailingList;
|
import de.srsoftware.widerhall.data.MailingList;
|
||||||
import de.srsoftware.widerhall.data.User;
|
import de.srsoftware.widerhall.data.User;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -269,19 +270,37 @@ public class Web extends TemplateServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String inspect(HttpServletRequest req, HttpServletResponse resp) {
|
private String inspect(HttpServletRequest req, HttpServletResponse resp) {
|
||||||
var o = req.getSession().getAttribute(USER);
|
var user = Util.getUser(req);
|
||||||
if (!(o instanceof User user)) {
|
if (user == null) return redirectTo(LOGIN,resp);
|
||||||
return redirectTo(LOGIN,resp);
|
|
||||||
}
|
|
||||||
var post = req.getParameterMap();
|
|
||||||
var listEmail = req.getParameter(LIST);
|
|
||||||
var list = MailingList.load(listEmail);
|
|
||||||
if (list == null) return t("{} is does not denote a valid list",listEmail);
|
|
||||||
if (!list.mayBeAlteredBy(user)) {
|
|
||||||
|
|
||||||
|
var data = new HashMap<String,Object>();
|
||||||
|
var error = false;
|
||||||
|
|
||||||
|
var list = Util.getMailingList(req);
|
||||||
|
if (list == null) {
|
||||||
|
error = true;
|
||||||
|
data.put(ERROR, t("No valid mailing list provided!"));
|
||||||
|
} else data.put(LIST, list.email());
|
||||||
|
|
||||||
|
if (!error && !list.mayBeAlteredBy(user)) {
|
||||||
|
error = true;
|
||||||
|
data.put(ERROR,t("You are not allowed to alter this list!"));
|
||||||
}
|
}
|
||||||
LOG.debug("POST: {}",post);
|
|
||||||
return null;
|
if (!error){
|
||||||
|
var dummy = req.getParameterMap();
|
||||||
|
try {
|
||||||
|
list.forwardFrom(Util.getCheckbox(req, "forward_from"));
|
||||||
|
list.forwardAttached(Util.getCheckbox(req, "forward_attached"));
|
||||||
|
data.put(NOTES,t("Sucessfully updated MailingList!"));
|
||||||
|
} catch (SQLException e){
|
||||||
|
LOG.warn("Failed to update MailingList:",e);
|
||||||
|
data.put(ERROR,t("Failed to update MailingList!"));
|
||||||
|
}
|
||||||
|
LOG.debug("params: {}",dummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
return loadTemplate(INSPECT,data,resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,10 @@
|
|||||||
<input type="checkbox" name="forward_from">
|
<input type="checkbox" name="forward_from">
|
||||||
Forward using original sender
|
Forward using original sender
|
||||||
</label>
|
</label>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="forward_attached">
|
||||||
|
Append original message as attachment
|
||||||
|
</label>
|
||||||
<button type="submit">Save</button>
|
<button type="submit">Save</button>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ function showList(listEmail){
|
|||||||
|
|
||||||
function showListDetail(data){
|
function showListDetail(data){
|
||||||
console.log(data);
|
console.log(data);
|
||||||
|
if (data.forward_from) $('input[name="forward_from"]').prop('checked',true);
|
||||||
|
if (data.forward_attached) $('input[name="forward_attached"]').prop('checked',true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function showListOfEditableLists(data){
|
function showListOfEditableLists(data){
|
||||||
|
|||||||
Reference in New Issue
Block a user