diff --git a/doc/data structure.dia b/doc/data structure.dia
index ec54437..e887b44 100644
--- a/doc/data structure.dia
+++ b/doc/data structure.dia
@@ -868,13 +868,13 @@
-
+
-
+
-
+
@@ -900,7 +900,7 @@
-
+
@@ -913,13 +913,13 @@
-
+
-
+
-
+
@@ -945,7 +945,7 @@
-
+
@@ -958,13 +958,13 @@
-
+
-
+
-
+
@@ -990,7 +990,7 @@
-
+
@@ -1003,13 +1003,13 @@
-
+
-
+
-
+
@@ -1035,7 +1035,7 @@
-
+
@@ -1562,13 +1562,13 @@
-
+
-
+
-
+
@@ -1594,7 +1594,7 @@
-
+
@@ -1650,5 +1650,50 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #inbox#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/pom.xml b/pom.xml
index 3f3cf2f..8d6f2ca 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
org.example
Widerhall
- 0.0.13
+ 0.0.14
diff --git a/src/main/java/de/srsoftware/widerhall/Constants.java b/src/main/java/de/srsoftware/widerhall/Constants.java
index 1acd74d..22ea782 100644
--- a/src/main/java/de/srsoftware/widerhall/Constants.java
+++ b/src/main/java/de/srsoftware/widerhall/Constants.java
@@ -5,10 +5,10 @@ public class Constants {
public static final String BASE_URL = "base_url";
public static final String CONFIG = "configuration";
public static final String DB = "database";
+ public static final String DEFAULT_INBOX = "INBOX";
public static final String DOMAIN = "domain";
public static final String EMAIL = "email";
public static final String ERROR = "error";
- public static final String HOST = "host";
public static final String IMAPS = "imaps";
public static final String INBOX = "inbox";
public static final String INDEX = "index";
diff --git a/src/main/java/de/srsoftware/widerhall/data/MailingList.java b/src/main/java/de/srsoftware/widerhall/data/MailingList.java
index a13a38b..c6845e4 100644
--- a/src/main/java/de/srsoftware/widerhall/data/MailingList.java
+++ b/src/main/java/de/srsoftware/widerhall/data/MailingList.java
@@ -1,6 +1,7 @@
package de.srsoftware.widerhall.data;
import de.srsoftware.widerhall.Configuration;
+import de.srsoftware.widerhall.mail.ImapClient;
import de.srsoftware.widerhall.mail.SmtpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,10 +35,9 @@ public class MailingList {
private static final int STATE_PUBLIC = 2;
private final String name;
private final String email;
- private final String imapPass, imapHost, imapUser;
- private final int imapPort;
private int state;
private final SmtpClient smtp;
+ private final ImapClient imap;
private static final HashMap lists = new HashMap<>();
@@ -55,15 +55,12 @@ public class MailingList {
* @param smtpPass
* @param state
*/
- public MailingList(String email, String name, String imapHost, int imapPort, String imapUser, String imapPass, String smtpHost, int smtpPort, String smtpUser, String smtpPass, int state) {
+ public MailingList(String email, String name, String imapHost, int imapPort, String imapUser, String imapPass, String inbox, String smtpHost, int smtpPort, String smtpUser, String smtpPass, int state) {
this.email = email;
this.name = name;
- this.imapHost = imapHost;
- this.imapPort = imapPort;
- this.imapUser = imapUser;
- this.imapPass = imapPass;
this.state = state;
this.smtp = new SmtpClient(smtpHost,smtpPort,smtpUser,smtpPass);
+ this.imap = new ImapClient(imapHost,imapPort,imapUser,imapPass,inbox);
}
/**
@@ -81,8 +78,8 @@ public class MailingList {
* @return
* @throws SQLException
*/
- public static MailingList create(String email, String name, String imapHost, int imapPort, String imapUser, String imapPass, String smtpHost, int smtpPort, String smtpUser, String smtpPass) throws SQLException {
- return new MailingList(email, name, imapHost, imapPort, imapUser, imapPass, smtpHost, smtpPort, smtpUser, smtpPass, STATE_PENDING).save();
+ public static MailingList create(String email, String name, String imapHost, int imapPort, String imapUser, String imapPass, String inbox, String smtpHost, int smtpPort, String smtpUser, String smtpPass) throws SQLException {
+ return new MailingList(email, name, imapHost, imapPort, imapUser, imapPass, inbox, smtpHost, smtpPort, smtpUser, smtpPass, STATE_PENDING).save();
}
/**
@@ -99,6 +96,7 @@ public class MailingList {
.append(IMAP_PORT).append(" ").append(INT).append(", ")
.append(IMAP_USER).append(" ").append(VARCHAR).append(", ")
.append(IMAP_PASS).append(" ").append(VARCHAR).append(", ")
+ .append(INBOX).append(" ").append(VARCHAR).append(", ")
.append(SMTP_HOST).append(" ").append(VARCHAR).append(", ")
.append(SMTP_PORT).append(" ").append(INT).append(", ")
.append(SMTP_USER).append(" ").append(VARCHAR).append(", ")
@@ -168,6 +166,7 @@ public class MailingList {
rs.getInt(IMAP_PORT),
rs.getString(IMAP_USER),
rs.getString(IMAP_PASS),
+ rs.getString(INBOX),
rs.getString(SMTP_HOST),
rs.getInt(SMTP_PORT),
rs.getString(SMTP_USER),
@@ -241,12 +240,14 @@ public class MailingList {
*/
public Map safeMap() {
var map = minimalMap();
- if (imapHost != null) map.put(IMAP_HOST, imapHost);
- if (imapPort != 0) map.put(IMAP_PORT, imapPort);
- if (imapUser != null) map.put(IMAP_USER, imapUser);
+ if (imap.host() != null) map.put(IMAP_HOST, imap.host());
+ if (imap.port() != 0) map.put(IMAP_PORT, imap.port());
+ if (imap.username() != null) map.put(IMAP_USER, imap.username());
+ if (imap.folderName() != null) map.put(INBOX,imap.folderName());
if (smtp.host() != null) map.put(SMTP_HOST, smtp.host());
if (smtp.port() != 0) map.put(SMTP_PORT, smtp.port());
if (smtp.username() != null) map.put(SMTP_USER, smtp.username());
+ map.put(STATE,stateString(state));
return map;
}
@@ -261,10 +262,11 @@ public class MailingList {
.insertInto(TABLE_NAME)
.set(EMAIL, email)
.set(NAME, name)
- .set(IMAP_HOST, imapHost)
- .set(IMAP_PORT, imapPort)
- .set(IMAP_USER, imapUser)
- .set(IMAP_PASS, imapPass)
+ .set(IMAP_HOST, imap.host())
+ .set(IMAP_PORT, imap.port())
+ .set(IMAP_USER, imap.username())
+ .set(IMAP_PASS, imap.password())
+ .set(INBOX,imap.folderName())
.set(SMTP_HOST, smtp.host())
.set(SMTP_PORT, smtp.port())
.set(SMTP_USER, smtp.username())
diff --git a/src/main/java/de/srsoftware/widerhall/mail/Archiver.java b/src/main/java/de/srsoftware/widerhall/mail/Archiver.java
new file mode 100644
index 0000000..0bb8c07
--- /dev/null
+++ b/src/main/java/de/srsoftware/widerhall/mail/Archiver.java
@@ -0,0 +1,26 @@
+package de.srsoftware.widerhall.mail;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import java.io.UnsupportedEncodingException;
+
+public class Archiver implements MessageHandler {
+ private static final Logger LOG = LoggerFactory.getLogger(Archiver.class);
+ private final SmtpClient smtp;
+ private final String receiver,sender;
+
+ public Archiver(String host, int port, String username, String password, String sender, String receiver) {
+ this.sender = sender;
+ this.receiver = receiver;
+ SmtpClient smtp = new SmtpClient(host,port,username,password);
+ this.smtp = smtp;
+ }
+
+ @Override
+ public void onMessageReceived(Message message) throws MessagingException {
+ LOG.debug("storing {}",message.getSubject());
+ }
+}
diff --git a/src/main/java/de/srsoftware/widerhall/mail/Forwarder.java b/src/main/java/de/srsoftware/widerhall/mail/Forwarder.java
index 0cca288..4dca6bd 100644
--- a/src/main/java/de/srsoftware/widerhall/mail/Forwarder.java
+++ b/src/main/java/de/srsoftware/widerhall/mail/Forwarder.java
@@ -23,11 +23,5 @@ public class Forwarder implements MessageHandler {
@Override
public void onMessageReceived(Message message) throws MessagingException {
LOG.debug("forwarding {}",message.getSubject());
-
- try {
- smtp.send(sender,"Stephan Richter",receiver,"Info: "+message.getSubject(),"Neue Mail eingegangen!");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
}
}
diff --git a/src/main/java/de/srsoftware/widerhall/mail/ImapClient.java b/src/main/java/de/srsoftware/widerhall/mail/ImapClient.java
index 082402b..1a5c009 100644
--- a/src/main/java/de/srsoftware/widerhall/mail/ImapClient.java
+++ b/src/main/java/de/srsoftware/widerhall/mail/ImapClient.java
@@ -13,13 +13,12 @@ import java.util.Properties;
public class ImapClient {
private static final Logger LOG = LoggerFactory.getLogger(ImapClient.class);
- private final JSONObject config;
- private boolean stopped = false;
+ private final int port;
+ private final String host, username, password, folderName;
+ private boolean stopped = true;
private IMAPFolder inbox;
private HashSet listeners = new HashSet<>();
-
-
private class ListeningThread extends Thread {
private static final Logger LOG = LoggerFactory.getLogger(ListeningThread.class);
@@ -41,10 +40,6 @@ public class ImapClient {
}
private void openInbox() throws MessagingException {
- String host = (String) config.get(Constants.HOST);
- String username = (String) config.get(Constants.USER);
- String password = (String) config.get(Constants.PASSWORD);
- String folderName = (String) config.get(Constants.INBOX);
LOG.debug("Connecting and logging in…");
Properties props = imapProps();
Session session = Session.getInstance(props);
@@ -105,20 +100,50 @@ public class ImapClient {
}
}
}
- public ImapClient(JSONObject config){
- this.config = config;
+
+ public ImapClient(String host, int port, String username, String password, String folderName) {
+ this.host = host;
+ this.port = port;
+ this.username = username;
+ this.password = password;
+ this.folderName = folderName;
+ }
+
+
+ public ImapClient addListener(MessageHandler messageHandler) {
+ listeners.add(messageHandler);
+ return this;
+ }
+
+ public String host(){
+ return host;
+ }
+
+ public String username(){
+ return username;
+ }
+
+ public String password(){
+ return password;
+ }
+
+ public int port(){
+ return port;
+ }
+
+ public String folderName(){
+ return folderName;
}
public void start() {
+ stopped = false;
LOG.debug("Creating ListeningThread…");
new ListeningThread().start();
LOG.debug("Creating Heartbeat…");
new Heartbeat().start();
}
-
- public ImapClient addListener(MessageHandler messageHandler) {
- listeners.add(messageHandler);
- return this;
+ public void stop(){
+ stopped = true;
}
}
diff --git a/src/main/java/de/srsoftware/widerhall/web/Web.java b/src/main/java/de/srsoftware/widerhall/web/Web.java
index 8d6b861..a976397 100644
--- a/src/main/java/de/srsoftware/widerhall/web/Web.java
+++ b/src/main/java/de/srsoftware/widerhall/web/Web.java
@@ -1,25 +1,16 @@
package de.srsoftware.widerhall.web;
-import de.srsoftware.widerhall.Configuration;
-import de.srsoftware.widerhall.Constants;
import de.srsoftware.widerhall.Util;
import de.srsoftware.widerhall.data.ListMember;
import de.srsoftware.widerhall.data.MailingList;
import de.srsoftware.widerhall.data.User;
-import org.antlr.runtime.MismatchedTokenException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.stringtemplate.v4.STGroup;
-import org.stringtemplate.v4.STRawGroupDir;
import javax.mail.MessagingException;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import java.io.File;
import java.io.IOException;
-import java.nio.file.Files;
import java.security.InvalidKeyException;
import java.sql.SQLException;
import java.util.HashMap;
@@ -76,6 +67,8 @@ public class Web extends TemplateServlet {
data.put(IMAP_USER, imapUser);
var imapPass = req.getParameter(IMAP_PASS);
var smtpHost = req.getParameter(SMTP_HOST);
+ var inbox = req.getParameter(INBOX);
+ if (inbox == null) inbox = DEFAULT_INBOX;
data.put(SMTP_HOST, smtpHost);
var smtpUser = req.getParameter(SMTP_USER);
data.put(SMTP_USER, smtpUser);
@@ -125,7 +118,7 @@ public class Web extends TemplateServlet {
}
try {
- var list = MailingList.create(email, name, imapHost, imapPort, imapUser, imapPass, smtpHost, smtpPort, smtpUser, smtpPass);
+ var list = MailingList.create(email, name, imapHost, imapPort, imapUser, imapPass, inbox, smtpHost, smtpPort, smtpUser, smtpPass);
ListMember.create(list, user, ListMember.STATE_OWNER);
return redirectTo(INDEX, resp);
} catch (SQLException e) {
diff --git a/static/templates/add_list.st b/static/templates/add_list.st
index f855957..5b20816 100644
--- a/static/templates/add_list.st
+++ b/static/templates/add_list.st
@@ -43,6 +43,10 @@
Password
+