Fossil SCM

Automatically send alert emails after each webpage request.

drh 2018-06-23 18:44 trunk
Commit d4e9df1729ced9096bd7c3211166c05dc93d2d947ed2ecc6e46bd8c6d06101cb
3 files changed +5 +35 -1 +1 -1
+5
--- src/cgi.c
+++ src/cgi.c
@@ -336,10 +336,15 @@
336336
}
337337
}
338338
}
339339
fflush(g.httpOut);
340340
CGIDEBUG(("DONE\n"));
341
+
342
+ /* After the webpage has been sent, do any useful background
343
+ /* processing.
344
+ */
345
+ email_auto_exec();
341346
}
342347
343348
/*
344349
** Do a redirect request to the URL given in the argument.
345350
**
346351
--- src/cgi.c
+++ src/cgi.c
@@ -336,10 +336,15 @@
336 }
337 }
338 }
339 fflush(g.httpOut);
340 CGIDEBUG(("DONE\n"));
 
 
 
 
 
341 }
342
343 /*
344 ** Do a redirect request to the URL given in the argument.
345 **
346
--- src/cgi.c
+++ src/cgi.c
@@ -336,10 +336,15 @@
336 }
337 }
338 }
339 fflush(g.httpOut);
340 CGIDEBUG(("DONE\n"));
341
342 /* After the webpage has been sent, do any useful background
343 /* processing.
344 */
345 email_auto_exec();
346 }
347
348 /*
349 ** Do a redirect request to the URL given in the argument.
350 **
351
+35 -1
--- src/email.c
+++ src/email.c
@@ -231,10 +231,19 @@
231231
@ This is short name used to identifies the repository in the
232232
@ Subject: line of email alerts. Traditionally this name is
233233
@ included in square brackets. Examples: "[fossil-src]", "[sqlite-src]".
234234
@ (Property: "email-subname")</p>
235235
@ <hr>
236
+
237
+ onoff_attribute("Automatic Email Exec", "email-autoexec",
238
+ "eauto", 0, 0);
239
+ @ <p>If enabled, then email notifications are automatically
240
+ @ dispatched after some webpages are accessed. This eliminates the
241
+ @ need to have a cron job running to invoke "fossil email exec"
242
+ @ periodically.
243
+ @ (Property: "email-autoexec")</p>
244
+ @ <hr>
236245
237246
multiple_choice_attribute("Email Send Method", "email-send-method", "esm",
238247
"off", count(azSendMethods)/2, azSendMethods);
239248
@ <p>How to send email. The "Pipe to a command"
240249
@ method is the usual choice in production.
@@ -1658,11 +1667,11 @@
16581667
#define SENDALERT_STDOUT 0x0004 /* Print emails instead of sending */
16591668
16601669
#endif /* INTERFACE */
16611670
16621671
/*
1663
-** Send alert emails to all subscribers
1672
+** Send alert emails to all subscribers.
16641673
*/
16651674
void email_send_alerts(u32 flags){
16661675
EmailEvent *pEvents, *p;
16671676
int nEvent = 0;
16681677
Stmt q;
@@ -1754,5 +1763,30 @@
17541763
}
17551764
send_alerts_done:
17561765
email_sender_free(pSender);
17571766
db_end_transaction(0);
17581767
}
1768
+
1769
+/*
1770
+** Check to see if any email notifications need to occur, and then
1771
+** do them.
1772
+**
1773
+** This routine is called after certain webpages have been run and
1774
+** have already responded.
1775
+*/
1776
+void email_auto_exec(void){
1777
+ int iJulianDay;
1778
+ if( g.db==0 ) return;
1779
+ db_begin_transaction();
1780
+ if( !email_tables_exist() ) goto autoexec_done;
1781
+ if( !db_get_boolean("email-autoexec",0) ) goto autoexec_done;
1782
+ if( !db_exists("SELECT 1 FROM pending_alert") ) goto autoexec_done;
1783
+ email_send_alerts(0);
1784
+ iJulianDay = db_int(0, "SELECT julianday('now')");
1785
+ if( iJulianDay>db_get_int("email-last-digest",0) ){
1786
+ email_send_alerts(SENDALERT_DIGEST);
1787
+ db_set_int("email-last-digest", iJulianDay, 0);
1788
+ }
1789
+
1790
+autoexec_done:
1791
+ db_end_transaction(0);
1792
+}
17591793
--- src/email.c
+++ src/email.c
@@ -231,10 +231,19 @@
231 @ This is short name used to identifies the repository in the
232 @ Subject: line of email alerts. Traditionally this name is
233 @ included in square brackets. Examples: "[fossil-src]", "[sqlite-src]".
234 @ (Property: "email-subname")</p>
235 @ <hr>
 
 
 
 
 
 
 
 
 
236
237 multiple_choice_attribute("Email Send Method", "email-send-method", "esm",
238 "off", count(azSendMethods)/2, azSendMethods);
239 @ <p>How to send email. The "Pipe to a command"
240 @ method is the usual choice in production.
@@ -1658,11 +1667,11 @@
1658 #define SENDALERT_STDOUT 0x0004 /* Print emails instead of sending */
1659
1660 #endif /* INTERFACE */
1661
1662 /*
1663 ** Send alert emails to all subscribers
1664 */
1665 void email_send_alerts(u32 flags){
1666 EmailEvent *pEvents, *p;
1667 int nEvent = 0;
1668 Stmt q;
@@ -1754,5 +1763,30 @@
1754 }
1755 send_alerts_done:
1756 email_sender_free(pSender);
1757 db_end_transaction(0);
1758 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1759
--- src/email.c
+++ src/email.c
@@ -231,10 +231,19 @@
231 @ This is short name used to identifies the repository in the
232 @ Subject: line of email alerts. Traditionally this name is
233 @ included in square brackets. Examples: "[fossil-src]", "[sqlite-src]".
234 @ (Property: "email-subname")</p>
235 @ <hr>
236
237 onoff_attribute("Automatic Email Exec", "email-autoexec",
238 "eauto", 0, 0);
239 @ <p>If enabled, then email notifications are automatically
240 @ dispatched after some webpages are accessed. This eliminates the
241 @ need to have a cron job running to invoke "fossil email exec"
242 @ periodically.
243 @ (Property: "email-autoexec")</p>
244 @ <hr>
245
246 multiple_choice_attribute("Email Send Method", "email-send-method", "esm",
247 "off", count(azSendMethods)/2, azSendMethods);
248 @ <p>How to send email. The "Pipe to a command"
249 @ method is the usual choice in production.
@@ -1658,11 +1667,11 @@
1667 #define SENDALERT_STDOUT 0x0004 /* Print emails instead of sending */
1668
1669 #endif /* INTERFACE */
1670
1671 /*
1672 ** Send alert emails to all subscribers.
1673 */
1674 void email_send_alerts(u32 flags){
1675 EmailEvent *pEvents, *p;
1676 int nEvent = 0;
1677 Stmt q;
@@ -1754,5 +1763,30 @@
1763 }
1764 send_alerts_done:
1765 email_sender_free(pSender);
1766 db_end_transaction(0);
1767 }
1768
1769 /*
1770 ** Check to see if any email notifications need to occur, and then
1771 ** do them.
1772 **
1773 ** This routine is called after certain webpages have been run and
1774 ** have already responded.
1775 */
1776 void email_auto_exec(void){
1777 int iJulianDay;
1778 if( g.db==0 ) return;
1779 db_begin_transaction();
1780 if( !email_tables_exist() ) goto autoexec_done;
1781 if( !db_get_boolean("email-autoexec",0) ) goto autoexec_done;
1782 if( !db_exists("SELECT 1 FROM pending_alert") ) goto autoexec_done;
1783 email_send_alerts(0);
1784 iJulianDay = db_int(0, "SELECT julianday('now')");
1785 if( iJulianDay>db_get_int("email-last-digest",0) ){
1786 email_send_alerts(SENDALERT_DIGEST);
1787 db_set_int("email-last-digest", iJulianDay, 0);
1788 }
1789
1790 autoexec_done:
1791 db_end_transaction(0);
1792 }
1793
+1 -1
--- src/setup.c
+++ src/setup.c
@@ -969,11 +969,11 @@
969969
970970
971971
/*
972972
** Generate a checkbox for an attribute.
973973
*/
974
-static void onoff_attribute(
974
+void onoff_attribute(
975975
const char *zLabel, /* The text label on the checkbox */
976976
const char *zVar, /* The corresponding row in the VAR table */
977977
const char *zQParm, /* The query parameter */
978978
int dfltVal, /* Default value if VAR table entry does not exist */
979979
int disabled /* 1 if disabled */
980980
--- src/setup.c
+++ src/setup.c
@@ -969,11 +969,11 @@
969
970
971 /*
972 ** Generate a checkbox for an attribute.
973 */
974 static void onoff_attribute(
975 const char *zLabel, /* The text label on the checkbox */
976 const char *zVar, /* The corresponding row in the VAR table */
977 const char *zQParm, /* The query parameter */
978 int dfltVal, /* Default value if VAR table entry does not exist */
979 int disabled /* 1 if disabled */
980
--- src/setup.c
+++ src/setup.c
@@ -969,11 +969,11 @@
969
970
971 /*
972 ** Generate a checkbox for an attribute.
973 */
974 void onoff_attribute(
975 const char *zLabel, /* The text label on the checkbox */
976 const char *zVar, /* The corresponding row in the VAR table */
977 const char *zQParm, /* The query parameter */
978 int dfltVal, /* Default value if VAR table entry does not exist */
979 int disabled /* 1 if disabled */
980

Keyboard Shortcuts

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