implemented rewriting of "… (from <sender>)" in subject, prepared open flag
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.1.1</version>
|
<version>0.1.2</version>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ public class MailingList implements MessageHandler {
|
|||||||
public static final int STATE_FORWARD_ATTACHED = 8;
|
public static final int STATE_FORWARD_ATTACHED = 8;
|
||||||
public static final int STATE_HIDE_RECEIVERS = 16;
|
public static final int STATE_HIDE_RECEIVERS = 16;
|
||||||
public static final int STATE_REPLY_TO_LIST = 32;
|
public static final int STATE_REPLY_TO_LIST = 32;
|
||||||
|
public static final int STATE_OPEN = 64;
|
||||||
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 static final int DEFAULT_STATE = STATE_PENDING|STATE_HIDE_RECEIVERS;
|
private static final int DEFAULT_STATE = STATE_PENDING|STATE_HIDE_RECEIVERS;
|
||||||
@@ -134,7 +135,7 @@ public class MailingList implements MessageHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void enable(boolean enable) throws SQLException {
|
public MailingList enable(boolean enable) throws SQLException {
|
||||||
setFlag(STATE_ENABLED,enable);
|
setFlag(STATE_ENABLED,enable);
|
||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
@@ -142,6 +143,7 @@ public class MailingList implements MessageHandler {
|
|||||||
} else {
|
} else {
|
||||||
imap.stop();
|
imap.stop();
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void forward(Message message) throws MessagingException {
|
private void forward(Message message) throws MessagingException {
|
||||||
@@ -153,7 +155,7 @@ public class MailingList implements MessageHandler {
|
|||||||
.map(User::email)
|
.map(User::email)
|
||||||
.toList();
|
.toList();
|
||||||
var subject = message.getSubject();
|
var subject = message.getSubject();
|
||||||
// TODO: remove '(from …)' from subject
|
|
||||||
if (!subject.contains(stamp())) subject = stamp()+" "+subject;
|
if (!subject.contains(stamp())) subject = stamp()+" "+subject;
|
||||||
var replyTo = (newSender == null && hasState(STATE_REPLY_TO_LIST)) ? email() : null;
|
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);
|
smtp.forward(newSender,receivers,message,subject,hasState(STATE_FORWARD_ATTACHED),hasState(STATE_HIDE_RECEIVERS),replyTo);
|
||||||
@@ -162,12 +164,12 @@ public class MailingList implements MessageHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void forwardAttached(boolean forward) throws SQLException {
|
public MailingList forwardAttached(boolean forward) throws SQLException {
|
||||||
setFlag(STATE_FORWARD_ATTACHED,forward);
|
return setFlag(STATE_FORWARD_ATTACHED,forward);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void forwardFrom(boolean forward) throws SQLException {
|
public MailingList forwardFrom(boolean forward) throws SQLException {
|
||||||
setFlag(STATE_FORWARD_FROM,forward);
|
return setFlag(STATE_FORWARD_FROM,forward);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -201,12 +203,12 @@ public class MailingList implements MessageHandler {
|
|||||||
return (state & test) > 0;
|
return (state & test) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hide(boolean hide) throws SQLException {
|
public MailingList hide(boolean hide) throws SQLException {
|
||||||
setFlag(STATE_PUBLIC,!hide);
|
return setFlag(STATE_PUBLIC,!hide);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hideReceivers(boolean hide) throws SQLException {
|
public MailingList hideReceivers(boolean hide) throws SQLException {
|
||||||
setFlag(STATE_HIDE_RECEIVERS,hide);
|
return setFlag(STATE_HIDE_RECEIVERS,hide);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -316,6 +318,10 @@ public class MailingList implements MessageHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MailingList open(boolean open) throws SQLException {
|
||||||
|
return setFlag(STATE_OPEN,open);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* provide the set of mailing lists that are publicy open to subscriptions
|
* provide the set of mailing lists that are publicy open to subscriptions
|
||||||
* @return
|
* @return
|
||||||
@@ -336,8 +342,8 @@ public class MailingList implements MessageHandler {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void replyToList(boolean on) throws SQLException {
|
public MailingList replyToList(boolean on) throws SQLException {
|
||||||
setFlag(STATE_REPLY_TO_LIST,on);
|
return setFlag(STATE_REPLY_TO_LIST,on);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -399,9 +405,10 @@ 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 {
|
private MailingList setFlag(int flag, boolean on) throws SQLException {
|
||||||
state = on ? state | flag : state ^ (state & flag);
|
state = on ? state | flag : state ^ (state & flag);
|
||||||
Database.open().update(TABLE_NAME).set(STATE,state).where(EMAIL, email()).compile().run();
|
Database.open().update(TABLE_NAME).set(STATE,state).where(EMAIL, email()).compile().run();
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String,Integer> stateMap(){
|
public Map<String,Integer> stateMap(){
|
||||||
|
|||||||
@@ -37,6 +37,13 @@ public class SmtpClient {
|
|||||||
MimeMessage forward = new MimeMessage(session);
|
MimeMessage forward = new MimeMessage(session);
|
||||||
var oldSender = message.getFrom()[0].toString();
|
var oldSender = message.getFrom()[0].toString();
|
||||||
if (newSender != null){
|
if (newSender != null){
|
||||||
|
var pos = subject.indexOf(" (from ");
|
||||||
|
while (pos > 0){
|
||||||
|
var end = subject.indexOf(')',pos);
|
||||||
|
if (end < pos) break;
|
||||||
|
subject = (subject.substring(0,pos)+subject.substring(end+1)).trim();
|
||||||
|
pos = subject.indexOf(" (from ");
|
||||||
|
}
|
||||||
forward.setFrom(newSender);
|
forward.setFrom(newSender);
|
||||||
forward.setSubject(subject+" (from "+oldSender+")");
|
forward.setSubject(subject+" (from "+oldSender+")");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -222,6 +222,7 @@ public class Rest extends HttpServlet {
|
|||||||
if (list.hasState(MailingList.STATE_FORWARD_ATTACHED)) map.put("forward_attached",true);
|
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_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_REPLY_TO_LIST)) map.put("reply_to_list",true);
|
||||||
|
if (list.hasState(MailingList.STATE_OPEN)) map.put("open",true);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -289,10 +289,11 @@ public class Web extends TemplateServlet {
|
|||||||
|
|
||||||
if (!error){
|
if (!error){
|
||||||
try {
|
try {
|
||||||
list.forwardFrom(Util.getCheckbox(req, "forward_from"));
|
list.forwardFrom(Util.getCheckbox(req, "forward_from"))
|
||||||
list.forwardAttached(Util.getCheckbox(req, "forward_attached"));
|
.forwardAttached(Util.getCheckbox(req, "forward_attached"))
|
||||||
list.hideReceivers(Util.getCheckbox(req, "hide_receivers"));
|
.hideReceivers(Util.getCheckbox(req, "hide_receivers"))
|
||||||
list.replyToList(Util.getCheckbox(req, "reply_to_list"));
|
.replyToList(Util.getCheckbox(req, "reply_to_list"))
|
||||||
|
.open(Util.getCheckbox(req,"open"));
|
||||||
data.put(NOTES,t("Sucessfully updated MailingList!"));
|
data.put(NOTES,t("Sucessfully updated MailingList!"));
|
||||||
} catch (SQLException e){
|
} catch (SQLException e){
|
||||||
LOG.warn("Failed to update MailingList:",e);
|
LOG.warn("Failed to update MailingList:",e);
|
||||||
|
|||||||
@@ -23,6 +23,10 @@
|
|||||||
<input type="checkbox" name="reply_to_list">
|
<input type="checkbox" name="reply_to_list">
|
||||||
Set list adddress in "ReplyTo" header
|
Set list adddress in "ReplyTo" header
|
||||||
</label>
|
</label>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="open">
|
||||||
|
Allow non-members to send mails via list (Danger!)
|
||||||
|
</label>
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" name="forward_attached">
|
<input type="checkbox" name="forward_attached">
|
||||||
Append original message as attachment
|
Append original message as attachment
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ function showListDetail(data){
|
|||||||
if (data.forward_attached) $('input[name="forward_attached"]').prop('checked',true);
|
if (data.forward_attached) $('input[name="forward_attached"]').prop('checked',true);
|
||||||
if (data.hide_receivers) $('input[name="hide_receivers"]').prop('checked',true);
|
if (data.hide_receivers) $('input[name="hide_receivers"]').prop('checked',true);
|
||||||
if (data.reply_to_list) $('input[name="reply_to_list"]').prop('checked',true);
|
if (data.reply_to_list) $('input[name="reply_to_list"]').prop('checked',true);
|
||||||
|
if (data.open) $('input[name="open"]').prop('checked',true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function showListOfEditableLists(data){
|
function showListOfEditableLists(data){
|
||||||
|
|||||||
Reference in New Issue
Block a user