Fossil SCM

Improved debugging and diagnostic capabilities for announcement sending, especially when using relay.

drh 2025-04-07 16:42 trunk
Commit 056c83d120080925b0b6225ac98a08e10a3f1bc4617ec47b68ef753d5a245799
3 files changed +17 -7 +3 -1 +8 -5
+17 -7
--- src/alerts.c
+++ src/alerts.c
@@ -645,11 +645,14 @@
645645
u32 smtpFlags = SMTP_DIRECT;
646646
if( mFlags & ALERT_TRACE ) smtpFlags |= SMTP_TRACE_STDOUT;
647647
blob_init(&p->out, 0, 0);
648648
p->pSmtp = smtp_session_new(domain_of_addr(p->zFrom), zRelay,
649649
smtpFlags, 0);
650
- if( p->zDest[0]=='d' ){
650
+ if( p->pSmtp==0 || p->pSmtp->zErr ){
651
+ emailerError(p, "Could not start SMTP session: %s",
652
+ p->pSmtp ? p->pSmtp->zErr : "reason unknown");
653
+ }else if( p->zDest[0]=='d' ){
651654
smtp_session_config(p->pSmtp, SMTP_TRACE_BLOB, &p->out);
652655
}
653656
smtp_client_startup(p->pSmtp);
654657
}
655658
}
@@ -3501,14 +3504,20 @@
35013504
}
35023505
alert_send(pSender, &hdr, &body, 0);
35033506
}
35043507
db_finalize(&q);
35053508
}
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. */
3509
+ if( bTest && blob_size(&pSender->out) ){
3510
+ /* If the URL is "/announce/test2" then no email is actually sent.
3511
+ ** Instead, the text of the email that would have been sent is
3512
+ ** displayed in the result window.
3513
+ **
3514
+ ** If the URL is "/announce/test3" and the email-send-method is "relay"
3515
+ ** then the announcement is sent as it normally would be, but a
3516
+ ** transcript of the SMTP conversation with the MTA is shown here.
3517
+ */
3518
+ blob_trim(&pSender->out);
35103519
@ <pre style='border: 2px solid blue; padding: 1ex;'>
35113520
@ %h(blob_str(&pSender->out))
35123521
@ </pre>
35133522
blob_reset(&pSender->out);
35143523
}
@@ -3558,12 +3567,13 @@
35583567
@ </p>
35593568
}else if( P("submit")!=0 && cgi_csrf_safe(2) ){
35603569
char *zErr = alert_send_announcement();
35613570
style_header("Announcement Sent");
35623571
if( zErr ){
3563
- @ <h1>Internal Error</h1>
3564
- @ <p>The following error was reported by the system:
3572
+ @ <h1>Error</h1>
3573
+ @ <p>The following error was reported by the
3574
+ @ announcement-sending subsystem:
35653575
@ <blockquote><pre>
35663576
@ %h(zErr)
35673577
@ </pre></blockquote>
35683578
}else{
35693579
@ <p>The announcement has been sent.
35703580
--- src/alerts.c
+++ src/alerts.c
@@ -645,11 +645,14 @@
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 }
@@ -3501,14 +3504,20 @@
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 }
@@ -3558,12 +3567,13 @@
3558 @ </p>
3559 }else if( P("submit")!=0 && cgi_csrf_safe(2) ){
3560 char *zErr = alert_send_announcement();
3561 style_header("Announcement Sent");
3562 if( zErr ){
3563 @ <h1>Internal Error</h1>
3564 @ <p>The following error was reported by the system:
 
3565 @ <blockquote><pre>
3566 @ %h(zErr)
3567 @ </pre></blockquote>
3568 }else{
3569 @ <p>The announcement has been sent.
3570
--- src/alerts.c
+++ src/alerts.c
@@ -645,11 +645,14 @@
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->pSmtp==0 || p->pSmtp->zErr ){
651 emailerError(p, "Could not start SMTP session: %s",
652 p->pSmtp ? p->pSmtp->zErr : "reason unknown");
653 }else if( p->zDest[0]=='d' ){
654 smtp_session_config(p->pSmtp, SMTP_TRACE_BLOB, &p->out);
655 }
656 smtp_client_startup(p->pSmtp);
657 }
658 }
@@ -3501,14 +3504,20 @@
3504 }
3505 alert_send(pSender, &hdr, &body, 0);
3506 }
3507 db_finalize(&q);
3508 }
3509 if( bTest && blob_size(&pSender->out) ){
3510 /* If the URL is "/announce/test2" then no email is actually sent.
3511 ** Instead, the text of the email that would have been sent is
3512 ** displayed in the result window.
3513 **
3514 ** If the URL is "/announce/test3" and the email-send-method is "relay"
3515 ** then the announcement is sent as it normally would be, but a
3516 ** transcript of the SMTP conversation with the MTA is shown here.
3517 */
3518 blob_trim(&pSender->out);
3519 @ <pre style='border: 2px solid blue; padding: 1ex;'>
3520 @ %h(blob_str(&pSender->out))
3521 @ </pre>
3522 blob_reset(&pSender->out);
3523 }
@@ -3558,12 +3567,13 @@
3567 @ </p>
3568 }else if( P("submit")!=0 && cgi_csrf_safe(2) ){
3569 char *zErr = alert_send_announcement();
3570 style_header("Announcement Sent");
3571 if( zErr ){
3572 @ <h1>Error</h1>
3573 @ <p>The following error was reported by the
3574 @ announcement-sending subsystem:
3575 @ <blockquote><pre>
3576 @ %h(zErr)
3577 @ </pre></blockquote>
3578 }else{
3579 @ <p>The announcement has been sent.
3580
+3 -1
--- src/main.c
+++ src/main.c
@@ -3068,23 +3068,25 @@
30683068
** using this command interactively over SSH. A better solution would be
30693069
** to use a different command for "ssh" sync, but we cannot do that without
30703070
** breaking legacy.
30713071
**
30723072
** Options:
3073
+** --csrf-safe N Set cgi_csrf_safe() to to return N
30733074
** --nobody Pretend to be user "nobody"
30743075
** --test Do not do special "sync" processing when operating
30753076
** over an SSH link
30763077
** --th-trace Trace TH1 execution (for debugging purposes)
30773078
** --usercap CAP User capability string (Default: "sxy")
3078
-**
30793079
*/
30803080
void cmd_test_http(void){
30813081
const char *zIpAddr; /* IP address of remote client */
30823082
const char *zUserCap;
30833083
int bTest = 0;
3084
+ const char *zCsrfSafe = find_option("csrf-safe",0,1);
30843085
30853086
Th_InitTraceLog();
3087
+ if( zCsrfSafe ) g.okCsrf = atoi(zCsrfSafe);
30863088
zUserCap = find_option("usercap",0,1);
30873089
if( !find_option("nobody",0,0) ){
30883090
if( zUserCap==0 ){
30893091
g.useLocalauth = 1;
30903092
zUserCap = "sxy";
30913093
--- src/main.c
+++ src/main.c
@@ -3068,23 +3068,25 @@
3068 ** using this command interactively over SSH. A better solution would be
3069 ** to use a different command for "ssh" sync, but we cannot do that without
3070 ** breaking legacy.
3071 **
3072 ** Options:
 
3073 ** --nobody Pretend to be user "nobody"
3074 ** --test Do not do special "sync" processing when operating
3075 ** over an SSH link
3076 ** --th-trace Trace TH1 execution (for debugging purposes)
3077 ** --usercap CAP User capability string (Default: "sxy")
3078 **
3079 */
3080 void cmd_test_http(void){
3081 const char *zIpAddr; /* IP address of remote client */
3082 const char *zUserCap;
3083 int bTest = 0;
 
3084
3085 Th_InitTraceLog();
 
3086 zUserCap = find_option("usercap",0,1);
3087 if( !find_option("nobody",0,0) ){
3088 if( zUserCap==0 ){
3089 g.useLocalauth = 1;
3090 zUserCap = "sxy";
3091
--- src/main.c
+++ src/main.c
@@ -3068,23 +3068,25 @@
3068 ** using this command interactively over SSH. A better solution would be
3069 ** to use a different command for "ssh" sync, but we cannot do that without
3070 ** breaking legacy.
3071 **
3072 ** Options:
3073 ** --csrf-safe N Set cgi_csrf_safe() to to return N
3074 ** --nobody Pretend to be user "nobody"
3075 ** --test Do not do special "sync" processing when operating
3076 ** over an SSH link
3077 ** --th-trace Trace TH1 execution (for debugging purposes)
3078 ** --usercap CAP User capability string (Default: "sxy")
 
3079 */
3080 void cmd_test_http(void){
3081 const char *zIpAddr; /* IP address of remote client */
3082 const char *zUserCap;
3083 int bTest = 0;
3084 const char *zCsrfSafe = find_option("csrf-safe",0,1);
3085
3086 Th_InitTraceLog();
3087 if( zCsrfSafe ) g.okCsrf = atoi(zCsrfSafe);
3088 zUserCap = find_option("usercap",0,1);
3089 if( !find_option("nobody",0,0) ){
3090 if( zUserCap==0 ){
3091 g.useLocalauth = 1;
3092 zUserCap = "sxy";
3093
+8 -5
--- src/smtp.c
+++ src/smtp.c
@@ -381,15 +381,17 @@
381381
int smtp_client_quit(SmtpSession *p){
382382
Blob in = BLOB_INITIALIZER;
383383
int iCode = 0;
384384
int bMore = 0;
385385
char *zArg = 0;
386
- smtp_send_line(p, "QUIT\r\n");
387
- do{
388
- smtp_get_reply_from_server(p, &in, &iCode, &bMore, &zArg);
389
- }while( bMore );
390
- p->atEof = 1;
386
+ if( !p->atEof ){
387
+ smtp_send_line(p, "QUIT\r\n");
388
+ do{
389
+ smtp_get_reply_from_server(p, &in, &iCode, &bMore, &zArg);
390
+ }while( bMore );
391
+ p->atEof = 1;
392
+ }
391393
socket_close();
392394
return 0;
393395
}
394396
395397
/*
@@ -401,10 +403,11 @@
401403
int smtp_client_startup(SmtpSession *p){
402404
Blob in = BLOB_INITIALIZER;
403405
int iCode = 0;
404406
int bMore = 0;
405407
char *zArg = 0;
408
+ if( p==0 || p->atEof ) return 1;
406409
do{
407410
smtp_get_reply_from_server(p, &in, &iCode, &bMore, &zArg);
408411
}while( bMore );
409412
if( iCode!=220 ){
410413
smtp_client_quit(p);
411414
--- src/smtp.c
+++ src/smtp.c
@@ -381,15 +381,17 @@
381 int smtp_client_quit(SmtpSession *p){
382 Blob in = BLOB_INITIALIZER;
383 int iCode = 0;
384 int bMore = 0;
385 char *zArg = 0;
386 smtp_send_line(p, "QUIT\r\n");
387 do{
388 smtp_get_reply_from_server(p, &in, &iCode, &bMore, &zArg);
389 }while( bMore );
390 p->atEof = 1;
 
 
391 socket_close();
392 return 0;
393 }
394
395 /*
@@ -401,10 +403,11 @@
401 int smtp_client_startup(SmtpSession *p){
402 Blob in = BLOB_INITIALIZER;
403 int iCode = 0;
404 int bMore = 0;
405 char *zArg = 0;
 
406 do{
407 smtp_get_reply_from_server(p, &in, &iCode, &bMore, &zArg);
408 }while( bMore );
409 if( iCode!=220 ){
410 smtp_client_quit(p);
411
--- src/smtp.c
+++ src/smtp.c
@@ -381,15 +381,17 @@
381 int smtp_client_quit(SmtpSession *p){
382 Blob in = BLOB_INITIALIZER;
383 int iCode = 0;
384 int bMore = 0;
385 char *zArg = 0;
386 if( !p->atEof ){
387 smtp_send_line(p, "QUIT\r\n");
388 do{
389 smtp_get_reply_from_server(p, &in, &iCode, &bMore, &zArg);
390 }while( bMore );
391 p->atEof = 1;
392 }
393 socket_close();
394 return 0;
395 }
396
397 /*
@@ -401,10 +403,11 @@
403 int smtp_client_startup(SmtpSession *p){
404 Blob in = BLOB_INITIALIZER;
405 int iCode = 0;
406 int bMore = 0;
407 char *zArg = 0;
408 if( p==0 || p->atEof ) return 1;
409 do{
410 smtp_get_reply_from_server(p, &in, &iCode, &bMore, &zArg);
411 }while( bMore );
412 if( iCode!=220 ){
413 smtp_client_quit(p);
414

Keyboard Shortcuts

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