Fossil SCM

Add the test/fake-smtpd.tcl script used for testing. It will likely come in handy someday. See header comments on the file for details.

drh 2025-04-16 11:40 trunk
Commit f031f744f0e061c3708be33c51d9f63984b949928455559ca18bdcf1a40c6107
1 file changed +84
--- a/tools/fake-smtpd.tcl
+++ b/tools/fake-smtpd.tcl
@@ -0,0 +1,84 @@
1
+#!/usr/bin/tclsh
2
+#
3
+# This script is a testing aid for working on the Relay notification method
4
+# in Fossil.
5
+#
6
+# This script listens for connections on port 25 or probably some other TCP
7
+# port specified by the "--port N" option. It pretend to be an SMTP server,
8
+# though it does not actually relay any email. Instead, it just prints the
9
+# SMTP conversation on stdout.
10
+#
11
+# If the "--max N" option is used, then the fake SMTP server shuts down
12
+# with an error after receiving N messages from the client. This can be
13
+# used to test retry capabilities in the client.
14
+#
15
+# Suggested Test Procedure For Fossil Relay Notifications
16
+#
17
+# 1. Bring up "fossil ui"
18
+# 2. Configure notification for relay to localhost:8025
19
+# 3. Start this script in a separate window. Something like:
20
+# tclsh fake-smtpd.tcl -port 8025 -max 100
21
+# 4. Send test messages using Fossil
22
+#
23
+proc conn_puts {chan txt} {
24
+ puts "S: $txt"
25
+ puts $chan $txt
26
+ flush $chan
27
+}
28
+set mxMsg 100000000
29
+proc connection {chan ip port} {
30
+ global mxMsg
31
+ set nMsg 0
32
+ puts "*** begin connection from $ip:$port ***"
33
+ conn_puts $chan "220 localhost fake-SMTPD"
34
+ set inData 0
35
+ while {1} {
36
+ set line [string trimright [gets $chan]]
37
+ if {$line eq ""} {
38
+ if {[eof $chan]} break
39
+ }
40
+ puts "C: $line"
41
+ incr nMsg
42
+ if {$inData} {
43
+ if {$line eq "."} {
44
+ set inData 0
45
+ conn_puts $chan "250 Ok"
46
+ }
47
+ } elseif {$nMsg>$mxMsg} {
48
+ conn_puts $chan "999 I'm done!"
49
+ break
50
+ } elseif {[string match "HELO *" $line]} {
51
+ conn_puts $chan "250 Ok"
52
+ } elseif {[string match "EHLO *" $line]} {
53
+ conn_puts $chan "250-SIZE 100000"
54
+ conn_puts $chan "250 HELP"
55
+ } elseif {[string match "DATA*" $line]} {
56
+ conn_puts $chan "354 End data with <CR><LF>.<CR><LF>"
57
+ set inData 1
58
+ } elseif {[string match "QUIT*" $line]} {
59
+ conn_puts $chan "221 Bye"
60
+ break
61
+ } else {
62
+ conn_puts $chan "250 Ok"
63
+ }
64
+ }
65
+ puts "*** connection closed ($nMsg messages) ***"
66
+ close $chan
67
+}
68
+set port 25
69
+set argc [llength $argv]
70
+for {set i 0} {$i<$argc-1} {incr i} {
71
+ set arg [lindex $argv $i]
72
+ if {$arg eq "-port" || $arg eq "--port"} {
73
+ incr i
74
+ set port [lindex $argv $i]
75
+ }
76
+ if {$arg eq "-max" || $arg eq "--max"} {
77
+ incr i
78
+ set mxMsg [lindex $argv $i]
79
+ }
80
+}
81
+puts "listening on localhost:$port"
82
+socket -server connection $port
83
+set forever 0
84
+vwait forever
--- a/tools/fake-smtpd.tcl
+++ b/tools/fake-smtpd.tcl
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/tools/fake-smtpd.tcl
+++ b/tools/fake-smtpd.tcl
@@ -0,0 +1,84 @@
1 #!/usr/bin/tclsh
2 #
3 # This script is a testing aid for working on the Relay notification method
4 # in Fossil.
5 #
6 # This script listens for connections on port 25 or probably some other TCP
7 # port specified by the "--port N" option. It pretend to be an SMTP server,
8 # though it does not actually relay any email. Instead, it just prints the
9 # SMTP conversation on stdout.
10 #
11 # If the "--max N" option is used, then the fake SMTP server shuts down
12 # with an error after receiving N messages from the client. This can be
13 # used to test retry capabilities in the client.
14 #
15 # Suggested Test Procedure For Fossil Relay Notifications
16 #
17 # 1. Bring up "fossil ui"
18 # 2. Configure notification for relay to localhost:8025
19 # 3. Start this script in a separate window. Something like:
20 # tclsh fake-smtpd.tcl -port 8025 -max 100
21 # 4. Send test messages using Fossil
22 #
23 proc conn_puts {chan txt} {
24 puts "S: $txt"
25 puts $chan $txt
26 flush $chan
27 }
28 set mxMsg 100000000
29 proc connection {chan ip port} {
30 global mxMsg
31 set nMsg 0
32 puts "*** begin connection from $ip:$port ***"
33 conn_puts $chan "220 localhost fake-SMTPD"
34 set inData 0
35 while {1} {
36 set line [string trimright [gets $chan]]
37 if {$line eq ""} {
38 if {[eof $chan]} break
39 }
40 puts "C: $line"
41 incr nMsg
42 if {$inData} {
43 if {$line eq "."} {
44 set inData 0
45 conn_puts $chan "250 Ok"
46 }
47 } elseif {$nMsg>$mxMsg} {
48 conn_puts $chan "999 I'm done!"
49 break
50 } elseif {[string match "HELO *" $line]} {
51 conn_puts $chan "250 Ok"
52 } elseif {[string match "EHLO *" $line]} {
53 conn_puts $chan "250-SIZE 100000"
54 conn_puts $chan "250 HELP"
55 } elseif {[string match "DATA*" $line]} {
56 conn_puts $chan "354 End data with <CR><LF>.<CR><LF>"
57 set inData 1
58 } elseif {[string match "QUIT*" $line]} {
59 conn_puts $chan "221 Bye"
60 break
61 } else {
62 conn_puts $chan "250 Ok"
63 }
64 }
65 puts "*** connection closed ($nMsg messages) ***"
66 close $chan
67 }
68 set port 25
69 set argc [llength $argv]
70 for {set i 0} {$i<$argc-1} {incr i} {
71 set arg [lindex $argv $i]
72 if {$arg eq "-port" || $arg eq "--port"} {
73 incr i
74 set port [lindex $argv $i]
75 }
76 if {$arg eq "-max" || $arg eq "--max"} {
77 incr i
78 set mxMsg [lindex $argv $i]
79 }
80 }
81 puts "listening on localhost:$port"
82 socket -server connection $port
83 set forever 0
84 vwait forever

Keyboard Shortcuts

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