|
|
@ -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.mail.ImapClient; |
|
|
|
import de.srsoftware.widerhall.mail.SmtpClient; |
|
|
|
import de.srsoftware.widerhall.mail.SmtpClient; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
@ -34,10 +35,9 @@ public class MailingList { |
|
|
|
private static final int STATE_PUBLIC = 2; |
|
|
|
private static final int STATE_PUBLIC = 2; |
|
|
|
private final String name; |
|
|
|
private final String name; |
|
|
|
private final String email; |
|
|
|
private final String email; |
|
|
|
private final String imapPass, imapHost, imapUser; |
|
|
|
|
|
|
|
private final int imapPort; |
|
|
|
|
|
|
|
private int state; |
|
|
|
private int state; |
|
|
|
private final SmtpClient smtp; |
|
|
|
private final SmtpClient smtp; |
|
|
|
|
|
|
|
private final ImapClient imap; |
|
|
|
|
|
|
|
|
|
|
|
private static final HashMap<String,MailingList> lists = new HashMap<>(); |
|
|
|
private static final HashMap<String,MailingList> lists = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
@ -55,15 +55,12 @@ public class MailingList { |
|
|
|
* @param smtpPass |
|
|
|
* @param smtpPass |
|
|
|
* @param state |
|
|
|
* @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.email = email; |
|
|
|
this.name = name; |
|
|
|
this.name = name; |
|
|
|
this.imapHost = imapHost; |
|
|
|
|
|
|
|
this.imapPort = imapPort; |
|
|
|
|
|
|
|
this.imapUser = imapUser; |
|
|
|
|
|
|
|
this.imapPass = imapPass; |
|
|
|
|
|
|
|
this.state = state; |
|
|
|
this.state = state; |
|
|
|
this.smtp = new SmtpClient(smtpHost,smtpPort,smtpUser,smtpPass); |
|
|
|
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 |
|
|
|
* @return |
|
|
|
* @throws SQLException |
|
|
|
* @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 { |
|
|
|
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, smtpHost, smtpPort, smtpUser, smtpPass, STATE_PENDING).save(); |
|
|
|
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_PORT).append(" ").append(INT).append(", ") |
|
|
|
.append(IMAP_USER).append(" ").append(VARCHAR).append(", ") |
|
|
|
.append(IMAP_USER).append(" ").append(VARCHAR).append(", ") |
|
|
|
.append(IMAP_PASS).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_HOST).append(" ").append(VARCHAR).append(", ") |
|
|
|
.append(SMTP_PORT).append(" ").append(INT).append(", ") |
|
|
|
.append(SMTP_PORT).append(" ").append(INT).append(", ") |
|
|
|
.append(SMTP_USER).append(" ").append(VARCHAR).append(", ") |
|
|
|
.append(SMTP_USER).append(" ").append(VARCHAR).append(", ") |
|
|
@ -168,6 +166,7 @@ public class MailingList { |
|
|
|
rs.getInt(IMAP_PORT), |
|
|
|
rs.getInt(IMAP_PORT), |
|
|
|
rs.getString(IMAP_USER), |
|
|
|
rs.getString(IMAP_USER), |
|
|
|
rs.getString(IMAP_PASS), |
|
|
|
rs.getString(IMAP_PASS), |
|
|
|
|
|
|
|
rs.getString(INBOX), |
|
|
|
rs.getString(SMTP_HOST), |
|
|
|
rs.getString(SMTP_HOST), |
|
|
|
rs.getInt(SMTP_PORT), |
|
|
|
rs.getInt(SMTP_PORT), |
|
|
|
rs.getString(SMTP_USER), |
|
|
|
rs.getString(SMTP_USER), |
|
|
@ -241,12 +240,14 @@ public class MailingList { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Map<String, Object> safeMap() { |
|
|
|
public Map<String, Object> safeMap() { |
|
|
|
var map = minimalMap(); |
|
|
|
var map = minimalMap(); |
|
|
|
if (imapHost != null) map.put(IMAP_HOST, imapHost); |
|
|
|
if (imap.host() != null) map.put(IMAP_HOST, imap.host()); |
|
|
|
if (imapPort != 0) map.put(IMAP_PORT, imapPort); |
|
|
|
if (imap.port() != 0) map.put(IMAP_PORT, imap.port()); |
|
|
|
if (imapUser != null) map.put(IMAP_USER, imapUser); |
|
|
|
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.host() != null) map.put(SMTP_HOST, smtp.host()); |
|
|
|
if (smtp.port() != 0) map.put(SMTP_PORT, smtp.port()); |
|
|
|
if (smtp.port() != 0) map.put(SMTP_PORT, smtp.port()); |
|
|
|
if (smtp.username() != null) map.put(SMTP_USER, smtp.username()); |
|
|
|
if (smtp.username() != null) map.put(SMTP_USER, smtp.username()); |
|
|
|
|
|
|
|
map.put(STATE,stateString(state)); |
|
|
|
return map; |
|
|
|
return map; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -261,10 +262,11 @@ public class MailingList { |
|
|
|
.insertInto(TABLE_NAME) |
|
|
|
.insertInto(TABLE_NAME) |
|
|
|
.set(EMAIL, email) |
|
|
|
.set(EMAIL, email) |
|
|
|
.set(NAME, name) |
|
|
|
.set(NAME, name) |
|
|
|
.set(IMAP_HOST, imapHost) |
|
|
|
.set(IMAP_HOST, imap.host()) |
|
|
|
.set(IMAP_PORT, imapPort) |
|
|
|
.set(IMAP_PORT, imap.port()) |
|
|
|
.set(IMAP_USER, imapUser) |
|
|
|
.set(IMAP_USER, imap.username()) |
|
|
|
.set(IMAP_PASS, imapPass) |
|
|
|
.set(IMAP_PASS, imap.password()) |
|
|
|
|
|
|
|
.set(INBOX,imap.folderName()) |
|
|
|
.set(SMTP_HOST, smtp.host()) |
|
|
|
.set(SMTP_HOST, smtp.host()) |
|
|
|
.set(SMTP_PORT, smtp.port()) |
|
|
|
.set(SMTP_PORT, smtp.port()) |
|
|
|
.set(SMTP_USER, smtp.username()) |
|
|
|
.set(SMTP_USER, smtp.username()) |
|
|
|