Fossil SCM

Fix minor problems in email notification.

drh 2018-06-23 01:24 trunk
Commit 1cdf6f2049f7658e16fac9034d105cb15f2f659e51eaa9dc260241e6901d6014
1 file changed +20 -16
+20 -16
--- src/email.c
+++ src/email.c
@@ -70,11 +70,11 @@
7070
@ -- 'c4413' means check-in with rid=4413.
7171
@ --
7272
@ CREATE TABLE repository.pending_alert(
7373
@ eventid TEXT PRIMARY KEY, -- Object that changed
7474
@ sentSep BOOLEAN DEFAULT false, -- individual emails sent
75
-@ sendDigest BOOLEAN DEFAULT false -- digest emails sent
75
+@ sentDigest BOOLEAN DEFAULT false -- digest emails sent
7676
@ ) WITHOUT ROWID;
7777
@
7878
@ -- Record bounced emails. If too many bounces are received within
7979
@ -- some defined time range, then cancel the subscription. Older
8080
@ -- entries are periodically purged.
@@ -468,10 +468,11 @@
468468
** a cron-job to make sure alerts are sent
469469
** in a timely manner.
470470
** Options:
471471
**
472472
** --digest Send digests
473
+** --test Resets to standard output
473474
**
474475
** inbound [FILE] Receive an inbound email message. This message
475476
** is analyzed to see if it is a bounce, and if
476477
** necessary, subscribers may be disabled.
477478
**
@@ -504,10 +505,13 @@
504505
zCmd = g.argc>=3 ? g.argv[2] : "x";
505506
nCmd = (int)strlen(zCmd);
506507
if( strncmp(zCmd, "exec", nCmd)==0 ){
507508
u32 eFlags = 0;
508509
if( find_option("digest",0,0)!=0 ) eFlags |= SENDALERT_DIGEST;
510
+ if( find_option("test",0,0)!=0 ){
511
+ eFlags |= SENDALERT_PRESERVE|SENDALERT_STDOUT;
512
+ }
509513
verify_all_options();
510514
email_send_alerts(eFlags);
511515
}else
512516
if( strncmp(zCmd, "inbound", nCmd)==0 ){
513517
Blob email;
@@ -1434,34 +1438,33 @@
14341438
blob_appendf(pOut, "\n%.72c\nTo unsubscribe: %s/unsubscribe\n",
14351439
'-', db_get("email-url","http://localhost:8080"));
14361440
}
14371441
14381442
/*
1439
-** COMMAND: test-generate-alert
1443
+** COMMAND: test-alert
14401444
**
1441
-** Usage: %fossil test-generate-alert [--html] [--actual] EVENTID ...
1445
+** Usage: %fossil test-alert EVENTID ...
14421446
**
14431447
** Generate the text of an email alert for all of the EVENTIDs
1444
-** listed on the command-line. Write that text to standard
1445
-** output. If the --actual flag is present, then the EVENTIDs are
1446
-** the actual event-ids in the pending_alert table.
1448
+** listed on the command-line. Or if no events are listed on the
1449
+** command line, generate text for all events named in the
1450
+** pending_alert table.
14471451
**
14481452
** This command is intended for testing and debugging the logic
14491453
** that generates email alert text.
14501454
*/
1451
-void test_generate_alert_cmd(void){
1452
- int bActual = find_option("actual",0,0)!=0;
1455
+void test_alert_cmd(void){
14531456
Blob out;
14541457
int nEvent;
14551458
EmailEvent *pEvent, *p;
14561459
14571460
db_find_and_open_repository(0, 0);
14581461
verify_all_options();
14591462
db_begin_transaction();
14601463
email_schema();
14611464
db_multi_exec("CREATE TEMP TABLE wantalert(eventid TEXT)");
1462
- if( bActual ){
1465
+ if( g.argc==2 ){
14631466
db_multi_exec("INSERT INTO wantalert SELECT eventid FROM pending_alert");
14641467
}else{
14651468
int i;
14661469
for(i=2; i<g.argc; i++){
14671470
db_multi_exec("INSERT INTO wantalert VALUES(%Q)", g.argv[i]);
@@ -1495,11 +1498,11 @@
14951498
db_find_and_open_repository(0, 0);
14961499
verify_all_options();
14971500
db_begin_transaction();
14981501
email_schema();
14991502
for(i=2; i<g.argc; i++){
1500
- db_multi_exec("INSERT INTO pending_alert(eventId) VALUES(%Q)", g.argv[i]);
1503
+ db_multi_exec("REPLACE INTO pending_alert(eventId) VALUES(%Q)", g.argv[i]);
15011504
}
15021505
db_end_transaction(0);
15031506
}
15041507
15051508
#if INTERFACE
@@ -1506,10 +1509,11 @@
15061509
/*
15071510
** Flags for email_send_alerts()
15081511
*/
15091512
#define SENDALERT_DIGEST 0x0001 /* Send a digest */
15101513
#define SENDALERT_PRESERVE 0x0002 /* Do not mark the task as done */
1514
+#define SENDALERT_STDOUT 0x0004 /* Print emails instead of sending */
15111515
15121516
#endif /* INTERFACE */
15131517
15141518
/*
15151519
** Send alert emails to all subscribers
@@ -1521,10 +1525,11 @@
15211525
const char *zDigest = "false";
15221526
Blob hdr, body;
15231527
const char *zUrl;
15241528
const char *zRepoName;
15251529
const char *zFrom;
1530
+ const char *zDest = (flags & SENDALERT_STDOUT) ? "stdout" : 0;
15261531
15271532
db_begin_transaction();
15281533
if( !email_enabled() ) goto send_alerts_done;
15291534
zUrl = db_get("email-url",0);
15301535
if( zUrl==0 ) goto send_alerts_done;
@@ -1552,13 +1557,13 @@
15521557
if( nEvent==0 ) return;
15531558
blob_init(&hdr, 0, 0);
15541559
blob_init(&body, 0, 0);
15551560
db_prepare(&q,
15561561
"SELECT"
1557
- " subscriberCode," /* 0 */
1558
- " semail," /* 1 */
1559
- " ssub" /* 2 */
1562
+ " hex(subscriberCode)," /* 0 */
1563
+ " semail," /* 1 */
1564
+ " ssub" /* 2 */
15601565
" FROM subscriber"
15611566
" WHERE sverified AND NOT sdonotcall"
15621567
" AND sdigest IS %s",
15631568
zDigest/*safe-for-%s*/
15641569
);
@@ -1569,15 +1574,14 @@
15691574
int nHit = 0;
15701575
for(p=pEvents; p; p=p->pNext){
15711576
if( strchr(zSub,p->type)==0 ) continue;
15721577
if( nHit==0 ){
15731578
blob_appendf(&hdr,"To: %s\n", zEmail);
1574
- blob_appendf(&hdr,"From: %s\n", zFrom);
15751579
blob_appendf(&hdr,"Subject: %s activity alert\n", zRepoName);
15761580
blob_appendf(&body,
15771581
"This is an automated email sent by the Fossil repository "
1578
- "at %s to alert you to changes.\n",
1582
+ "at %s to report changes.\n",
15791583
zUrl
15801584
);
15811585
}
15821586
nHit++;
15831587
blob_append(&body, "\n", 1);
@@ -1584,11 +1588,11 @@
15841588
blob_append(&body, blob_buffer(&p->txt), blob_size(&p->txt));
15851589
}
15861590
if( nHit==0 ) continue;
15871591
blob_appendf(&body,"\n%.72c\nSubscription info: %s/alerts/%s\n",
15881592
'-', zUrl, zCode);
1589
- email_send(&hdr,&body,0,0);
1593
+ email_send(&hdr,&body,0,zDest);
15901594
blob_truncate(&hdr);
15911595
blob_truncate(&body);
15921596
}
15931597
blob_zero(&hdr);
15941598
blob_zero(&body);
15951599
--- src/email.c
+++ src/email.c
@@ -70,11 +70,11 @@
70 @ -- 'c4413' means check-in with rid=4413.
71 @ --
72 @ CREATE TABLE repository.pending_alert(
73 @ eventid TEXT PRIMARY KEY, -- Object that changed
74 @ sentSep BOOLEAN DEFAULT false, -- individual emails sent
75 @ sendDigest BOOLEAN DEFAULT false -- digest emails sent
76 @ ) WITHOUT ROWID;
77 @
78 @ -- Record bounced emails. If too many bounces are received within
79 @ -- some defined time range, then cancel the subscription. Older
80 @ -- entries are periodically purged.
@@ -468,10 +468,11 @@
468 ** a cron-job to make sure alerts are sent
469 ** in a timely manner.
470 ** Options:
471 **
472 ** --digest Send digests
 
473 **
474 ** inbound [FILE] Receive an inbound email message. This message
475 ** is analyzed to see if it is a bounce, and if
476 ** necessary, subscribers may be disabled.
477 **
@@ -504,10 +505,13 @@
504 zCmd = g.argc>=3 ? g.argv[2] : "x";
505 nCmd = (int)strlen(zCmd);
506 if( strncmp(zCmd, "exec", nCmd)==0 ){
507 u32 eFlags = 0;
508 if( find_option("digest",0,0)!=0 ) eFlags |= SENDALERT_DIGEST;
 
 
 
509 verify_all_options();
510 email_send_alerts(eFlags);
511 }else
512 if( strncmp(zCmd, "inbound", nCmd)==0 ){
513 Blob email;
@@ -1434,34 +1438,33 @@
1434 blob_appendf(pOut, "\n%.72c\nTo unsubscribe: %s/unsubscribe\n",
1435 '-', db_get("email-url","http://localhost:8080"));
1436 }
1437
1438 /*
1439 ** COMMAND: test-generate-alert
1440 **
1441 ** Usage: %fossil test-generate-alert [--html] [--actual] EVENTID ...
1442 **
1443 ** Generate the text of an email alert for all of the EVENTIDs
1444 ** listed on the command-line. Write that text to standard
1445 ** output. If the --actual flag is present, then the EVENTIDs are
1446 ** the actual event-ids in the pending_alert table.
1447 **
1448 ** This command is intended for testing and debugging the logic
1449 ** that generates email alert text.
1450 */
1451 void test_generate_alert_cmd(void){
1452 int bActual = find_option("actual",0,0)!=0;
1453 Blob out;
1454 int nEvent;
1455 EmailEvent *pEvent, *p;
1456
1457 db_find_and_open_repository(0, 0);
1458 verify_all_options();
1459 db_begin_transaction();
1460 email_schema();
1461 db_multi_exec("CREATE TEMP TABLE wantalert(eventid TEXT)");
1462 if( bActual ){
1463 db_multi_exec("INSERT INTO wantalert SELECT eventid FROM pending_alert");
1464 }else{
1465 int i;
1466 for(i=2; i<g.argc; i++){
1467 db_multi_exec("INSERT INTO wantalert VALUES(%Q)", g.argv[i]);
@@ -1495,11 +1498,11 @@
1495 db_find_and_open_repository(0, 0);
1496 verify_all_options();
1497 db_begin_transaction();
1498 email_schema();
1499 for(i=2; i<g.argc; i++){
1500 db_multi_exec("INSERT INTO pending_alert(eventId) VALUES(%Q)", g.argv[i]);
1501 }
1502 db_end_transaction(0);
1503 }
1504
1505 #if INTERFACE
@@ -1506,10 +1509,11 @@
1506 /*
1507 ** Flags for email_send_alerts()
1508 */
1509 #define SENDALERT_DIGEST 0x0001 /* Send a digest */
1510 #define SENDALERT_PRESERVE 0x0002 /* Do not mark the task as done */
 
1511
1512 #endif /* INTERFACE */
1513
1514 /*
1515 ** Send alert emails to all subscribers
@@ -1521,10 +1525,11 @@
1521 const char *zDigest = "false";
1522 Blob hdr, body;
1523 const char *zUrl;
1524 const char *zRepoName;
1525 const char *zFrom;
 
1526
1527 db_begin_transaction();
1528 if( !email_enabled() ) goto send_alerts_done;
1529 zUrl = db_get("email-url",0);
1530 if( zUrl==0 ) goto send_alerts_done;
@@ -1552,13 +1557,13 @@
1552 if( nEvent==0 ) return;
1553 blob_init(&hdr, 0, 0);
1554 blob_init(&body, 0, 0);
1555 db_prepare(&q,
1556 "SELECT"
1557 " subscriberCode," /* 0 */
1558 " semail," /* 1 */
1559 " ssub" /* 2 */
1560 " FROM subscriber"
1561 " WHERE sverified AND NOT sdonotcall"
1562 " AND sdigest IS %s",
1563 zDigest/*safe-for-%s*/
1564 );
@@ -1569,15 +1574,14 @@
1569 int nHit = 0;
1570 for(p=pEvents; p; p=p->pNext){
1571 if( strchr(zSub,p->type)==0 ) continue;
1572 if( nHit==0 ){
1573 blob_appendf(&hdr,"To: %s\n", zEmail);
1574 blob_appendf(&hdr,"From: %s\n", zFrom);
1575 blob_appendf(&hdr,"Subject: %s activity alert\n", zRepoName);
1576 blob_appendf(&body,
1577 "This is an automated email sent by the Fossil repository "
1578 "at %s to alert you to changes.\n",
1579 zUrl
1580 );
1581 }
1582 nHit++;
1583 blob_append(&body, "\n", 1);
@@ -1584,11 +1588,11 @@
1584 blob_append(&body, blob_buffer(&p->txt), blob_size(&p->txt));
1585 }
1586 if( nHit==0 ) continue;
1587 blob_appendf(&body,"\n%.72c\nSubscription info: %s/alerts/%s\n",
1588 '-', zUrl, zCode);
1589 email_send(&hdr,&body,0,0);
1590 blob_truncate(&hdr);
1591 blob_truncate(&body);
1592 }
1593 blob_zero(&hdr);
1594 blob_zero(&body);
1595
--- src/email.c
+++ src/email.c
@@ -70,11 +70,11 @@
70 @ -- 'c4413' means check-in with rid=4413.
71 @ --
72 @ CREATE TABLE repository.pending_alert(
73 @ eventid TEXT PRIMARY KEY, -- Object that changed
74 @ sentSep BOOLEAN DEFAULT false, -- individual emails sent
75 @ sentDigest BOOLEAN DEFAULT false -- digest emails sent
76 @ ) WITHOUT ROWID;
77 @
78 @ -- Record bounced emails. If too many bounces are received within
79 @ -- some defined time range, then cancel the subscription. Older
80 @ -- entries are periodically purged.
@@ -468,10 +468,11 @@
468 ** a cron-job to make sure alerts are sent
469 ** in a timely manner.
470 ** Options:
471 **
472 ** --digest Send digests
473 ** --test Resets to standard output
474 **
475 ** inbound [FILE] Receive an inbound email message. This message
476 ** is analyzed to see if it is a bounce, and if
477 ** necessary, subscribers may be disabled.
478 **
@@ -504,10 +505,13 @@
505 zCmd = g.argc>=3 ? g.argv[2] : "x";
506 nCmd = (int)strlen(zCmd);
507 if( strncmp(zCmd, "exec", nCmd)==0 ){
508 u32 eFlags = 0;
509 if( find_option("digest",0,0)!=0 ) eFlags |= SENDALERT_DIGEST;
510 if( find_option("test",0,0)!=0 ){
511 eFlags |= SENDALERT_PRESERVE|SENDALERT_STDOUT;
512 }
513 verify_all_options();
514 email_send_alerts(eFlags);
515 }else
516 if( strncmp(zCmd, "inbound", nCmd)==0 ){
517 Blob email;
@@ -1434,34 +1438,33 @@
1438 blob_appendf(pOut, "\n%.72c\nTo unsubscribe: %s/unsubscribe\n",
1439 '-', db_get("email-url","http://localhost:8080"));
1440 }
1441
1442 /*
1443 ** COMMAND: test-alert
1444 **
1445 ** Usage: %fossil test-alert EVENTID ...
1446 **
1447 ** Generate the text of an email alert for all of the EVENTIDs
1448 ** listed on the command-line. Or if no events are listed on the
1449 ** command line, generate text for all events named in the
1450 ** pending_alert table.
1451 **
1452 ** This command is intended for testing and debugging the logic
1453 ** that generates email alert text.
1454 */
1455 void test_alert_cmd(void){
 
1456 Blob out;
1457 int nEvent;
1458 EmailEvent *pEvent, *p;
1459
1460 db_find_and_open_repository(0, 0);
1461 verify_all_options();
1462 db_begin_transaction();
1463 email_schema();
1464 db_multi_exec("CREATE TEMP TABLE wantalert(eventid TEXT)");
1465 if( g.argc==2 ){
1466 db_multi_exec("INSERT INTO wantalert SELECT eventid FROM pending_alert");
1467 }else{
1468 int i;
1469 for(i=2; i<g.argc; i++){
1470 db_multi_exec("INSERT INTO wantalert VALUES(%Q)", g.argv[i]);
@@ -1495,11 +1498,11 @@
1498 db_find_and_open_repository(0, 0);
1499 verify_all_options();
1500 db_begin_transaction();
1501 email_schema();
1502 for(i=2; i<g.argc; i++){
1503 db_multi_exec("REPLACE INTO pending_alert(eventId) VALUES(%Q)", g.argv[i]);
1504 }
1505 db_end_transaction(0);
1506 }
1507
1508 #if INTERFACE
@@ -1506,10 +1509,11 @@
1509 /*
1510 ** Flags for email_send_alerts()
1511 */
1512 #define SENDALERT_DIGEST 0x0001 /* Send a digest */
1513 #define SENDALERT_PRESERVE 0x0002 /* Do not mark the task as done */
1514 #define SENDALERT_STDOUT 0x0004 /* Print emails instead of sending */
1515
1516 #endif /* INTERFACE */
1517
1518 /*
1519 ** Send alert emails to all subscribers
@@ -1521,10 +1525,11 @@
1525 const char *zDigest = "false";
1526 Blob hdr, body;
1527 const char *zUrl;
1528 const char *zRepoName;
1529 const char *zFrom;
1530 const char *zDest = (flags & SENDALERT_STDOUT) ? "stdout" : 0;
1531
1532 db_begin_transaction();
1533 if( !email_enabled() ) goto send_alerts_done;
1534 zUrl = db_get("email-url",0);
1535 if( zUrl==0 ) goto send_alerts_done;
@@ -1552,13 +1557,13 @@
1557 if( nEvent==0 ) return;
1558 blob_init(&hdr, 0, 0);
1559 blob_init(&body, 0, 0);
1560 db_prepare(&q,
1561 "SELECT"
1562 " hex(subscriberCode)," /* 0 */
1563 " semail," /* 1 */
1564 " ssub" /* 2 */
1565 " FROM subscriber"
1566 " WHERE sverified AND NOT sdonotcall"
1567 " AND sdigest IS %s",
1568 zDigest/*safe-for-%s*/
1569 );
@@ -1569,15 +1574,14 @@
1574 int nHit = 0;
1575 for(p=pEvents; p; p=p->pNext){
1576 if( strchr(zSub,p->type)==0 ) continue;
1577 if( nHit==0 ){
1578 blob_appendf(&hdr,"To: %s\n", zEmail);
 
1579 blob_appendf(&hdr,"Subject: %s activity alert\n", zRepoName);
1580 blob_appendf(&body,
1581 "This is an automated email sent by the Fossil repository "
1582 "at %s to report changes.\n",
1583 zUrl
1584 );
1585 }
1586 nHit++;
1587 blob_append(&body, "\n", 1);
@@ -1584,11 +1588,11 @@
1588 blob_append(&body, blob_buffer(&p->txt), blob_size(&p->txt));
1589 }
1590 if( nHit==0 ) continue;
1591 blob_appendf(&body,"\n%.72c\nSubscription info: %s/alerts/%s\n",
1592 '-', zUrl, zCode);
1593 email_send(&hdr,&body,0,zDest);
1594 blob_truncate(&hdr);
1595 blob_truncate(&body);
1596 }
1597 blob_zero(&hdr);
1598 blob_zero(&body);
1599

Keyboard Shortcuts

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