|
|
@ -1,15 +1,21 @@ |
|
|
|
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.MessageHandler; |
|
|
|
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; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.mail.Message; |
|
|
|
import javax.mail.MessagingException; |
|
|
|
import javax.mail.MessagingException; |
|
|
|
|
|
|
|
import javax.mail.internet.AddressException; |
|
|
|
|
|
|
|
import javax.mail.internet.InternetAddress; |
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
import java.sql.ResultSet; |
|
|
|
import java.sql.ResultSet; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
|
|
|
|
import static de.srsoftware.widerhall.Constants.*; |
|
|
|
import static de.srsoftware.widerhall.Constants.*; |
|
|
|
import static de.srsoftware.widerhall.Util.t; |
|
|
|
import static de.srsoftware.widerhall.Util.t; |
|
|
@ -18,7 +24,7 @@ import static de.srsoftware.widerhall.data.User.PERMISSION_ADMIN; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* this class encapsulates a MailingList db object |
|
|
|
* this class encapsulates a MailingList db object |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class MailingList { |
|
|
|
public class MailingList implements MessageHandler { |
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(MailingList.class); |
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(MailingList.class); |
|
|
|
private static final String IMAP_HOST = "imap_host"; |
|
|
|
private static final String IMAP_HOST = "imap_host"; |
|
|
|
private static final String IMAP_PORT = "imap_port"; |
|
|
|
private static final String IMAP_PORT = "imap_port"; |
|
|
@ -32,14 +38,17 @@ public class MailingList { |
|
|
|
private static final int STATE_PENDING = 0; |
|
|
|
private static final int STATE_PENDING = 0; |
|
|
|
private static final int STATE_ENABLED = 1; |
|
|
|
private static final int STATE_ENABLED = 1; |
|
|
|
private static final int STATE_PUBLIC = 2; |
|
|
|
private static final int STATE_PUBLIC = 2; |
|
|
|
|
|
|
|
public static final int STATE_FORWARD_FROM = 4; |
|
|
|
|
|
|
|
public static final int STATE_FORWARD_ATTACHED = 8; |
|
|
|
|
|
|
|
private static final int VISIBLE = 1; |
|
|
|
|
|
|
|
private static final int HIDDEN = 0; |
|
|
|
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> cache = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* create a new ML object |
|
|
|
* create a new ML object |
|
|
@ -55,15 +64,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 +87,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 +105,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(", ") |
|
|
@ -108,49 +115,51 @@ public class MailingList { |
|
|
|
Database.open().query(sql).compile().run(); |
|
|
|
Database.open().query(sql).compile().run(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* load the set of mailing lists a given user is allowed to edit |
|
|
|
|
|
|
|
* @param user |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static Set<MailingList> editableBy(User user) { |
|
|
|
|
|
|
|
var list = new HashSet<MailingList>(); |
|
|
|
|
|
|
|
for (String key : ListMember.listsOwnedBy(user)) list.add(load(key)); |
|
|
|
|
|
|
|
return list; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String email() { |
|
|
|
public String email() { |
|
|
|
return email; |
|
|
|
return email; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void enable(boolean enable) throws SQLException { |
|
|
|
public void enable(boolean enable) throws SQLException { |
|
|
|
state = enable ? state | STATE_ENABLED : state ^ (state & STATE_ENABLED); |
|
|
|
setFlag(STATE_ENABLED,enable); |
|
|
|
Database.open().update(TABLE_NAME).set(STATE,state).where(EMAIL, email()).compile().run(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void hide(boolean hide) throws SQLException { |
|
|
|
if (enable) { |
|
|
|
state = hide ? state ^ (state & STATE_PUBLIC) : state | STATE_PUBLIC; |
|
|
|
imap.start().addListener(this); |
|
|
|
Database.open().update(TABLE_NAME).set(STATE,state).where(EMAIL, email()).compile().run(); |
|
|
|
} else { |
|
|
|
|
|
|
|
imap.stop(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
private void forward(Message message) throws MessagingException { |
|
|
|
* test, whether the current ML is subscribable by a given user |
|
|
|
|
|
|
|
* @param user |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public boolean isOpenFor(User user) { |
|
|
|
|
|
|
|
if ((state & STATE_PUBLIC) > 0) return true; // all users may subscribe public mailing lists
|
|
|
|
|
|
|
|
if (user == null) return false; |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
var member = ListMember.load(this,user); |
|
|
|
var emails = members().stream().map(ListMember::user).map(User::email).toList(); |
|
|
|
return member.hasState(ListMember.STATE_OWNER|ListMember.STATE_SUBSCRIBER); // owners may subscribe their own mailing lists
|
|
|
|
String sender = (state & STATE_FORWARD_FROM) > 0 ? message.getFrom()[0].toString() : email(); |
|
|
|
|
|
|
|
smtp.bccForward(sender,message,emails); |
|
|
|
} catch (SQLException e) { |
|
|
|
} catch (SQLException e) { |
|
|
|
LOG.warn("Konnte ListeMember nicht laden: ",e); |
|
|
|
LOG.error("Laden der Listen-Mitglieder von {} fehlgeschlagen. Nachricht kann nicht weitergeleitet werden!",email(),e); |
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
public void forwardAttached(boolean forward) throws SQLException { |
|
|
|
* load the set of mailing lists a given user is allowed to edit |
|
|
|
setFlag(STATE_FORWARD_ATTACHED,forward); |
|
|
|
* @param user |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static Set<MailingList> editableBy(User user) { |
|
|
|
|
|
|
|
var list = new HashSet<MailingList>(); |
|
|
|
|
|
|
|
for (String key : ListMember.listsOwnedBy(user)) list.add(load(key)); |
|
|
|
|
|
|
|
return list; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void forwardFrom(boolean forward) throws SQLException { |
|
|
|
|
|
|
|
setFlag(STATE_FORWARD_FROM,forward); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a mailing list object from a ResultSet. |
|
|
|
* Create a mailing list object from a ResultSet. |
|
|
|
* This is a cached method: if the ML has been loaded before, the already-loaded object will be returned. |
|
|
|
* This is a cached method: if the ML has been loaded before, the already-loaded object will be returned. |
|
|
@ -161,13 +170,14 @@ public class MailingList { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private static MailingList from(ResultSet rs) throws SQLException { |
|
|
|
private static MailingList from(ResultSet rs) throws SQLException { |
|
|
|
String email = rs.getString(EMAIL); |
|
|
|
String email = rs.getString(EMAIL); |
|
|
|
var ml = lists.get(email); |
|
|
|
var ml = cache.get(email); |
|
|
|
if (ml == null) lists.put(email,ml = new MailingList(rs.getString(EMAIL), |
|
|
|
if (ml == null) cache.put(email,ml = new MailingList(rs.getString(EMAIL), |
|
|
|
rs.getString(NAME), |
|
|
|
rs.getString(NAME), |
|
|
|
rs.getString(IMAP_HOST), |
|
|
|
rs.getString(IMAP_HOST), |
|
|
|
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), |
|
|
@ -176,6 +186,31 @@ public class MailingList { |
|
|
|
return ml; |
|
|
|
return ml; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean hasState(int test){ |
|
|
|
|
|
|
|
return (state & test) > 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void hide(boolean hide) throws SQLException { |
|
|
|
|
|
|
|
setFlag(STATE_PUBLIC,!hide); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* test, whether the current ML is subscribable by a given user |
|
|
|
|
|
|
|
* @param user |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public boolean isOpenFor(User user) { |
|
|
|
|
|
|
|
if ((state & STATE_PUBLIC) > 0) return true; // all users may subscribe public mailing lists
|
|
|
|
|
|
|
|
if (user == null) return false; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
var member = ListMember.load(this,user); |
|
|
|
|
|
|
|
return member.hasState(ListMember.STATE_OWNER|ListMember.STATE_SUBSCRIBER); // owners may subscribe their own mailing lists
|
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
|
|
|
LOG.warn("Konnte Listen-Mitglied nicht laden: ",e); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Load a ML object by it's identifying email address. |
|
|
|
* Load a ML object by it's identifying email address. |
|
|
|
* This is a cached method: if the ML has been loaded before, the already-loaded object will be returned. |
|
|
|
* This is a cached method: if the ML has been loaded before, the already-loaded object will be returned. |
|
|
@ -184,7 +219,7 @@ public class MailingList { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static MailingList load(String listEmail) { |
|
|
|
public static MailingList load(String listEmail) { |
|
|
|
if (listEmail == null) return null; |
|
|
|
if (listEmail == null) return null; |
|
|
|
var ml = lists.get(listEmail); |
|
|
|
var ml = cache.get(listEmail); |
|
|
|
if (ml == null) try { |
|
|
|
if (ml == null) try { |
|
|
|
var rs = Database.open() |
|
|
|
var rs = Database.open() |
|
|
|
.select(TABLE_NAME) |
|
|
|
.select(TABLE_NAME) |
|
|
@ -192,11 +227,46 @@ public class MailingList { |
|
|
|
.compile().exec(); |
|
|
|
.compile().exec(); |
|
|
|
if (rs.next()) ml = MailingList.from(rs); |
|
|
|
if (rs.next()) ml = MailingList.from(rs); |
|
|
|
} catch (SQLException e) { |
|
|
|
} catch (SQLException e) { |
|
|
|
LOG.debug("Konnte MailingList nicht laden: ",e); |
|
|
|
LOG.debug("Konnte Mailing-Liste nicht laden: ",e); |
|
|
|
} |
|
|
|
} |
|
|
|
return ml; |
|
|
|
return ml; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean mayBeAlteredBy(User user) { |
|
|
|
|
|
|
|
if (user.hashPermission(PERMISSION_ADMIN)) return true; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
if (ListMember.load(this,user).hasState(ListMember.STATE_OWNER)) return true; |
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
|
|
|
LOG.debug("Fehler beim Laden des Listenmitglieds für ({}, {})",user.email(),email()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean mayBeTestedBy(User user) { |
|
|
|
|
|
|
|
if (user.hashPermission(PERMISSION_ADMIN)) return true; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
if (ListMember.load(this,user).hasState(ListMember.STATE_OWNER)) return true; |
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
|
|
|
LOG.debug("Fehler beim Laden des Listenmitglieds für ({}, {})",user.email(),email()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Set<ListMember> members() throws SQLException { |
|
|
|
|
|
|
|
return ListMember.of(this); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean membersMayBeListedBy(User user) { |
|
|
|
|
|
|
|
if (user.hashPermission(PERMISSION_ADMIN)) return true; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
if (ListMember.load(this,user).hasState(ListMember.STATE_OWNER)) return true; |
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
|
|
|
LOG.debug("Fehler beim Laden des Listenmitglieds für ({}, {})",user.email(),email()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* creates a map from the current ML object containing only email and name of the ML |
|
|
|
* creates a map from the current ML object containing only email and name of the ML |
|
|
|
* @return |
|
|
|
* @return |
|
|
@ -206,7 +276,7 @@ public class MailingList { |
|
|
|
String[] parts = email.split("@", 2); |
|
|
|
String[] parts = email.split("@", 2); |
|
|
|
map.put(EMAIL,Map.of(PREFIX,parts[0],DOMAIN,parts[1])); |
|
|
|
map.put(EMAIL,Map.of(PREFIX,parts[0],DOMAIN,parts[1])); |
|
|
|
map.put(NAME, name); |
|
|
|
map.put(NAME, name); |
|
|
|
map.put(STATE, stateString(state)); |
|
|
|
map.put(STATE, stateMap()); |
|
|
|
return map; |
|
|
|
return map; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -214,6 +284,13 @@ public class MailingList { |
|
|
|
return name; |
|
|
|
return name; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onMessageReceived(Message message) throws MessagingException { |
|
|
|
|
|
|
|
LOG.debug("Nachricht empfangen: {}",message.getFrom()); |
|
|
|
|
|
|
|
storeMessage(message); |
|
|
|
|
|
|
|
forward(message); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* provide the set of mailing lists that are publicy open to subscriptions |
|
|
|
* provide the set of mailing lists that are publicy open to subscriptions |
|
|
|
* @return |
|
|
|
* @return |
|
|
@ -241,12 +318,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,stateMap()); |
|
|
|
return map; |
|
|
|
return map; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -261,10 +340,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()) |
|
|
@ -290,16 +370,17 @@ public class MailingList { |
|
|
|
smtp.login().send(email(),name(),user.email(),subject,text); |
|
|
|
smtp.login().send(email(),name(),user.email(),subject,text); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
private void setFlag(int flag, boolean on) throws SQLException { |
|
|
|
* convert state to readable string |
|
|
|
state = on ? state | flag : state ^ (state & flag); |
|
|
|
* @param state |
|
|
|
Database.open().update(TABLE_NAME).set(STATE,state).where(EMAIL, email()).compile().run(); |
|
|
|
* @return |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
private static String stateString(int state) { |
|
|
|
public Map<String,Integer> stateMap(){ |
|
|
|
var states = new ArrayList<String>(); |
|
|
|
var map = new HashMap<String,Integer>(); |
|
|
|
states.add((state & STATE_ENABLED) == STATE_ENABLED ? "enabled" : "disabled"); |
|
|
|
if (hasState(STATE_ENABLED)) map.put("enabled",VISIBLE); |
|
|
|
states.add((state & STATE_PUBLIC) == STATE_PUBLIC ? "public" : "hidden"); |
|
|
|
if (hasState(STATE_PUBLIC)) map.put("public",VISIBLE); |
|
|
|
return String.join(", ", states); |
|
|
|
if (hasState(STATE_FORWARD_FROM)) map.put("original_from",HIDDEN); |
|
|
|
|
|
|
|
return map; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -335,7 +416,7 @@ public class MailingList { |
|
|
|
rs.close(); |
|
|
|
rs.close(); |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} catch (SQLException e) { |
|
|
|
} catch (SQLException e) { |
|
|
|
LOG.warn("Lesen der für {} abbonnierbaren Mailinglisten fehlgeschlagen.",user,e); |
|
|
|
LOG.warn("Lesen der abbonnierbaren Mailinglisten von {} fehlgeschlagen.",user,e); |
|
|
|
return Set.of(); |
|
|
|
return Set.of(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -360,6 +441,10 @@ public class MailingList { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void storeMessage(Message message){ |
|
|
|
|
|
|
|
// TODO: implement
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* send a test email to the provided user |
|
|
|
* send a test email to the provided user |
|
|
@ -372,4 +457,13 @@ public class MailingList { |
|
|
|
var text = "Wenn Sie diese Nachricht empfangen haben, sind die SMTP-Einstellungen Ihrer Mailing-Liste korrekt."; |
|
|
|
var text = "Wenn Sie diese Nachricht empfangen haben, sind die SMTP-Einstellungen Ihrer Mailing-Liste korrekt."; |
|
|
|
smtp.login().send(email(),name(),user.email(),subject,text); |
|
|
|
smtp.login().send(email(),name(),user.email(),subject,text); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Stream<InternetAddress> toAddress(String email) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
return Arrays.asList(InternetAddress.parse(email)).stream(); |
|
|
|
|
|
|
|
} catch (AddressException e) { |
|
|
|
|
|
|
|
LOG.debug("Parsen von {} fehlgeschlagen",email,e); |
|
|
|
|
|
|
|
return new ArrayList<InternetAddress>().stream(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|