From 5806ff63c6e28070c1b037852a77a0db661b3dfa Mon Sep 17 00:00:00 2001 From: AGentooCat Date: Sun, 8 Jun 2025 21:17:09 +0000 Subject: [PATCH] add generate_mail func Signed-off-by: AGentooCat --- src/mail.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/mail.c b/src/mail.c index 431acce..44b736d 100644 --- a/src/mail.c +++ b/src/mail.c @@ -749,6 +749,44 @@ wipemailfail: return 1; } +int generate_mail(char *user, char *subject, char *data) { + struct Header hdrs[] = { + { .key = "subject", .val = subject }, + { .key = "from", .val = NULL }, + { .key = "to", .val = NULL }, + { .key = "date", .val = NULL }, + }; + struct Mail mail = { + .from = NULL, + .hdrl = 4, + .hdrs = hdrs, + }; + char *to = NULL; + if (asprintf(&mail.from, "itoomail notification ", mehost->knownas) < 1) { +genmailfail: + logno(ERROR, "failed to generate mail entry for %s", user); + xfree(to); + xfree(mail.from); + return -1; + } + if (asprintf(&to, "%s@%s", user, mehost->knownas) < 1) + goto genmailfail; + + char tbuf[512]; + time_t ct1 = time(NULL); + struct tm *ct2 = gmtime(&ct1); + strftime(tbuf, 512, "%a, %d %b %Y %H:%M:%S %z", ct2); + + mail.hdrs[1].val = mail.from; + mail.hdrs[2].val = to; + mail.hdrs[3].val = tbuf; + if (commit_incoming_mail(&mail, data, &to, 1) < 0) + goto genmailfail; + xfree(to); + xfree(mail.from); + return 1; +} + int sendmsgid(char *msgid) { log(INFO, "will send mail %s...", msgid);