|
|
|
@ -8,10 +8,7 @@ import org.slf4j.LoggerFactory;
@@ -8,10 +8,7 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
import javax.mail.MessagingException; |
|
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
|
import java.sql.SQLException; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
|
import static de.srsoftware.widerhall.Constants.*; |
|
|
|
|
import static de.srsoftware.widerhall.Util.t; |
|
|
|
@ -78,48 +75,28 @@ public class MailingList {
@@ -78,48 +75,28 @@ public class MailingList {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void enable(String listEmail, boolean enable) throws SQLException { |
|
|
|
|
// https://stackoverflow.com/questions/16440831/bitwise-xor-in-sqlite-bitwise-not-not-working-as-i-expect
|
|
|
|
|
String expression = enable ? "state = state | "+ STATE_ENABLED : "state = (~(state & "+ STATE_ENABLED +"))&(state|"+ STATE_ENABLED +")"; |
|
|
|
|
Database.open().update(TABLE_NAME,expression).where(EMAIL, listEmail).run(); |
|
|
|
|
Database.open() |
|
|
|
|
.update(TABLE_NAME) |
|
|
|
|
.set(STATE,enable ? STATE+" | "+ STATE_ENABLED : Database.xor(STATE,STATE_ENABLED)) |
|
|
|
|
.where(EMAIL, listEmail).run(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void hide(String listEmail, boolean hide) throws SQLException { |
|
|
|
|
// https://stackoverflow.com/questions/16440831/bitwise-xor-in-sqlite-bitwise-not-not-working-as-i-expect
|
|
|
|
|
String expression = hide ? "state = (~(state & "+ STATE_PUBLIC +"))&(state|"+ STATE_PUBLIC +")" : ("state = state | "+ STATE_PUBLIC); |
|
|
|
|
Database.open().update(TABLE_NAME,expression).where(EMAIL, listEmail).run(); |
|
|
|
|
Database.open() |
|
|
|
|
.update(TABLE_NAME) |
|
|
|
|
.set(STATE,hide ? STATE+" | "+ STATE_PUBLIC : Database.xor(STATE,STATE_PUBLIC)) |
|
|
|
|
.where(EMAIL, listEmail).run(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static boolean isOpen(String list) { |
|
|
|
|
return openLists().stream().filter(ml -> ml.email.equals(list)).count() > 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static List<MailingList> listsOf(User user) { |
|
|
|
|
|
|
|
|
|
List<String> keys = (user.is(ADMIN)) ? null : ListMember.listsOwnedBy(user); |
|
|
|
|
var list = new ArrayList<MailingList>(); |
|
|
|
|
if (keys != null && keys.isEmpty()) return list; |
|
|
|
|
try { |
|
|
|
|
Database.Request query = Database.open().select(TABLE_NAME); |
|
|
|
|
if (keys != null) query.where(EMAIL, keys); |
|
|
|
|
var rs = query.exec(); |
|
|
|
|
while (rs.next()) { |
|
|
|
|
var email = rs.getString(EMAIL); |
|
|
|
|
var name = rs.getString(NAME); |
|
|
|
|
var imapHost = rs.getString(IMAP_HOST); |
|
|
|
|
var imapPort = rs.getInt(IMAP_PORT); |
|
|
|
|
var imapUser = rs.getString(IMAP_USER); |
|
|
|
|
var imapPass = rs.getString(IMAP_PASS); |
|
|
|
|
var smtpHost = rs.getString(SMTP_HOST); |
|
|
|
|
var smtpPort = rs.getInt(SMTP_PORT); |
|
|
|
|
var smtpUser = rs.getString(SMTP_USER); |
|
|
|
|
var smtpPass = rs.getString(SMTP_PASS); |
|
|
|
|
var state = rs.getInt(STATE); |
|
|
|
|
list.add(new MailingList(email, name, imapHost, imapPort, imapUser, imapPass, smtpHost, smtpPort, smtpUser, smtpPass, state)); |
|
|
|
|
} |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
LOG.warn("Listing mailing lists failed: ", e); |
|
|
|
|
} |
|
|
|
|
public static Set<MailingList> listsOf(User user) { |
|
|
|
|
var list = openLists(); |
|
|
|
|
Set<String> keys = (user.is(ADMIN)) ? null : ListMember.listsOwnedBy(user); |
|
|
|
|
if (keys == null || keys.isEmpty()) return list; |
|
|
|
|
for (String key : keys) list.add(load(key)); |
|
|
|
|
return list; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -155,19 +132,17 @@ public class MailingList {
@@ -155,19 +132,17 @@ public class MailingList {
|
|
|
|
|
return name; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static List<MailingList> openLists() { |
|
|
|
|
var list = new ArrayList<MailingList>(); |
|
|
|
|
public static Set<MailingList> openLists() { |
|
|
|
|
var list = new HashSet<MailingList>(); |
|
|
|
|
try { |
|
|
|
|
var rs = Database.open() |
|
|
|
|
.select(TABLE_NAME,"*", "(" + STATE + " & " + STATE_PUBLIC + ") as test") |
|
|
|
|
.select(TABLE_NAME,EMAIL, "(" + STATE + " & " + STATE_PUBLIC + ") as test") |
|
|
|
|
.where("test", STATE_PUBLIC) |
|
|
|
|
.exec(); |
|
|
|
|
while (rs.next()) { |
|
|
|
|
var email = rs.getString(EMAIL); |
|
|
|
|
var name = rs.getString(NAME); |
|
|
|
|
var state = rs.getInt(STATE); |
|
|
|
|
list.add(new MailingList(email, name, null, 0, null, null, null, 0, null, null, state)); |
|
|
|
|
} |
|
|
|
|
var emails = new ArrayList<String>(); |
|
|
|
|
while (rs.next()) emails.add(rs.getString(EMAIL)); |
|
|
|
|
rs.close(); |
|
|
|
|
for (String email : emails) list.add(load(email)); |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
LOG.warn("Listing mailing lists failed: ", e); |
|
|
|
|
} |
|
|
|
|