Skip to content

Commit

Permalink
geändert: src/main/java/de/olech2412/mensahub/datadispatcher/email/M…
Browse files Browse the repository at this point in the history
…ailer.java
  • Loading branch information
olech2412 committed Sep 2, 2024
1 parent 1977d34 commit a16c566
Showing 1 changed file with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.*;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
Expand Down Expand Up @@ -101,6 +98,9 @@ protected PasswordAuthentication getPasswordAuthentication() {
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(emailTarget.getEmail()));

String msg = createEmailContent(menu, emailTarget, deactivateUrl, mensa, update);

// HTML-Datei speichern
saveEmailToFile(emailTarget, msg, mensa.getName(), update);
message.setSubject(getSubject(update, mensa.getName()));

MimeBodyPart mimeBodyPart = new MimeBodyPart();
Expand Down Expand Up @@ -473,4 +473,32 @@ private String createEmailCollabInfo(List<PredictionResult> predictions, String

return header + menuText + footer;
}

private void saveEmailToFile(MailUser emailTarget, String content, String mensaName, boolean update) throws IOException {
// Verzeichnispfad für das Archiv erstellen
String archiveDirPath = System.getProperty("user.home") + "/mensaHub/archiv";
File archiveDir = new File(archiveDirPath);

// Verzeichnis erstellen, falls es nicht existiert
if (!archiveDir.exists()) {
boolean createdArchiveDir = archiveDir.mkdirs();
if (createdArchiveDir) {
log.info("Archive directory created: {}", archiveDirPath);
} else {
log.error("Archive directory did not exist but cant be created: {}", archiveDirPath);
}
}

// Dateinamen generieren
String formattedDate = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy_MM_dd"));
String fileName = emailTarget.getEmail() + "_" + formattedDate + "_" + mensaName + (update ? "_update" : "_regular") + ".html";

// Pfad zur Datei
File file = new File(archiveDir, fileName);

// Dateiinhalt schreiben
try (FileWriter writer = new FileWriter(file)) {
writer.write(content);
}
}
}

0 comments on commit a16c566

Please sign in to comment.