Fossil SCM

New debugging option for /announce shows the SMTP transcript when the notification type is "relay".

drh 2025-04-07 16:03 trunk
Commit bbfca4cb6433df721d23440638e8bc61224f2379213e67c53bdb1e9b0513ab6d
1 file changed +45 -14
+45 -14
--- src/alerts.c
+++ src/alerts.c
@@ -634,18 +634,24 @@
634634
emailerGetSetting(p, &p->zCmd, "email-send-command");
635635
}else if( fossil_strcmp(p->zDest, "dir")==0 ){
636636
emailerGetSetting(p, &p->zDir, "email-send-dir");
637637
}else if( fossil_strcmp(p->zDest, "blob")==0 ){
638638
blob_init(&p->out, 0, 0);
639
- }else if( fossil_strcmp(p->zDest, "relay")==0 ){
639
+ }else if( fossil_strcmp(p->zDest, "relay")==0
640
+ || fossil_strcmp(p->zDest, "debug-relay")==0
641
+ ){
640642
const char *zRelay = 0;
641643
emailerGetSetting(p, &zRelay, "email-send-relayhost");
642644
if( zRelay ){
643645
u32 smtpFlags = SMTP_DIRECT;
644646
if( mFlags & ALERT_TRACE ) smtpFlags |= SMTP_TRACE_STDOUT;
647
+ blob_init(&p->out, 0, 0);
645648
p->pSmtp = smtp_session_new(domain_of_addr(p->zFrom), zRelay,
646649
smtpFlags, 0);
650
+ if( p->zDest[0]=='d' ){
651
+ smtp_session_config(p->pSmtp, SMTP_TRACE_BLOB, &p->out);
652
+ }
647653
smtp_client_startup(p->pSmtp);
648654
}
649655
}
650656
return p;
651657
}
@@ -3440,16 +3446,28 @@
34403446
char *zSubject = PT("subject");
34413447
int bAll = PB("all");
34423448
int bAA = PB("aa");
34433449
int bMods = PB("mods");
34443450
const char *zSub = db_get("email-subname", "[Fossil Repo]");
3445
- int bTest2 = fossil_strcmp(P("name"),"test2")==0;
3451
+ const char *zName = P("name"); /* Debugging options */
3452
+ const char *zDest = 0; /* How to send the announcement */
3453
+ int bTest = 0;
34463454
Blob hdr, body;
3455
+
3456
+ if( fossil_strcmp(zName, "test2")==0 ){
3457
+ bTest = 2;
3458
+ zDest = "blob";
3459
+ }else if( fossil_strcmp(zName, "test3")==0 ){
3460
+ bTest = 3;
3461
+ if( fossil_strcmp(db_get("email-send-method",""),"relay")==0 ){
3462
+ zDest = "debug-relay";
3463
+ }
3464
+ }
34473465
blob_init(&body, 0, 0);
34483466
blob_init(&hdr, 0, 0);
34493467
blob_appendf(&body, "%s", PT("msg")/*safe-for-%s*/);
3450
- pSender = alert_sender_new(bTest2 ? "blob" : 0, 0);
3468
+ pSender = alert_sender_new(zDest, 0);
34513469
if( zTo[0] ){
34523470
blob_appendf(&hdr, "To: <%s>\r\nSubject: %s %s\r\n", zTo, zSub, zSubject);
34533471
alert_send(pSender, &hdr, &body, 0);
34543472
}
34553473
if( bAll || bAA || bMods ){
@@ -3483,17 +3501,18 @@
34833501
}
34843502
alert_send(pSender, &hdr, &body, 0);
34853503
}
34863504
db_finalize(&q);
34873505
}
3488
- if( bTest2 ){
3506
+ if( bTest ){
34893507
/* If the URL is /announce/test2 instead of just /announce, then no
34903508
** email is actually sent. Instead, the text of the email that would
34913509
** have been sent is displayed in the result window. */
3492
- @ <pre style='border: 2px solid blue; padding: 1ex'>
3510
+ @ <pre style='border: 2px solid blue; padding: 1ex;'>
34933511
@ %h(blob_str(&pSender->out))
34943512
@ </pre>
3513
+ blob_reset(&pSender->out);
34953514
}
34963515
zErr = pSender->zErr;
34973516
pSender->zErr = 0;
34983517
alert_sender_free(pSender);
34993518
return zErr;
@@ -3509,24 +3528,31 @@
35093528
** also send a message to an arbitrary email address and/or to all
35103529
** subscribers regardless of whether or not they have elected to
35113530
** receive announcements.
35123531
*/
35133532
void announce_page(void){
3514
- const char *zAction = "announce"
3515
- /* Maintenance reminder: we need an explicit action=THIS_PAGE on the
3516
- ** form element to avoid that a URL arg of to=... passed to this
3517
- ** page ends up overwriting the form-posted "to" value. This
3518
- ** action value differs for the test1 request path.
3519
- */;
3520
-
3533
+ const char *zAction = "announce";
3534
+ const char *zName = PD("name","");
3535
+ /*
3536
+ ** Debugging Notes:
3537
+ **
3538
+ ** /announce/test1 -> Shows query parameter values
3539
+ ** /announce/test2 -> Shows the formatted message but does
3540
+ ** not send it.
3541
+ ** /announce/test3 -> Sends the message, but also shows
3542
+ ** the SMTP transcript.
3543
+ */
35213544
login_check_credentials();
35223545
if( !g.perm.Announce ){
35233546
login_needed(0);
35243547
return;
35253548
}
3549
+ if( !g.perm.Setup ){
3550
+ zName = 0; /* Disable debugging feature for non-admin users */
3551
+ }
35263552
style_set_current_feature("alerts");
3527
- if( fossil_strcmp(P("name"),"test1")==0 ){
3553
+ if( fossil_strcmp(zName,"test1")==0 ){
35283554
/* Visit the /announce/test1 page to see the CGI variables */
35293555
zAction = "announce/test1";
35303556
@ <p style='border: 1px solid black; padding: 1ex;'>
35313557
cgi_print_all(0, 0, 0);
35323558
@ </p>
@@ -3553,10 +3579,15 @@
35533579
return;
35543580
}
35553581
35563582
style_header("Send Announcement");
35573583
alert_submenu_common();
3584
+ if( fossil_strcmp(zName,"test2")==0 ){
3585
+ zAction = "announce/test2";
3586
+ }else if( fossil_strcmp(zName,"test3")==0 ){
3587
+ zAction = "announce/test3";
3588
+ }
35583589
@ <form method="POST" action="%R/%s(zAction)">
35593590
login_insert_csrf_secret();
35603591
@ <table class="subscribe">
35613592
if( g.perm.Admin ){
35623593
int aa = PB("aa");
@@ -3589,15 +3620,15 @@
35893620
@ <td><textarea name="msg" cols="80" rows="10" wrap="virtual">\
35903621
@ %h(PT("msg"))</textarea>
35913622
@ </tr>
35923623
@ <tr>
35933624
@ <td></td>
3594
- if( fossil_strcmp(P("name"),"test2")==0 ){
3625
+ if( fossil_strcmp(zName,"test2")==0 ){
35953626
@ <td><input type="submit" name="submit" value="Dry Run">
35963627
}else{
35973628
@ <td><input type="submit" name="submit" value="Send Message">
35983629
}
35993630
@ </tr>
36003631
@ </table>
36013632
@ </form>
36023633
style_finish_page();
36033634
}
36043635
--- src/alerts.c
+++ src/alerts.c
@@ -634,18 +634,24 @@
634 emailerGetSetting(p, &p->zCmd, "email-send-command");
635 }else if( fossil_strcmp(p->zDest, "dir")==0 ){
636 emailerGetSetting(p, &p->zDir, "email-send-dir");
637 }else if( fossil_strcmp(p->zDest, "blob")==0 ){
638 blob_init(&p->out, 0, 0);
639 }else if( fossil_strcmp(p->zDest, "relay")==0 ){
 
 
640 const char *zRelay = 0;
641 emailerGetSetting(p, &zRelay, "email-send-relayhost");
642 if( zRelay ){
643 u32 smtpFlags = SMTP_DIRECT;
644 if( mFlags & ALERT_TRACE ) smtpFlags |= SMTP_TRACE_STDOUT;
 
645 p->pSmtp = smtp_session_new(domain_of_addr(p->zFrom), zRelay,
646 smtpFlags, 0);
 
 
 
647 smtp_client_startup(p->pSmtp);
648 }
649 }
650 return p;
651 }
@@ -3440,16 +3446,28 @@
3440 char *zSubject = PT("subject");
3441 int bAll = PB("all");
3442 int bAA = PB("aa");
3443 int bMods = PB("mods");
3444 const char *zSub = db_get("email-subname", "[Fossil Repo]");
3445 int bTest2 = fossil_strcmp(P("name"),"test2")==0;
 
 
3446 Blob hdr, body;
 
 
 
 
 
 
 
 
 
 
3447 blob_init(&body, 0, 0);
3448 blob_init(&hdr, 0, 0);
3449 blob_appendf(&body, "%s", PT("msg")/*safe-for-%s*/);
3450 pSender = alert_sender_new(bTest2 ? "blob" : 0, 0);
3451 if( zTo[0] ){
3452 blob_appendf(&hdr, "To: <%s>\r\nSubject: %s %s\r\n", zTo, zSub, zSubject);
3453 alert_send(pSender, &hdr, &body, 0);
3454 }
3455 if( bAll || bAA || bMods ){
@@ -3483,17 +3501,18 @@
3483 }
3484 alert_send(pSender, &hdr, &body, 0);
3485 }
3486 db_finalize(&q);
3487 }
3488 if( bTest2 ){
3489 /* If the URL is /announce/test2 instead of just /announce, then no
3490 ** email is actually sent. Instead, the text of the email that would
3491 ** have been sent is displayed in the result window. */
3492 @ <pre style='border: 2px solid blue; padding: 1ex'>
3493 @ %h(blob_str(&pSender->out))
3494 @ </pre>
 
3495 }
3496 zErr = pSender->zErr;
3497 pSender->zErr = 0;
3498 alert_sender_free(pSender);
3499 return zErr;
@@ -3509,24 +3528,31 @@
3509 ** also send a message to an arbitrary email address and/or to all
3510 ** subscribers regardless of whether or not they have elected to
3511 ** receive announcements.
3512 */
3513 void announce_page(void){
3514 const char *zAction = "announce"
3515 /* Maintenance reminder: we need an explicit action=THIS_PAGE on the
3516 ** form element to avoid that a URL arg of to=... passed to this
3517 ** page ends up overwriting the form-posted "to" value. This
3518 ** action value differs for the test1 request path.
3519 */;
3520
 
 
 
 
3521 login_check_credentials();
3522 if( !g.perm.Announce ){
3523 login_needed(0);
3524 return;
3525 }
 
 
 
3526 style_set_current_feature("alerts");
3527 if( fossil_strcmp(P("name"),"test1")==0 ){
3528 /* Visit the /announce/test1 page to see the CGI variables */
3529 zAction = "announce/test1";
3530 @ <p style='border: 1px solid black; padding: 1ex;'>
3531 cgi_print_all(0, 0, 0);
3532 @ </p>
@@ -3553,10 +3579,15 @@
3553 return;
3554 }
3555
3556 style_header("Send Announcement");
3557 alert_submenu_common();
 
 
 
 
 
3558 @ <form method="POST" action="%R/%s(zAction)">
3559 login_insert_csrf_secret();
3560 @ <table class="subscribe">
3561 if( g.perm.Admin ){
3562 int aa = PB("aa");
@@ -3589,15 +3620,15 @@
3589 @ <td><textarea name="msg" cols="80" rows="10" wrap="virtual">\
3590 @ %h(PT("msg"))</textarea>
3591 @ </tr>
3592 @ <tr>
3593 @ <td></td>
3594 if( fossil_strcmp(P("name"),"test2")==0 ){
3595 @ <td><input type="submit" name="submit" value="Dry Run">
3596 }else{
3597 @ <td><input type="submit" name="submit" value="Send Message">
3598 }
3599 @ </tr>
3600 @ </table>
3601 @ </form>
3602 style_finish_page();
3603 }
3604
--- src/alerts.c
+++ src/alerts.c
@@ -634,18 +634,24 @@
634 emailerGetSetting(p, &p->zCmd, "email-send-command");
635 }else if( fossil_strcmp(p->zDest, "dir")==0 ){
636 emailerGetSetting(p, &p->zDir, "email-send-dir");
637 }else if( fossil_strcmp(p->zDest, "blob")==0 ){
638 blob_init(&p->out, 0, 0);
639 }else if( fossil_strcmp(p->zDest, "relay")==0
640 || fossil_strcmp(p->zDest, "debug-relay")==0
641 ){
642 const char *zRelay = 0;
643 emailerGetSetting(p, &zRelay, "email-send-relayhost");
644 if( zRelay ){
645 u32 smtpFlags = SMTP_DIRECT;
646 if( mFlags & ALERT_TRACE ) smtpFlags |= SMTP_TRACE_STDOUT;
647 blob_init(&p->out, 0, 0);
648 p->pSmtp = smtp_session_new(domain_of_addr(p->zFrom), zRelay,
649 smtpFlags, 0);
650 if( p->zDest[0]=='d' ){
651 smtp_session_config(p->pSmtp, SMTP_TRACE_BLOB, &p->out);
652 }
653 smtp_client_startup(p->pSmtp);
654 }
655 }
656 return p;
657 }
@@ -3440,16 +3446,28 @@
3446 char *zSubject = PT("subject");
3447 int bAll = PB("all");
3448 int bAA = PB("aa");
3449 int bMods = PB("mods");
3450 const char *zSub = db_get("email-subname", "[Fossil Repo]");
3451 const char *zName = P("name"); /* Debugging options */
3452 const char *zDest = 0; /* How to send the announcement */
3453 int bTest = 0;
3454 Blob hdr, body;
3455
3456 if( fossil_strcmp(zName, "test2")==0 ){
3457 bTest = 2;
3458 zDest = "blob";
3459 }else if( fossil_strcmp(zName, "test3")==0 ){
3460 bTest = 3;
3461 if( fossil_strcmp(db_get("email-send-method",""),"relay")==0 ){
3462 zDest = "debug-relay";
3463 }
3464 }
3465 blob_init(&body, 0, 0);
3466 blob_init(&hdr, 0, 0);
3467 blob_appendf(&body, "%s", PT("msg")/*safe-for-%s*/);
3468 pSender = alert_sender_new(zDest, 0);
3469 if( zTo[0] ){
3470 blob_appendf(&hdr, "To: <%s>\r\nSubject: %s %s\r\n", zTo, zSub, zSubject);
3471 alert_send(pSender, &hdr, &body, 0);
3472 }
3473 if( bAll || bAA || bMods ){
@@ -3483,17 +3501,18 @@
3501 }
3502 alert_send(pSender, &hdr, &body, 0);
3503 }
3504 db_finalize(&q);
3505 }
3506 if( bTest ){
3507 /* If the URL is /announce/test2 instead of just /announce, then no
3508 ** email is actually sent. Instead, the text of the email that would
3509 ** have been sent is displayed in the result window. */
3510 @ <pre style='border: 2px solid blue; padding: 1ex;'>
3511 @ %h(blob_str(&pSender->out))
3512 @ </pre>
3513 blob_reset(&pSender->out);
3514 }
3515 zErr = pSender->zErr;
3516 pSender->zErr = 0;
3517 alert_sender_free(pSender);
3518 return zErr;
@@ -3509,24 +3528,31 @@
3528 ** also send a message to an arbitrary email address and/or to all
3529 ** subscribers regardless of whether or not they have elected to
3530 ** receive announcements.
3531 */
3532 void announce_page(void){
3533 const char *zAction = "announce";
3534 const char *zName = PD("name","");
3535 /*
3536 ** Debugging Notes:
3537 **
3538 ** /announce/test1 -> Shows query parameter values
3539 ** /announce/test2 -> Shows the formatted message but does
3540 ** not send it.
3541 ** /announce/test3 -> Sends the message, but also shows
3542 ** the SMTP transcript.
3543 */
3544 login_check_credentials();
3545 if( !g.perm.Announce ){
3546 login_needed(0);
3547 return;
3548 }
3549 if( !g.perm.Setup ){
3550 zName = 0; /* Disable debugging feature for non-admin users */
3551 }
3552 style_set_current_feature("alerts");
3553 if( fossil_strcmp(zName,"test1")==0 ){
3554 /* Visit the /announce/test1 page to see the CGI variables */
3555 zAction = "announce/test1";
3556 @ <p style='border: 1px solid black; padding: 1ex;'>
3557 cgi_print_all(0, 0, 0);
3558 @ </p>
@@ -3553,10 +3579,15 @@
3579 return;
3580 }
3581
3582 style_header("Send Announcement");
3583 alert_submenu_common();
3584 if( fossil_strcmp(zName,"test2")==0 ){
3585 zAction = "announce/test2";
3586 }else if( fossil_strcmp(zName,"test3")==0 ){
3587 zAction = "announce/test3";
3588 }
3589 @ <form method="POST" action="%R/%s(zAction)">
3590 login_insert_csrf_secret();
3591 @ <table class="subscribe">
3592 if( g.perm.Admin ){
3593 int aa = PB("aa");
@@ -3589,15 +3620,15 @@
3620 @ <td><textarea name="msg" cols="80" rows="10" wrap="virtual">\
3621 @ %h(PT("msg"))</textarea>
3622 @ </tr>
3623 @ <tr>
3624 @ <td></td>
3625 if( fossil_strcmp(zName,"test2")==0 ){
3626 @ <td><input type="submit" name="submit" value="Dry Run">
3627 }else{
3628 @ <td><input type="submit" name="submit" value="Send Message">
3629 }
3630 @ </tr>
3631 @ </table>
3632 @ </form>
3633 style_finish_page();
3634 }
3635

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button