summaryrefslogtreecommitdiff
path: root/tools/email-sender.tcl
diff options
context:
space:
mode:
authorcashmere <cashmere@autistici.org>2026-09-04 09:05:24 +0200
committercashmere <cashmere@autistici.org>2026-09-04 09:05:24 +0200
commit4f49b16079b27d7ce633619e4cddfdf2bffbc952 (patch)
treec296c1e7f3c3e2f6859c6d3a1b1b208779b89679 /tools/email-sender.tcl
downloadrelic-4f49b16079b27d7ce633619e4cddfdf2bffbc952.tar.gz
initial commitHEADmaster
Diffstat (limited to 'tools/email-sender.tcl')
-rwxr-xr-xtools/email-sender.tcl65
1 files changed, 65 insertions, 0 deletions
diff --git a/tools/email-sender.tcl b/tools/email-sender.tcl
new file mode 100755
index 0000000..cbec22f
--- /dev/null
+++ b/tools/email-sender.tcl
@@ -0,0 +1,65 @@
+#!/usr/bin/tcl
+#
+# Monitor the database file named by the DBFILE variable
+# looking for email messages sent by Fossil. Forward each
+# to /usr/sbin/sendmail.
+#
+set POLLING_INTERVAL 10000 ;# milliseconds
+set DBFILE /home/www/data/emailqueue.db
+set PIPE "/usr/sbin/sendmail -ti"
+
+package require sqlite3
+# puts "SQLite version [sqlite3 -version]"
+sqlite3 db $DBFILE
+db timeout 5000
+catch {db eval {PRAGMA journal_mode=WAL}}
+db eval {
+ CREATE TABLE IF NOT EXISTS email(
+ emailid INTEGER PRIMARY KEY,
+ msg TXT
+ );
+ CREATE TABLE IF NOT EXISTS sentlog(
+ mtime INT,
+ xto TEXT,
+ xfrom TEXT,
+ xsubject TEXT,
+ xsize INT
+ );
+}
+set ctr 0
+while {1} {
+ set n 0
+ db transaction immediate {
+ set emailid 0
+ db eval {SELECT emailid, msg FROM email LIMIT 1} {
+ set pipe $PIPE
+ set to unk
+ set subject none
+ set size [string length $msg]
+ regexp {To:[^\n]*<([^>]+)>} $msg all to
+ regexp {\nSubject:[ ]*([^\r\n]+)} $msg all subject
+ set subject [string trim $subject]
+ if {[regexp {\nFrom:[^\n]*<([^>]+)>} $msg all from]} {
+ append pipe " -f $from"
+ }
+ set out [open |$pipe w]
+ puts -nonewline $out $msg
+ flush $out
+ close $out
+ incr n
+ incr ctr
+ }
+ if {$n>0} {
+ db eval {DELETE FROM email WHERE emailid=$emailid}
+ db eval {INSERT INTO sentlog(mtime,xto,xfrom,xsubject,xsize)
+ VALUES(unixepoch(),$to,$from,$subject,$size)}
+ }
+ }
+ if {$n==0} {
+ if {$ctr>100} {
+ db eval {DELETE FROM sentlog WHERE mtime<unixepoch('now','-30 days')}
+ set ctr 0
+ }
+ after $POLLING_INTERVAL
+ }
+}