From 5e01a64a6433c8c0481638240439d18592b2a2d2 Mon Sep 17 00:00:00 2001 From: Stephan Richter Date: Wed, 20 Apr 2022 13:34:55 +0200 Subject: [PATCH] =?UTF-8?q?implemented=20rewriting=20of=20"=E2=80=A6=20(fr?= =?UTF-8?q?om=20)"=20in=20subject,=20prepared=20open=20flag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../widerhall/data/MailingList.java | 33 +++++++++++-------- .../srsoftware/widerhall/mail/SmtpClient.java | 7 ++++ .../de/srsoftware/widerhall/web/Rest.java | 1 + .../java/de/srsoftware/widerhall/web/Web.java | 9 ++--- static/templates/inspect.st | 4 +++ static/templates/js.st | 1 + 7 files changed, 39 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index 180b480..efb6329 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.example Widerhall - 0.1.1 + 0.1.2 diff --git a/src/main/java/de/srsoftware/widerhall/data/MailingList.java b/src/main/java/de/srsoftware/widerhall/data/MailingList.java index ed71b03..aa2cd3a 100644 --- a/src/main/java/de/srsoftware/widerhall/data/MailingList.java +++ b/src/main/java/de/srsoftware/widerhall/data/MailingList.java @@ -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 { } - 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 { } else { imap.stop(); } + return this; } private void forward(Message message) throws MessagingException { @@ -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 { } } - 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 { 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 { } } + 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 { 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 { 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 stateMap(){ diff --git a/src/main/java/de/srsoftware/widerhall/mail/SmtpClient.java b/src/main/java/de/srsoftware/widerhall/mail/SmtpClient.java index ebc5cdc..2c0f875 100644 --- a/src/main/java/de/srsoftware/widerhall/mail/SmtpClient.java +++ b/src/main/java/de/srsoftware/widerhall/mail/SmtpClient.java @@ -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 { diff --git a/src/main/java/de/srsoftware/widerhall/web/Rest.java b/src/main/java/de/srsoftware/widerhall/web/Rest.java index c85cda0..b90367a 100644 --- a/src/main/java/de/srsoftware/widerhall/web/Rest.java +++ b/src/main/java/de/srsoftware/widerhall/web/Rest.java @@ -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; } diff --git a/src/main/java/de/srsoftware/widerhall/web/Web.java b/src/main/java/de/srsoftware/widerhall/web/Web.java index fe8d5d6..516b548 100644 --- a/src/main/java/de/srsoftware/widerhall/web/Web.java +++ b/src/main/java/de/srsoftware/widerhall/web/Web.java @@ -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); diff --git a/static/templates/inspect.st b/static/templates/inspect.st index a286c05..071fc44 100644 --- a/static/templates/inspect.st +++ b/static/templates/inspect.st @@ -23,6 +23,10 @@ Set list adddress in "ReplyTo" header +