diff --git a/src/de/p1st/exec_notify/execNotify.py b/src/de/p1st/exec_notify/execNotify.py index 6b38ebd..afc8a7c 100755 --- a/src/de/p1st/exec_notify/execNotify.py +++ b/src/de/p1st/exec_notify/execNotify.py @@ -38,9 +38,7 @@ def executeCommand(command: List) -> int: print(BODY) if exitCode != 0: - hostname = socket.gethostname() - - SUBJECT = f'{hostname} | {str(command)}' + SUBJECT = f'{socket.gethostname()} | {str(command)}' mail.sendMailOrWriteToFile(SUBJECT=SUBJECT, BODY=BODY) return exitCode diff --git a/src/de/p1st/exec_notify/lib/mail.py b/src/de/p1st/exec_notify/lib/mail.py index bd181e0..035d1d9 100644 --- a/src/de/p1st/exec_notify/lib/mail.py +++ b/src/de/p1st/exec_notify/lib/mail.py @@ -6,7 +6,7 @@ import socket from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart -from de.p1st.exec_notify.lib import config +from de.p1st.exec_notify.lib import config, util def sendMailOrWriteToFile(SUBJECT: str, BODY: str, informAboutLocalMail: bool = True): @@ -65,13 +65,23 @@ def saveMail(SUBJECT: str, BODY: str): mailDir = config.getMailDir() mailFile = mailDir.joinpath(timeStr) + prefix='┃ ' + mailStr = f'┏{"━"*19}\n' \ + f'┣╸Date:\n' \ + f'{util.appendLinePrefix(prefix, timeStr)}\n' \ + f'┣╸Subject:\n' \ + f'{util.appendLinePrefix(prefix, SUBJECT)}\n' \ + f'┣╸Body:\n' \ + f'{util.appendLinePrefix(prefix, BODY)}\n' \ + f'┗{"━"*19}' + try: # create parent directory if not existent mailDir.mkdir(parents=True, exist_ok=True) # append to file; create file if not existent with open(mailFile, "a") as f: - f.write(f'{"=" * 20}\n=== date ===\n{timeStr}\n=== subject ===\n{SUBJECT}\n=== body ===\n{BODY}\n') + f.write(mailStr) except Exception as e: print(f'execNotify>> Could not write to file: {e}', file=sys.stderr) diff --git a/src/de/p1st/exec_notify/notify.py b/src/de/p1st/exec_notify/notify.py index 453cffc..96f7700 100755 --- a/src/de/p1st/exec_notify/notify.py +++ b/src/de/p1st/exec_notify/notify.py @@ -28,7 +28,7 @@ def main(): if subj is None: subj = 'notify' if BODY is None: - BODY = f'=== stdin ===\n{stdin.read()}' + BODY = stdin.read() SUBJECT = f'{hostname} | {subj}' print(BODY)