first version with working archive
This commit is contained in:
@@ -48,9 +48,10 @@ public class MailingList implements MessageHandler {
|
||||
public static final int STATE_HIDE_RECEIVERS = 16;
|
||||
public static final int STATE_REPLY_TO_LIST = 32;
|
||||
public static final int STATE_OPEN = 64;
|
||||
public static final int STATE_PUBLIC_ARCHIVE = 128;
|
||||
private static final int VISIBLE = 1;
|
||||
private static final int HIDDEN = 0;
|
||||
private static final int DEFAULT_STATE = STATE_PENDING|STATE_HIDE_RECEIVERS;
|
||||
private static final int DEFAULT_STATE = STATE_PENDING|STATE_HIDE_RECEIVERS|STATE_PUBLIC_ARCHIVE;
|
||||
private static final String RETAINED_FOLDER = "retained";
|
||||
private final String name;
|
||||
private final String email;
|
||||
@@ -82,6 +83,10 @@ public class MailingList implements MessageHandler {
|
||||
this.imap = new ImapClient(imapHost,imapPort,imapUser,imapPass,inbox);
|
||||
}
|
||||
|
||||
public MailingList archive(boolean enabled) throws SQLException {
|
||||
return setFlag(STATE_PUBLIC_ARCHIVE,enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* create a new ML object int the database
|
||||
* @param email
|
||||
@@ -336,15 +341,10 @@ public class MailingList implements MessageHandler {
|
||||
return;
|
||||
}
|
||||
}
|
||||
storeMessage(message);
|
||||
if (hasState(STATE_PUBLIC_ARCHIVE)) storeMessage(message);
|
||||
forward(message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public MailingList open(boolean open) throws SQLException {
|
||||
return setFlag(STATE_OPEN,open);
|
||||
}
|
||||
@@ -492,6 +492,7 @@ public class MailingList implements MessageHandler {
|
||||
if (hasState(STATE_HIDE_RECEIVERS)) map.put("hide_receivers",HIDDEN);
|
||||
if (hasState(STATE_REPLY_TO_LIST)) map.put("reply_to_list",HIDDEN);
|
||||
if (hasState(STATE_OPEN)) map.put("open",VISIBLE);
|
||||
if (hasState(STATE_PUBLIC_ARCHIVE)) map.put("archive",VISIBLE);
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -571,28 +572,7 @@ public class MailingList implements MessageHandler {
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
Post.create(this,message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user