Browse Source

implemented rewriting of "… (from <sender>)" in subject, prepared open flag

drop_old_mail
Stephan Richter 3 years ago
parent
commit
5e01a64a64
  1. 2
      pom.xml
  2. 33
      src/main/java/de/srsoftware/widerhall/data/MailingList.java
  3. 7
      src/main/java/de/srsoftware/widerhall/mail/SmtpClient.java
  4. 1
      src/main/java/de/srsoftware/widerhall/web/Rest.java
  5. 9
      src/main/java/de/srsoftware/widerhall/web/Web.java
  6. 4
      static/templates/inspect.st
  7. 1
      static/templates/js.st

2
pom.xml

@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
<groupId>org.example</groupId>
<artifactId>Widerhall</artifactId>
<version>0.1.1</version>
<version>0.1.2</version>
<build>
<plugins>
<plugin>

33
src/main/java/de/srsoftware/widerhall/data/MailingList.java

@ -42,6 +42,7 @@ public class MailingList implements MessageHandler { @@ -42,6 +42,7 @@ public class MailingList implements MessageHandler {
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;
private static final int VISIBLE = 1;
private static final int HIDDEN = 0;
private static final int DEFAULT_STATE = STATE_PENDING|STATE_HIDE_RECEIVERS;
@ -134,7 +135,7 @@ public class MailingList implements MessageHandler { @@ -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);
if (enable) {
@ -142,6 +143,7 @@ public class MailingList implements MessageHandler { @@ -142,6 +143,7 @@ public class MailingList implements MessageHandler {
} else {
imap.stop();
}
return this;
}
private void forward(Message message) throws MessagingException {
@ -153,7 +155,7 @@ public class MailingList implements MessageHandler { @@ -153,7 +155,7 @@ public class MailingList implements MessageHandler {
.map(User::email)
.toList();
var subject = message.getSubject();
// TODO: remove '(from …)' from subject
if (!subject.contains(stamp())) subject = stamp()+" "+subject;
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);
@ -162,12 +164,12 @@ public class MailingList implements MessageHandler { @@ -162,12 +164,12 @@ public class MailingList implements MessageHandler {
}
}
public void forwardAttached(boolean forward) throws SQLException {
setFlag(STATE_FORWARD_ATTACHED,forward);
public MailingList forwardAttached(boolean forward) throws SQLException {
return setFlag(STATE_FORWARD_ATTACHED,forward);
}
public void forwardFrom(boolean forward) throws SQLException {
setFlag(STATE_FORWARD_FROM,forward);
public MailingList forwardFrom(boolean forward) throws SQLException {
return setFlag(STATE_FORWARD_FROM,forward);
}
@ -201,12 +203,12 @@ public class MailingList implements MessageHandler { @@ -201,12 +203,12 @@ public class MailingList implements MessageHandler {
return (state & test) > 0;
}
public void hide(boolean hide) throws SQLException {
setFlag(STATE_PUBLIC,!hide);
public MailingList hide(boolean hide) throws SQLException {
return setFlag(STATE_PUBLIC,!hide);
}
public void hideReceivers(boolean hide) throws SQLException {
setFlag(STATE_HIDE_RECEIVERS,hide);
public MailingList hideReceivers(boolean hide) throws SQLException {
return setFlag(STATE_HIDE_RECEIVERS,hide);
}
/**
@ -316,6 +318,10 @@ public class MailingList implements MessageHandler { @@ -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
* @return
@ -336,8 +342,8 @@ public class MailingList implements MessageHandler { @@ -336,8 +342,8 @@ public class MailingList implements MessageHandler {
return list;
}
public void replyToList(boolean on) throws SQLException {
setFlag(STATE_REPLY_TO_LIST,on);
public MailingList replyToList(boolean on) throws SQLException {
return setFlag(STATE_REPLY_TO_LIST,on);
}
@ -399,9 +405,10 @@ public class MailingList implements MessageHandler { @@ -399,9 +405,10 @@ public class MailingList implements MessageHandler {
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);
Database.open().update(TABLE_NAME).set(STATE,state).where(EMAIL, email()).compile().run();
return this;
}
public Map<String,Integer> stateMap(){

7
src/main/java/de/srsoftware/widerhall/mail/SmtpClient.java

@ -37,6 +37,13 @@ public class SmtpClient { @@ -37,6 +37,13 @@ public class SmtpClient {
MimeMessage forward = new MimeMessage(session);
var oldSender = message.getFrom()[0].toString();
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.setSubject(subject+" (from "+oldSender+")");
} else {

1
src/main/java/de/srsoftware/widerhall/web/Rest.java

@ -222,6 +222,7 @@ public class Rest extends HttpServlet { @@ -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_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);
return map;
}

9
src/main/java/de/srsoftware/widerhall/web/Web.java

@ -289,10 +289,11 @@ public class Web extends TemplateServlet { @@ -289,10 +289,11 @@ public class Web extends TemplateServlet {
if (!error){
try {
list.forwardFrom(Util.getCheckbox(req, "forward_from"));
list.forwardAttached(Util.getCheckbox(req, "forward_attached"));
list.hideReceivers(Util.getCheckbox(req, "hide_receivers"));
list.replyToList(Util.getCheckbox(req, "reply_to_list"));
list.forwardFrom(Util.getCheckbox(req, "forward_from"))
.forwardAttached(Util.getCheckbox(req, "forward_attached"))
.hideReceivers(Util.getCheckbox(req, "hide_receivers"))
.replyToList(Util.getCheckbox(req, "reply_to_list"))
.open(Util.getCheckbox(req,"open"));
data.put(NOTES,t("Sucessfully updated MailingList!"));
} catch (SQLException e){
LOG.warn("Failed to update MailingList:",e);

4
static/templates/inspect.st

@ -23,6 +23,10 @@ @@ -23,6 +23,10 @@
<input type="checkbox" name="reply_to_list">
Set list adddress in "ReplyTo" header
</label>
<label>
<input type="checkbox" name="open">
Allow non-members to send mails via list (Danger!)
</label>
<label>
<input type="checkbox" name="forward_attached">
Append original message as attachment

1
static/templates/js.st

@ -61,6 +61,7 @@ function showListDetail(data){ @@ -61,6 +61,7 @@ function showListDetail(data){
if (data.forward_attached) $('input[name="forward_attached"]').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.open) $('input[name="open"]').prop('checked',true);
}
function showListOfEditableLists(data){

Loading…
Cancel
Save