|
|
|
@ -1,9 +1,11 @@
@@ -1,9 +1,11 @@
|
|
|
|
|
package de.srsoftware.widerhall.data; |
|
|
|
|
|
|
|
|
|
import de.srsoftware.widerhall.Configuration; |
|
|
|
|
import de.srsoftware.widerhall.Util; |
|
|
|
|
import de.srsoftware.widerhall.mail.ImapClient; |
|
|
|
|
import de.srsoftware.widerhall.mail.MessageHandler; |
|
|
|
|
import de.srsoftware.widerhall.mail.SmtpClient; |
|
|
|
|
import org.json.simple.JSONObject; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
@ -13,7 +15,7 @@ import javax.mail.Message;
@@ -13,7 +15,7 @@ import javax.mail.Message;
|
|
|
|
|
import javax.mail.MessagingException; |
|
|
|
|
import javax.mail.internet.AddressException; |
|
|
|
|
import javax.mail.internet.InternetAddress; |
|
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
|
import java.io.*; |
|
|
|
|
import java.sql.ResultSet; |
|
|
|
|
import java.sql.SQLException; |
|
|
|
|
import java.util.*; |
|
|
|
@ -199,6 +201,16 @@ public class MailingList implements MessageHandler {
@@ -199,6 +201,16 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
return ml; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean hashMember(String senderEmail) { |
|
|
|
|
if (senderEmail == null) return false; |
|
|
|
|
try { |
|
|
|
|
return members().stream().map(ListMember::user).map(User::email).anyMatch(senderEmail::equals); |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
LOG.warn("hasMember() failded for {}",email(),e); |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean hasState(int test){ |
|
|
|
|
return (state & test) > 0; |
|
|
|
|
} |
|
|
|
@ -331,15 +343,7 @@ public class MailingList implements MessageHandler {
@@ -331,15 +343,7 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean hashMember(String senderEmail) { |
|
|
|
|
if (senderEmail == null) return false; |
|
|
|
|
try { |
|
|
|
|
return members().stream().map(ListMember::user).map(User::email).anyMatch(senderEmail::equals); |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
LOG.warn("hasMember() failded for {}",email(),e); |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public MailingList open(boolean open) throws SQLException { |
|
|
|
|
return setFlag(STATE_OPEN,open); |
|
|
|
@ -554,8 +558,41 @@ public class MailingList implements MessageHandler {
@@ -554,8 +558,41 @@ public class MailingList implements MessageHandler {
|
|
|
|
|
return "["+name+"]"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void storeMessage(Message message){ |
|
|
|
|
// TODO: implement
|
|
|
|
|
public static void startEnabled() { |
|
|
|
|
try { |
|
|
|
|
var rs = Database.open().select(TABLE_NAME).compile().exec(); |
|
|
|
|
while (rs.next()) { |
|
|
|
|
var list = MailingList.from(rs); |
|
|
|
|
if (list.hasState(STATE_ENABLED)) list.enable(true); |
|
|
|
|
} |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
LOG.debug("Failed to load MailingLists."); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void storeMessage(Message message) { |
|
|
|
|
try { |
|
|
|
|
var id = message.getHeader("Message-ID")[0].replace("<","").replace(">",""); |
|
|
|
|
var addr = ((InternetAddress)message.getFrom()[0]); |
|
|
|
|
var fromEmail = addr.getAddress(); |
|
|
|
|
var fromName = addr.getPersonal(); |
|
|
|
|
if (fromName == null || fromName.isBlank()) fromName = fromEmail.split("@")[0]+"@xxxxxx"; |
|
|
|
|
var subject = message.getSubject(); |
|
|
|
|
var text = Util.getText(message); |
|
|
|
|
JSONObject json = new JSONObject(); |
|
|
|
|
json.put("id",id); |
|
|
|
|
json.put("from",Map.of(EMAIL,fromEmail,NAME,fromName)); |
|
|
|
|
json.put(SUBJECT,subject); |
|
|
|
|
json.put(TEXT,text); |
|
|
|
|
|
|
|
|
|
File file = new File("/tmp/"+id+".json"); |
|
|
|
|
try (var fw = new FileWriter(file)) { |
|
|
|
|
json.writeJSONString(fw); |
|
|
|
|
fw.flush(); |
|
|
|
|
} |
|
|
|
|
} catch (MessagingException | IOException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|