|
|
|
@ -1,5 +1,6 @@
@@ -1,5 +1,6 @@
|
|
|
|
|
package de.srsoftware.widerhall.data; |
|
|
|
|
|
|
|
|
|
import de.srsoftware.widerhall.Configuration; |
|
|
|
|
import de.srsoftware.widerhall.Util; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
@ -11,8 +12,10 @@ import java.io.File;
@@ -11,8 +12,10 @@ import java.io.File;
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
|
import java.nio.file.Files; |
|
|
|
|
import java.sql.Array; |
|
|
|
|
import java.sql.ResultSet; |
|
|
|
|
import java.sql.SQLException; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.HashSet; |
|
|
|
|
import java.util.Map; |
|
|
|
@ -59,7 +62,9 @@ public class Post {
@@ -59,7 +62,9 @@ public class Post {
|
|
|
|
|
var time = message.getSentDate().getTime(); |
|
|
|
|
|
|
|
|
|
Post post = new Post(id,list,fromEmail,fromName,subject,time); |
|
|
|
|
Files.writeString(post.file().toPath(),text, StandardCharsets.UTF_8); |
|
|
|
|
var file = post.file(); |
|
|
|
|
file.getParentFile().mkdirs(); |
|
|
|
|
Files.writeString(file.toPath(),text, StandardCharsets.UTF_8); |
|
|
|
|
return post.save(); |
|
|
|
|
} catch (MessagingException | IOException | SQLException e) { |
|
|
|
|
LOG.warn("Failed to create post from {}",message); |
|
|
|
@ -93,10 +98,10 @@ public class Post {
@@ -93,10 +98,10 @@ public class Post {
|
|
|
|
|
return new File(filename); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static HashSet<Post> find(MailingList list) throws SQLException { |
|
|
|
|
var rs = Database.open().select(TABLE_NAME).where(LIST,list.email()).compile().exec(); |
|
|
|
|
public static ArrayList<Post> find(MailingList list) throws SQLException { |
|
|
|
|
var rs = Database.open().select(TABLE_NAME).where(LIST,list.email()).sort(DATE).compile().exec(); |
|
|
|
|
try { |
|
|
|
|
var result = new HashSet<Post>(); |
|
|
|
|
var result = new ArrayList<Post>(); |
|
|
|
|
while (rs.next()) result.add(Post.from(rs)); |
|
|
|
|
return result; |
|
|
|
|
} finally { |
|
|
|
@ -111,6 +116,7 @@ public class Post {
@@ -111,6 +116,7 @@ public class Post {
|
|
|
|
|
if (post == null) { |
|
|
|
|
var list = MailingList.load(rs.getString(LIST)); |
|
|
|
|
post = new Post(id, list, rs.getString(FROM_ADDR), rs.getString(FROM_NAME), rs.getString(SUBJECT), rs.getLong(DATE)); |
|
|
|
|
post.filename = rs.getString(FILE); |
|
|
|
|
cache.put(id,post); |
|
|
|
|
} |
|
|
|
|
return post; |
|
|
|
@ -122,7 +128,7 @@ public class Post {
@@ -122,7 +128,7 @@ public class Post {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String generateFilename() { |
|
|
|
|
return "/tmp/"+id+".json"; |
|
|
|
|
return Configuration.instance().archiveDir()+File.separator+id+".txt"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public String id() { |
|
|
|
|