Browse Source

bugfix: now loading value of hold_time column in List table

test
Stephan Richter 3 years ago
parent
commit
71cfeb4856
  1. 2
      pom.xml
  2. 7
      src/main/java/de/srsoftware/widerhall/Util.java
  3. 12
      src/main/java/de/srsoftware/widerhall/data/MailingList.java
  4. 2
      src/main/java/de/srsoftware/widerhall/web/Web.java

2
pom.xml

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

7
src/main/java/de/srsoftware/widerhall/Util.java

@ -16,6 +16,8 @@ import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -162,4 +164,9 @@ public class Util {
public static String dropEmail(String tx) { public static String dropEmail(String tx) {
return tx.replaceAll( "[.\\-\\w]+@[.\\-\\w]+", "[email_removed]"); return tx.replaceAll( "[.\\-\\w]+@[.\\-\\w]+", "[email_removed]");
} }
public static <T> T getNullable(ResultSet rs, String colName) throws SQLException {
final T val = (T) rs.getObject(colName);
return rs.wasNull() ? null : val;
}
} }

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

@ -1,6 +1,7 @@
package de.srsoftware.widerhall.data; package de.srsoftware.widerhall.data;
import de.srsoftware.widerhall.Configuration; import de.srsoftware.widerhall.Configuration;
import de.srsoftware.widerhall.Util;
import de.srsoftware.widerhall.mail.ImapClient; import de.srsoftware.widerhall.mail.ImapClient;
import de.srsoftware.widerhall.mail.MessageHandler; import de.srsoftware.widerhall.mail.MessageHandler;
import de.srsoftware.widerhall.mail.ProblemListener; import de.srsoftware.widerhall.mail.ProblemListener;
@ -87,12 +88,13 @@ public class MailingList implements MessageHandler, ProblemListener {
* @param smtpPass * @param smtpPass
* @param state * @param 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) { 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, Integer holdTime) {
this.email = email.toLowerCase(); this.email = email.toLowerCase();
this.name = name; this.name = name;
this.state = state; this.state = state;
this.smtp = new SmtpClient(smtpHost,smtpPort,smtpUser,smtpPass,email); this.smtp = new SmtpClient(smtpHost,smtpPort,smtpUser,smtpPass,email);
this.imap = new ImapClient(imapHost,imapPort,imapUser,imapPass,inbox,this); this.imap = new ImapClient(imapHost,imapPort,imapUser,imapPass,inbox,this);
this.holdTime = holdTime;
} }
public MailingList archive(boolean enabled) throws SQLException { public MailingList archive(boolean enabled) throws SQLException {
@ -123,8 +125,8 @@ public class MailingList implements MessageHandler, ProblemListener {
* @return * @return
* @throws SQLException * @throws SQLException
*/ */
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 { 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, Integer holdTime) throws SQLException {
return new MailingList(email, name, imapHost, imapPort, imapUser, imapPass, inbox, smtpHost, smtpPort, smtpUser, smtpPass, DEFAULT_STATE).save(); return new MailingList(email, name, imapHost, imapPort, imapUser, imapPass, inbox, smtpHost, smtpPort, smtpUser, smtpPass, DEFAULT_STATE, holdTime).save();
} }
public static void createHoldTimeColumn() throws SQLException { public static void createHoldTimeColumn() throws SQLException {
@ -232,7 +234,8 @@ public class MailingList implements MessageHandler, ProblemListener {
rs.getInt(SMTP_PORT), rs.getInt(SMTP_PORT),
rs.getString(SMTP_USER), rs.getString(SMTP_USER),
rs.getString(SMTP_PASS), rs.getString(SMTP_PASS),
rs.getInt(STATE))); rs.getInt(STATE),
Util.getNullable(rs,HOLD_TIME)));
return ml; return ml;
} }
@ -563,6 +566,7 @@ public class MailingList implements MessageHandler, ProblemListener {
.set(SMTP_USER, smtp.username()) .set(SMTP_USER, smtp.username())
.set(SMTP_PASS, smtp.password()) .set(SMTP_PASS, smtp.password())
.set(STATE, state) .set(STATE, state)
.set(HOLD_TIME,holdTime)
.compile() .compile()
.run(); .run();
return this; return this;

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

@ -125,7 +125,7 @@ public class Web extends TemplateServlet {
} }
try { try {
var list = MailingList.create(email, name, imapHost, imapPort, imapUser, imapPass, inbox, smtpHost, smtpPort, smtpUser, smtpPass); var list = MailingList.create(email, name, imapHost, imapPort, imapUser, imapPass, inbox, smtpHost, smtpPort, smtpUser, smtpPass, null);
ListMember.create(list, user, ListMember.STATE_OWNER); ListMember.create(list, user, ListMember.STATE_OWNER);
return redirectTo(ADMIN, resp); return redirectTo(ADMIN, resp);
} catch (SQLException e) { } catch (SQLException e) {

Loading…
Cancel
Save