Fossil SCM

Update the email notification transfer daemon script.

drh 2025-10-23 13:16 trunk
Commit 4163ef006d7067a686f24b9fc0aa6572e9df1f3a777d08486814b3af205621be
--- tools/email-sender.tcl
+++ tools/email-sender.tcl
@@ -16,29 +16,50 @@
1616
db eval {
1717
CREATE TABLE IF NOT EXISTS email(
1818
emailid INTEGER PRIMARY KEY,
1919
msg TXT
2020
);
21
+ CREATE TABLE IF NOT EXISTS sentlog(
22
+ mtime INT,
23
+ xto TEXT,
24
+ xfrom TEXT,
25
+ xsubject TEXT,
26
+ xsize INT
27
+ );
2128
}
29
+set ctr 0
2230
while {1} {
2331
set n 0
2432
db transaction immediate {
2533
set emailid 0
2634
db eval {SELECT emailid, msg FROM email LIMIT 1} {
2735
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"
3044
}
3145
set out [open |$pipe w]
3246
puts -nonewline $out $msg
3347
flush $out
3448
close $out
3549
incr n
50
+ incr ctr
3651
}
3752
if {$n>0} {
3853
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)}
3956
}
4057
}
4158
if {$n==0} {
59
+ if {$ctr>100} {
60
+ db eval {DELETE FROM sentlog WHERE mtime<unixepoch('now','-30 days')}
61
+ set ctr 0
62
+ }
4263
after $POLLING_INTERVAL
4364
}
4465
}
4566
--- 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 @@
390390
391391
When you configure a Fossil server this way, it adds outgoing email
392392
messages to an SQLite database file. A separate daemon process can then
393393
extract those messages for further disposition.
394394
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
398397
it finds off to a local MTA using the same [pipe to MTA protocol](#pipe)
399398
as above.
400399
401400
In this way, outbound email alerts escape the chroot jail without
402401
requiring that we insert a separate MTA configuration inside that jail.
403402
--- 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

Keyboard Shortcuts

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