Fossil SCM
Update the email notification transfer daemon script.
Commit
4163ef006d7067a686f24b9fc0aa6572e9df1f3a777d08486814b3af205621be
Parent
2f27f4b09640acf…
2 files changed
+23
-2
+2
-3
+23
-2
| --- tools/email-sender.tcl | ||
| +++ tools/email-sender.tcl | ||
| @@ -16,29 +16,50 @@ | ||
| 16 | 16 | db eval { |
| 17 | 17 | CREATE TABLE IF NOT EXISTS email( |
| 18 | 18 | emailid INTEGER PRIMARY KEY, |
| 19 | 19 | msg TXT |
| 20 | 20 | ); |
| 21 | + CREATE TABLE IF NOT EXISTS sentlog( | |
| 22 | + mtime INT, | |
| 23 | + xto TEXT, | |
| 24 | + xfrom TEXT, | |
| 25 | + xsubject TEXT, | |
| 26 | + xsize INT | |
| 27 | + ); | |
| 21 | 28 | } |
| 29 | +set ctr 0 | |
| 22 | 30 | while {1} { |
| 23 | 31 | set n 0 |
| 24 | 32 | db transaction immediate { |
| 25 | 33 | set emailid 0 |
| 26 | 34 | db eval {SELECT emailid, msg FROM email LIMIT 1} { |
| 27 | 35 | set pipe $PIPE |
| 28 | - if {[regexp {\nFrom:[^\n]*<([^>]+)>} $msg all addr]} { | |
| 29 | - append pipe " -f $addr" | |
| 36 | + set to unk | |
| 37 | + set subject none | |
| 38 | + set size [string length $msg] | |
| 39 | + regexp {To:[^\n]*<([^>]+)>} $msg all to | |
| 40 | + regexp {\nSubject:[ ]*([^\r\n]+)} $msg all subject | |
| 41 | + set subject [string trim $subject] | |
| 42 | + if {[regexp {\nFrom:[^\n]*<([^>]+)>} $msg all from]} { | |
| 43 | + append pipe " -f $from" | |
| 30 | 44 | } |
| 31 | 45 | set out [open |$pipe w] |
| 32 | 46 | puts -nonewline $out $msg |
| 33 | 47 | flush $out |
| 34 | 48 | close $out |
| 35 | 49 | incr n |
| 50 | + incr ctr | |
| 36 | 51 | } |
| 37 | 52 | if {$n>0} { |
| 38 | 53 | db eval {DELETE FROM email WHERE emailid=$emailid} |
| 54 | + db eval {INSERT INTO sentlog(mtime,xto,xfrom,xsubject,xsize) | |
| 55 | + VALUES(unixepoch(),$to,$from,$subject,$size)} | |
| 39 | 56 | } |
| 40 | 57 | } |
| 41 | 58 | if {$n==0} { |
| 59 | + if {$ctr>100} { | |
| 60 | + db eval {DELETE FROM sentlog WHERE mtime<unixepoch('now','-30 days')} | |
| 61 | + set ctr 0 | |
| 62 | + } | |
| 42 | 63 | after $POLLING_INTERVAL |
| 43 | 64 | } |
| 44 | 65 | } |
| 45 | 66 |
| --- tools/email-sender.tcl | |
| +++ tools/email-sender.tcl | |
| @@ -16,29 +16,50 @@ | |
| 16 | db eval { |
| 17 | CREATE TABLE IF NOT EXISTS email( |
| 18 | emailid INTEGER PRIMARY KEY, |
| 19 | msg TXT |
| 20 | ); |
| 21 | } |
| 22 | while {1} { |
| 23 | set n 0 |
| 24 | db transaction immediate { |
| 25 | set emailid 0 |
| 26 | db eval {SELECT emailid, msg FROM email LIMIT 1} { |
| 27 | set pipe $PIPE |
| 28 | if {[regexp {\nFrom:[^\n]*<([^>]+)>} $msg all addr]} { |
| 29 | append pipe " -f $addr" |
| 30 | } |
| 31 | set out [open |$pipe w] |
| 32 | puts -nonewline $out $msg |
| 33 | flush $out |
| 34 | close $out |
| 35 | incr n |
| 36 | } |
| 37 | if {$n>0} { |
| 38 | db eval {DELETE FROM email WHERE emailid=$emailid} |
| 39 | } |
| 40 | } |
| 41 | if {$n==0} { |
| 42 | after $POLLING_INTERVAL |
| 43 | } |
| 44 | } |
| 45 |
| --- tools/email-sender.tcl | |
| +++ tools/email-sender.tcl | |
| @@ -16,29 +16,50 @@ | |
| 16 | db eval { |
| 17 | CREATE TABLE IF NOT EXISTS email( |
| 18 | emailid INTEGER PRIMARY KEY, |
| 19 | msg TXT |
| 20 | ); |
| 21 | CREATE TABLE IF NOT EXISTS sentlog( |
| 22 | mtime INT, |
| 23 | xto TEXT, |
| 24 | xfrom TEXT, |
| 25 | xsubject TEXT, |
| 26 | xsize INT |
| 27 | ); |
| 28 | } |
| 29 | set ctr 0 |
| 30 | while {1} { |
| 31 | set n 0 |
| 32 | db transaction immediate { |
| 33 | set emailid 0 |
| 34 | db eval {SELECT emailid, msg FROM email LIMIT 1} { |
| 35 | set pipe $PIPE |
| 36 | set to unk |
| 37 | set subject none |
| 38 | set size [string length $msg] |
| 39 | regexp {To:[^\n]*<([^>]+)>} $msg all to |
| 40 | regexp {\nSubject:[ ]*([^\r\n]+)} $msg all subject |
| 41 | set subject [string trim $subject] |
| 42 | if {[regexp {\nFrom:[^\n]*<([^>]+)>} $msg all from]} { |
| 43 | append pipe " -f $from" |
| 44 | } |
| 45 | set out [open |$pipe w] |
| 46 | puts -nonewline $out $msg |
| 47 | flush $out |
| 48 | close $out |
| 49 | incr n |
| 50 | incr ctr |
| 51 | } |
| 52 | if {$n>0} { |
| 53 | db eval {DELETE FROM email WHERE emailid=$emailid} |
| 54 | db eval {INSERT INTO sentlog(mtime,xto,xfrom,xsubject,xsize) |
| 55 | VALUES(unixepoch(),$to,$from,$subject,$size)} |
| 56 | } |
| 57 | } |
| 58 | if {$n==0} { |
| 59 | if {$ctr>100} { |
| 60 | db eval {DELETE FROM sentlog WHERE mtime<unixepoch('now','-30 days')} |
| 61 | set ctr 0 |
| 62 | } |
| 63 | after $POLLING_INTERVAL |
| 64 | } |
| 65 | } |
| 66 |
+2
-3
| --- www/alerts.md | ||
| +++ www/alerts.md | ||
| @@ -390,13 +390,12 @@ | ||
| 390 | 390 | |
| 391 | 391 | When you configure a Fossil server this way, it adds outgoing email |
| 392 | 392 | messages to an SQLite database file. A separate daemon process can then |
| 393 | 393 | extract those messages for further disposition. |
| 394 | 394 | |
| 395 | -Fossil includes a copy of [the daemon](/file/tools/email-sender.tcl) | |
| 396 | -used on `fossil-scm.org`: it is just a short Tcl script that | |
| 397 | -continuously monitors this database for new messages and hands any that | |
| 395 | +Fossil uses a short TCL script (seen at [](/file/tools/email-sender.tcl)) | |
| 396 | +that continuously monitors this database for new messages and hands any that | |
| 398 | 397 | it finds off to a local MTA using the same [pipe to MTA protocol](#pipe) |
| 399 | 398 | as above. |
| 400 | 399 | |
| 401 | 400 | In this way, outbound email alerts escape the chroot jail without |
| 402 | 401 | requiring that we insert a separate MTA configuration inside that jail. |
| 403 | 402 |
| --- www/alerts.md | |
| +++ www/alerts.md | |
| @@ -390,13 +390,12 @@ | |
| 390 | |
| 391 | When you configure a Fossil server this way, it adds outgoing email |
| 392 | messages to an SQLite database file. A separate daemon process can then |
| 393 | extract those messages for further disposition. |
| 394 | |
| 395 | Fossil includes a copy of [the daemon](/file/tools/email-sender.tcl) |
| 396 | used on `fossil-scm.org`: it is just a short Tcl script that |
| 397 | continuously monitors this database for new messages and hands any that |
| 398 | it finds off to a local MTA using the same [pipe to MTA protocol](#pipe) |
| 399 | as above. |
| 400 | |
| 401 | In this way, outbound email alerts escape the chroot jail without |
| 402 | requiring that we insert a separate MTA configuration inside that jail. |
| 403 |
| --- www/alerts.md | |
| +++ www/alerts.md | |
| @@ -390,13 +390,12 @@ | |
| 390 | |
| 391 | When you configure a Fossil server this way, it adds outgoing email |
| 392 | messages to an SQLite database file. A separate daemon process can then |
| 393 | extract those messages for further disposition. |
| 394 | |
| 395 | Fossil uses a short TCL script (seen at [](/file/tools/email-sender.tcl)) |
| 396 | that continuously monitors this database for new messages and hands any that |
| 397 | it finds off to a local MTA using the same [pipe to MTA protocol](#pipe) |
| 398 | as above. |
| 399 | |
| 400 | In this way, outbound email alerts escape the chroot jail without |
| 401 | requiring that we insert a separate MTA configuration inside that jail. |
| 402 |