add generate_mail func

Signed-off-by: AGentooCat <agentoocat@mail.i2p>
This commit is contained in:
2025-06-08 21:17:09 +00:00
parent 49fb3db5b2
commit 5806ff63c6

View File

@ -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 <noreply@%s>", 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);