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