Skip to content

Commit

Permalink
mod_sysop: Enhance test email command.
Browse files Browse the repository at this point in the history
Allow an optionally specified email address
to be the target of test emails.

Also ensure that when the original email
is attached to a delivery status notification,
it always ends in CR LF to prevent mangling
with the boundary.
  • Loading branch information
InterLinked1 committed Jan 5, 2024
1 parent fa6a8ea commit e0844e9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
10 changes: 7 additions & 3 deletions modules/mod_sysop.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,12 @@ static RWLIST_HEAD_STATIC(consoles, sysop_console);

static int cli_testemail(struct bbs_cli_args *a)
{
UNUSED(a);
return bbs_mail(0, NULL, NULL, NULL, "Test Email", "This is a test email.\r\n\t--LBBS");
const char *recipient = a->argc >= 2 ? a->argv[1] : NULL; /* Default to sysop */
return bbs_mail(0, recipient, NULL, NULL, "Test Email",
"This is a test message generated automatically by the LBBS bulletin board system.\r\n"
"You may be receiving this to test deliverability to your address after a previous delivery failure.\r\n"
"If you have any questions, please contact your sysop directly; please, do not respond to this message.\r\n"
"\t--LBBS\r\n"); /* Email should end with CR LF */
}

static int cli_mtrim(struct bbs_cli_args *a)
Expand Down Expand Up @@ -547,7 +551,7 @@ static int cli_consoles(struct bbs_cli_args *a)
static struct bbs_cli_entry cli_commands_sysop[] = {
BBS_CLI_COMMAND(cli_consoles, "consoles", 1, "List all sysop console sessions", NULL),
/* General */
BBS_CLI_COMMAND(cli_testemail, "testemail", 1, "Send test email to sysop", NULL),
BBS_CLI_COMMAND(cli_testemail, "testemail", 1, "Send test email to a recipient (default: sysop)", "testemail <address>"),
BBS_CLI_COMMAND(cli_mtrim, "mtrim", 1, "Manually release free memory at the top of the heap", NULL),
BBS_CLI_COMMAND(cli_assert, "assert", 1, "Manually trigger an assertion (WARNING: May abort BBS)", NULL),
BBS_CLI_COMMAND(cli_copyright, "copyright", 1, "Show copyright notice", NULL),
Expand Down
13 changes: 8 additions & 5 deletions nets/net_smtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1479,10 +1479,10 @@ static int any_failures(struct smtp_delivery_outcome **f, int n)
int smtp_dsn(const char *sendinghost, struct tm *arrival, const char *sender, int srcfd, int offset, size_t msglen, struct smtp_delivery_outcome **f, int n)
{
int i, res;
char tmpattach[256] = "/tmp/bouncemsgXXXXXX";
char tmpattach[32] = "/tmp/bouncemsgXXXXXX";
FILE *fp;
char bound[256];
char date[256], date2[256];
char date[50], date2[50];
struct tm tm;
size_t length;
time_t t = time(NULL);
Expand All @@ -1502,7 +1502,10 @@ int smtp_dsn(const char *sendinghost, struct tm *arrival, const char *sender, in
/* Format of the non-delivery report is defined in RFC 3461 Section 6 */

/* Generate headers */
strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", localtime_r(&t, &tm));
if (!strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", localtime_r(&t, &tm))) {
bbs_error("strftime failed\n");
date[0] = '\0';
}
fprintf(fp, "Date: %s\r\n", date);
fprintf(fp, "From: \"Mail Delivery Subsystem\" <mailer-daemon@%s>\r\n", bbs_hostname());
fprintf(fp, "Subject: %s\r\n", delivery_subject_name(f, n));
Expand Down Expand Up @@ -1601,11 +1604,11 @@ int smtp_dsn(const char *sendinghost, struct tm *arrival, const char *sender, in
bbs_copy_file(srcfd, fileno(fp), offset, (int) msglen);

fseek(fp, 0, SEEK_END);
fprintf(fp, "--%s\r\n", bound);
}

fflush(fp);
fprintf(fp, "--%s--\r\n", bound); /* Last one, so include 2 dashes after the boundary */
/* Include CR LF first, in case original message did not end with one, to prevent boundary from leaking onto last line of attachment. */
fprintf(fp, "\r\n--%s--\r\n", bound); /* Last one, so include 2 dashes after the boundary */
length = (size_t) ftell(fp);
fclose(fp);

Expand Down

0 comments on commit e0844e9

Please sign in to comment.