7 Commits

Author SHA1 Message Date
2beb145ac3 testing splitted readme
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2024-01-21 11:28:42 +01:00
0fa9796294 applied some sorting 2022-05-04 00:51:55 +02:00
aef476e384 bugfix 2022-05-04 00:37:41 +02:00
275f2a19b0 bugfix 2022-05-04 00:03:30 +02:00
6fc9d5d484 fixed debug output 2022-04-30 13:32:07 +02:00
71cfeb4856 bugfix: now loading value of hold_time column in List table 2022-04-30 13:28:46 +02:00
2508d5389c bugfix in debug output 2022-04-30 13:19:05 +02:00
9 changed files with 28 additions and 11 deletions

View File

@@ -1,3 +1,7 @@
| Welcome to Widerhall! | Willkommen bei Widerhall! |
|-----------------------|---------------------------|
| ## What is Widerhall | ## Was ist Widerhall ? |
# Welcome to Widerhall! # Welcome to Widerhall!
## What is Widerhall? ## What is Widerhall?

View File

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

View File

@@ -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;
}
} }

View File

@@ -69,9 +69,9 @@ public class ListMember {
} }
try { try {
if (member == null) { if (member == null) {
ListMember.create(list, moderator, ListMember.STATE_MODERATOR); ListMember.create(list, moderator, STATE_MODERATOR);
} else { } else {
member.setState(ListMember.STATE_MODERATOR); member.setState(Util.unset(member.state|STATE_MODERATOR,STATE_AWAITING_CONFIRMATION));
} }
} catch (SQLException e) { } catch (SQLException e) {
LOG.warn("Failed to make {} a moderator of {}",moderator.email(),list.email(),e); LOG.warn("Failed to make {} a moderator of {}",moderator.email(),list.email(),e);
@@ -212,7 +212,7 @@ public class ListMember {
if (member == null) { if (member == null) {
ListMember.create(list, moderator, ListMember.STATE_SUBSCRIBER); ListMember.create(list, moderator, ListMember.STATE_SUBSCRIBER);
} else { } else {
member.setState(ListMember.STATE_SUBSCRIBER); member.setState(Util.unset(member.state,STATE_MODERATOR));
} }
} catch (SQLException e) { } catch (SQLException e) {
LOG.warn("Failed to make {} a subscriber of {}",moderator.email(),list.email(),e); LOG.warn("Failed to make {} a subscriber of {}",moderator.email(),list.email(),e);

View File

@@ -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;

View File

@@ -175,6 +175,7 @@ public class User {
if (emails != null) query.where(EMAIL,emails); if (emails != null) query.where(EMAIL,emails);
var rs = query.compile().exec(); var rs = query.compile().exec();
while (rs.next()) userList.add(User.from(rs)); while (rs.next()) userList.add(User.from(rs));
Collections.sort(userList,(u1,u2)->u1.name.compareTo(u2.name));
return userList; return userList;
} }

View File

@@ -154,7 +154,7 @@ public class ImapClient {
Date receivedDate = message.getReceivedDate(); Date receivedDate = message.getReceivedDate();
Duration duration = Duration.between(receivedDate.toInstant(),now.toInstant()); Duration duration = Duration.between(receivedDate.toInstant(),now.toInstant());
var days = duration.toDays(); var days = duration.toDays();
LOG.info("Message {} is {} days old!"); LOG.info("Message {} is {} days old!",message.getSubject(),days);
if (days > holdTime){ if (days > holdTime){
Folder folder = message.getFolder(); Folder folder = message.getFolder();
if (!folder.isOpen()) folder.open(Folder.READ_WRITE); if (!folder.isOpen()) folder.open(Folder.READ_WRITE);

View File

@@ -167,7 +167,7 @@ public class Rest extends HttpServlet {
} }
break; break;
case LIST_MODERATED: case LIST_MODERATED:
json.put("lists", MailingList.moderatedBy(user).stream().map(MailingList::safeMap).toList()); json.put("lists", MailingList.moderatedBy(user).stream().sorted((l1,l2)->l1.name().compareTo(l2.name())).map(MailingList::safeMap).toList());
break; break;
case LIST_SUBSCRIBABLE: case LIST_SUBSCRIBABLE:
json.put("lists", MailingList.subscribable(user).stream().map(MailingList::minimalMap).toList()); json.put("lists", MailingList.subscribable(user).stream().map(MailingList::minimalMap).toList());
@@ -348,6 +348,7 @@ public class Rest extends HttpServlet {
if (!list.membersMayBeListedBy(user)) Map.of(ERROR,t("You are not allowed to list members of '{}'",list.email())); if (!list.membersMayBeListedBy(user)) Map.of(ERROR,t("You are not allowed to list members of '{}'",list.email()));
try { try {
var members = list.members() var members = list.members()
.sorted((m1,m2)->m1.user().name().compareTo(m2.user().name()))
.map(ListMember::safeMap) .map(ListMember::safeMap)
.toList(); .toList();
return Map.of(MEMBERS,members,LIST,list.minimalMap()); return Map.of(MEMBERS,members,LIST,list.minimalMap());

View File

@@ -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) {