From bfac22dc79164bab10185188e12cee313ab96de9 Mon Sep 17 00:00:00 2001 From: James <31272717+gpd-pocket-hacker@users.noreply.github.com> Date: Mon, 9 Nov 2020 16:10:37 +0000 Subject: add email support --- rx.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'rx.c') diff --git a/rx.c b/rx.c index 09d969f..2087f99 100644 --- a/rx.c +++ b/rx.c @@ -5,17 +5,34 @@ #include #include "sia.h" +#include "email.h" -static void msg (char *account, char *event, char *ascii, int log) +static void msg (char *account, char *event, char *ascii, int log, const char *email) { + char body[256]; + char subject[256]; + + + snprintf (body, sizeof (body) - 1, "%s %64s %s", account, event, ascii); + body[sizeof (body) - 1] = 0; + if (log) - syslog (LOG_WARNING, "SIA: %s %64s %s", account, event, ascii); + syslog (LOG_WARNING, "SIA: %s", body); + + printf ("%s\n", body); + + + if (!email) return; + + if (strstr (body, "HEARTBT")) return; + + snprintf (subject, sizeof (subject) - 1, "Galaxy SIA from %s", account); - printf ("%s %64s %s\n", account, event, ascii); + send_email (email, subject, body); } -int new_block (int fd, SIA_Block *b, int log) +int new_block (int fd, SIA_Block *b, int log, const char *email) { static int have_ascii_messages = 0; /*SIA level 3 doesn't have ascii, SIA level 4 does */ @@ -39,7 +56,7 @@ int new_block (int fd, SIA_Block *b, int log) memcpy (event, b->data, len); event[len] = 0; - if (!have_ascii_messages) msg (account, event, "", log); + if (!have_ascii_messages) msg (account, event, "", log, email); break; @@ -48,7 +65,7 @@ int new_block (int fd, SIA_Block *b, int log) memcpy (ascii, b->data, len); ascii[len] = 0; - msg (account, event, ascii, log); + msg (account, event, ascii, log, email); break; } -- cgit v1.2.3