| 
									
										
										
										
											2008-11-30 18:49:46 -05:00
										 |  |  | USING: smtp tools.test io.streams.string io.sockets | 
					
						
							|  |  |  | io.sockets.secure threads smtp.server kernel sequences | 
					
						
							|  |  |  | namespaces logging accessors assocs sorting smtp.private | 
					
						
							|  |  |  | concurrency.promises system ;
 | 
					
						
							| 
									
										
										
										
											2008-03-01 17:00:45 -05:00
										 |  |  | IN: smtp.tests | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-30 11:12:08 -05:00
										 |  |  | \ send-email must-infer | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-07 02:03:27 -05:00
										 |  |  | { 0 0 } [ [ ] with-smtp-connection ] must-infer-as | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-07 02:03:27 -05:00
										 |  |  | [ "hello\nworld" validate-address ] must-fail | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-07 02:03:27 -05:00
										 |  |  | [ "slava@factorcode.org" ] | 
					
						
							|  |  |  | [ "slava@factorcode.org" validate-address ] unit-test | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-07 02:03:27 -05:00
										 |  |  | [ { "hello" "." "world" } validate-message ] must-fail | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-13 20:13:01 -05:00
										 |  |  | [ "aGVsbG8Kd29ybGQ=\r\n.\r\n" ] [ | 
					
						
							| 
									
										
										
										
											2009-04-17 18:52:41 -04:00
										 |  |  |     T{ email { body "hello\nworld" } } [ send-body ] with-string-writer | 
					
						
							| 
									
										
										
										
											2008-02-07 02:03:27 -05:00
										 |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-30 14:53:13 -05:00
										 |  |  | [ { "500 syntax error" } <response> check-response ] | 
					
						
							|  |  |  | [ smtp-error? ] must-fail-with | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-30 14:53:13 -05:00
										 |  |  | [ ] [ { "220 success" } <response> check-response ] unit-test | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-30 14:53:13 -05:00
										 |  |  | [ T{ response f 220 { "220 success" } } ] [ | 
					
						
							| 
									
										
										
										
											2008-02-15 23:20:31 -05:00
										 |  |  |     "220 success" [ receive-response ] with-string-reader | 
					
						
							| 
									
										
										
										
											2008-02-07 02:03:27 -05:00
										 |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-30 14:53:13 -05:00
										 |  |  | [ | 
					
						
							|  |  |  |     T{ response f 220 { | 
					
						
							|  |  |  |         "220-a multiline response" | 
					
						
							|  |  |  |         "250-another line" | 
					
						
							|  |  |  |         "220 the end" | 
					
						
							|  |  |  |     } } | 
					
						
							|  |  |  | ] [ | 
					
						
							| 
									
										
										
										
											2008-02-10 04:12:44 -05:00
										 |  |  |     "220-a multiline response\r\n250-another line\r\n220 the end" | 
					
						
							| 
									
										
										
										
											2008-02-15 23:20:31 -05:00
										 |  |  |     [ receive-response ] with-string-reader | 
					
						
							| 
									
										
										
										
											2008-02-07 02:03:27 -05:00
										 |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-07 02:03:27 -05:00
										 |  |  | [ ] [ | 
					
						
							| 
									
										
										
										
											2008-02-10 04:12:44 -05:00
										 |  |  |     "220-a multiline response\r\n250-another line\r\n220 the end" | 
					
						
							| 
									
										
										
										
											2008-02-15 23:20:31 -05:00
										 |  |  |     [ get-ok ] with-string-reader | 
					
						
							| 
									
										
										
										
											2008-02-07 02:03:27 -05:00
										 |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-07 02:03:27 -05:00
										 |  |  | [ | 
					
						
							|  |  |  |     "Subject:\r\nsecurity hole" validate-header | 
					
						
							|  |  |  | ] must-fail | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ | 
					
						
							| 
									
										
										
										
											2008-03-07 02:55:38 -05:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2009-01-13 20:13:01 -05:00
										 |  |  |         { "Content-Transfer-Encoding" "base64" } | 
					
						
							| 
									
										
										
										
											2009-04-17 18:52:41 -04:00
										 |  |  |         { "Content-Type" "text/plain; charset=UTF-8" } | 
					
						
							| 
									
										
										
										
											2008-02-07 02:03:27 -05:00
										 |  |  |         { "From" "Doug <erg@factorcode.org>" } | 
					
						
							| 
									
										
										
										
											2009-01-13 20:13:01 -05:00
										 |  |  |         { "MIME-Version" "1.0" } | 
					
						
							| 
									
										
										
										
											2008-02-07 02:03:27 -05:00
										 |  |  |         { "Subject" "Factor rules" } | 
					
						
							| 
									
										
										
										
											2008-03-07 02:55:38 -05:00
										 |  |  |         { "To" "Slava <slava@factorcode.org>, Ed <dharmatech@factorcode.org>" } | 
					
						
							| 
									
										
										
										
											2008-02-07 02:03:27 -05:00
										 |  |  |     } | 
					
						
							|  |  |  |     { "slava@factorcode.org" "dharmatech@factorcode.org" } | 
					
						
							|  |  |  |     "erg@factorcode.org" | 
					
						
							|  |  |  | ] [ | 
					
						
							| 
									
										
										
										
											2008-03-07 02:55:38 -05:00
										 |  |  |     <email> | 
					
						
							|  |  |  |         "Factor rules" >>subject | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             "Slava <slava@factorcode.org>" | 
					
						
							|  |  |  |             "Ed <dharmatech@factorcode.org>" | 
					
						
							|  |  |  |         } >>to | 
					
						
							|  |  |  |         "Doug <erg@factorcode.org>" >>from | 
					
						
							| 
									
										
										
										
											2008-08-16 18:20:18 -04:00
										 |  |  |     [ | 
					
						
							|  |  |  |         email>headers sort-keys [ | 
					
						
							|  |  |  |             drop { "Date" "Message-Id" } member? not
 | 
					
						
							|  |  |  |         ] assoc-filter
 | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  |     [ to>> [ extract-email ] map ] | 
					
						
							|  |  |  |     [ from>> extract-email ] tri
 | 
					
						
							| 
									
										
										
										
											2008-02-07 02:03:27 -05:00
										 |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-30 11:12:08 -05:00
										 |  |  | <promise> "p" set
 | 
					
						
							| 
									
										
										
										
											2008-05-09 18:11:20 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-30 11:12:08 -05:00
										 |  |  | [ ] [ "p" get mock-smtp-server ] unit-test | 
					
						
							| 
									
										
										
										
											2008-02-07 02:03:27 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | [ ] [ | 
					
						
							| 
									
										
										
										
											2008-11-30 16:11:03 -05:00
										 |  |  |     <secure-config> f >>verify [ | 
					
						
							| 
									
										
										
										
											2008-11-30 11:12:08 -05:00
										 |  |  |         "localhost" "p" get ?promise <inet> smtp-server set
 | 
					
						
							| 
									
										
										
										
											2008-11-30 14:53:13 -05:00
										 |  |  |         no-auth smtp-auth set
 | 
					
						
							| 
									
										
										
										
											2008-11-30 16:11:03 -05:00
										 |  |  |         os unix? [ smtp-tls? on ] when
 | 
					
						
							| 
									
										
										
										
											2008-02-07 02:03:27 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-07 02:55:38 -05:00
										 |  |  |         <email> | 
					
						
							|  |  |  |             "Hi guys\nBye guys" >>body | 
					
						
							|  |  |  |             "Factor rules" >>subject | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 "Slava <slava@factorcode.org>" | 
					
						
							|  |  |  |                 "Ed <dharmatech@factorcode.org>" | 
					
						
							|  |  |  |             } >>to | 
					
						
							|  |  |  |             "Doug <erg@factorcode.org>" >>from | 
					
						
							| 
									
										
										
										
											2008-03-11 04:35:43 -04:00
										 |  |  |         send-email | 
					
						
							| 
									
										
										
										
											2008-11-30 16:11:03 -05:00
										 |  |  |     ] with-secure-context | 
					
						
							| 
									
										
										
										
											2008-03-06 14:46:15 -05:00
										 |  |  | ] unit-test |