Support for ignoring mails
This commit is contained in:
parent
ca8e8f4086
commit
6f1d58ef14
|
@ -1,10 +1,14 @@
|
|||
package io.gitlab.jfronny.gitea.helpdesk;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class Config {
|
||||
public Gitea gitea;
|
||||
public EMail email;
|
||||
public Database database;
|
||||
public Web web;
|
||||
public Ban ban;
|
||||
|
||||
public static class Gitea {
|
||||
public String host;
|
||||
|
@ -81,6 +85,14 @@ public class Config {
|
|||
}
|
||||
}
|
||||
|
||||
public static class Ban {
|
||||
public List<String> ignored;
|
||||
|
||||
public void validate() {
|
||||
if (ignored == null) ignored = new LinkedList<>();
|
||||
}
|
||||
}
|
||||
|
||||
public void validate() throws IllegalConfigException {
|
||||
if (gitea == null) throw new IllegalConfigException("Lacking gitea config");
|
||||
gitea.validate();
|
||||
|
@ -90,6 +102,8 @@ public class Config {
|
|||
database.validate();
|
||||
if (web == null) throw new IllegalConfigException("Lacking web in config");
|
||||
web.validate();
|
||||
if (ban == null) ban = new Ban();
|
||||
ban.validate();
|
||||
}
|
||||
|
||||
public static class IllegalConfigException extends Exception {
|
||||
|
|
|
@ -40,7 +40,7 @@ public class Main {
|
|||
try (DBInterface db = new DBInterface(config.database);
|
||||
MailInterface mail = new MailInterface(config.email);
|
||||
WebInterface web = new WebInterface(config.web, config.email.address, db, gitea)) {
|
||||
UpdateTask updateTask = new UpdateTask(db, mail, gitea, web);
|
||||
UpdateTask updateTask = new UpdateTask(db, mail, gitea, web, config.ban.ignored);
|
||||
while (true) {
|
||||
updateTask.run();
|
||||
Thread.sleep(config.email.waitTime * 1000);
|
||||
|
|
|
@ -13,8 +13,9 @@ import org.commonmark.renderer.html.HtmlRenderer;
|
|||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public record UpdateTask(DBInterface db, MailInterface mail, GiteaInterface gitea, WebInterface web) implements Runnable {
|
||||
public record UpdateTask(DBInterface db, MailInterface mail, GiteaInterface gitea, WebInterface web, List<String> ignored) implements Runnable {
|
||||
private static final Parser MARKDOWN_PARSER = Parser.builder().build();
|
||||
private static final HtmlRenderer MARKDOWN_RENDER = HtmlRenderer.builder().build();
|
||||
private static final String TEMPLATE = Main.getResource("/mail/template.html");
|
||||
|
@ -74,6 +75,10 @@ public record UpdateTask(DBInterface db, MailInterface mail, GiteaInterface gite
|
|||
try (WrappedMessageSet wms = mail.getInbox()) {
|
||||
for (WrappedMessage message : wms) {
|
||||
try {
|
||||
if (ignored.contains(message.getSender())) {
|
||||
message.delete();
|
||||
continue;
|
||||
}
|
||||
String[] args = message.getRecipientSubAddress().split("\\+");
|
||||
switch (args[0]) {
|
||||
case "create" -> {
|
||||
|
|
Loading…
Reference in New Issue