update to files
This commit is contained in:
@@ -1,25 +1,40 @@
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
import os
|
||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||
|
||||
from src.ui.dialogs.mail_preview import Ui_Dialog
|
||||
|
||||
from src.ui.dialogs.Ui_mail_preview import Ui_eMailPreview as Ui_Dialog
|
||||
from omegaconf import OmegaConf
|
||||
config = OmegaConf.load("config.yaml")
|
||||
|
||||
class Mail_Dialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
def __init__(self, parent=None):
|
||||
def __init__(self, parent=None, app_id="", app_name="", app_subject="", prof_name="", data = None):
|
||||
super().__init__(parent)
|
||||
self.setupUi(self)
|
||||
self.appid = ""
|
||||
self.appid = app_id
|
||||
self.appname = app_name
|
||||
self.subject = app_subject
|
||||
self.profname = prof_name
|
||||
self.mail_data = ""
|
||||
self.data = None
|
||||
self.data = data
|
||||
self.buttonBox.accepted.connect(self.save_mail)
|
||||
self.comboBox.selec
|
||||
|
||||
def set_data(self, data: dict):
|
||||
self.prof_name.setText(data["prof_name"])
|
||||
self.mail_name.setText(data["mail_name"])
|
||||
# assign data["general"] to self.data
|
||||
self.data = data["general"]
|
||||
# def set_data(self, data: dict):
|
||||
# print(data)
|
||||
# self.prof_name.setText(data["prof_name"])
|
||||
# self.mail_name.setText(data["mail_name"])
|
||||
# # assign data["general"] to self.data
|
||||
# self.data = data["general"]
|
||||
|
||||
def get_greeting(self):
|
||||
if self.gender_male.isChecked():
|
||||
return "Sehr geehrter Herr"
|
||||
elif self.gender_female.isChecked():
|
||||
return "Sehr geehrte Frau"
|
||||
elif self.gender_non.isChecked():
|
||||
return "Guten Tag"
|
||||
|
||||
|
||||
def set_mail(self):
|
||||
email_template = self.comboBox.currentText()
|
||||
@@ -27,15 +42,14 @@ class Mail_Dialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
mail_template = f.read()
|
||||
email_header = email_template.split(".eml")[0]
|
||||
if "{AppNr}" in email_template:
|
||||
email_header = email_template.split(".eml")[0].format(AppNr=self.appid)
|
||||
email_header = email_template.split(".eml")[0]
|
||||
self.mail_header.setText(email_header)
|
||||
self.mail_data = mail_template.split("<html>")[0]
|
||||
mail_html = mail_template.split("<html>")[1]
|
||||
mail_html = "<html>" + mail_html
|
||||
print(self.data)
|
||||
Appname = self.data["Appname"]
|
||||
Appname = self.appname
|
||||
mail_html = mail_html.format(
|
||||
Profname=self.prof_name.text().split(" ")[-1], Appname=Appname
|
||||
Profname=self.prof_name.text().split(" ")[-1], Appname=Appname, AppNr=self.appid, AppSubject = self.subject,greeting = self.get_greeting()
|
||||
)
|
||||
|
||||
self.mail_body.setHtml(mail_html)
|
||||
@@ -46,14 +60,16 @@ class Mail_Dialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
mail_body = self.mail_body.toHtml()
|
||||
mail = self.mail_data + mail_body
|
||||
mail = mail.replace("Subject:", f"Subject: {mail_header}")
|
||||
directory = config["database"]["tempdir"]
|
||||
directory = directory.replace("~", str(os.path.expanduser("~")))
|
||||
with tempfile.NamedTemporaryFile(
|
||||
mode="w", delete=False, suffix=".eml", encoding="utf-8", dir="mails"
|
||||
mode="w", delete=False, suffix=".eml", encoding="utf-8", dir=directory
|
||||
) as f:
|
||||
f.write(mail)
|
||||
self.mail_path = f.name
|
||||
print(self.mail_path)
|
||||
# open the file using thunderbird
|
||||
subprocess.Popen(["thunderbird", f"{self.mail_path}"])
|
||||
subprocess.Popen([f"{self.mail_path}"])
|
||||
# delete the file
|
||||
# os.remove(self.mail_path)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user