reroute outgoing mails to self as incoming mail

Signed-off-by: AGentooCat <agentoocat@mail.i2p>
This commit is contained in:
2025-06-09 08:08:53 +00:00
parent 2538e67fd2
commit 471d0c1677

View File

@ -422,7 +422,50 @@ incommitfail:
#undef RETPATH
}
int commit_outgoing_mail(struct Mail *mail, char *buf, char **tos, long tlen) {
return commit_mail(0, mail, buf, tos, tlen);
char **local_tos = NULL;
char **remote_tos = NULL;
long local_dests = 0, remote_dests = 0, loff = 0, roff = 0;
for (long i = 0; i < tlen; i++) {
char *addr = strchr(tos[i], '@') + 1;
if (!strcmp(addr, mehost->b32addr))
local_dests++;
else
remote_dests++;
}
if (local_dests > 0 && !(local_tos = malloc(local_dests * sizeof(char*))))
return -SQLITE_NOMEM;
if (remote_dests > 0 && !(remote_tos = malloc(remote_dests * sizeof(char*)))) {
if (local_tos) free(local_tos);
return -SQLITE_NOMEM;
}
for (long i = 0; i < tlen; i++) {
char *addr = strchr(tos[i], '@') + 1;
if (!strcmp(addr, mehost->b32addr))
local_tos[loff++] = tos[i];
else
remote_tos[roff++] = tos[i];
}
int com;
if (remote_tos) {
com = commit_mail(0, mail, buf, remote_tos, remote_dests);
if (com != SQLITE_OK) {
if (local_tos) free(local_tos);
if (remote_tos) free(remote_tos);
return com;
}
}
if (local_tos) {
com = commit_mail(1, mail, buf, local_tos, local_dests);
if (com != SQLITE_OK) {
if (local_tos) free(local_tos);
if (remote_tos) free(remote_tos);
return com;
}
}
if (local_tos) free(local_tos);
if (remote_tos) free(remote_tos);
return SQLITE_OK;
}
int commit_incoming_mail(struct Mail *mail, char *buf, char **tos, long tlen) {
return commit_mail(1, mail, buf, tos, tlen);