X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=lambdamail.git;a=blobdiff_plain;f=lambdamail.scm;h=c5b18c61b872331ce283af30072df818ceba08a8;hp=25454e15d8bbed3a40a1bb2f54bedd8773700cd9;hb=aaad78011516497f884f8ffc5a10d891e9641eee;hpb=388c4d83a62d86384b925e112c7106d4e739bd55 diff --git a/lambdamail.scm b/lambdamail.scm index 25454e1..c5b18c6 100644 --- a/lambdamail.scm +++ b/lambdamail.scm @@ -17,7 +17,7 @@ (chicken sort) srfi-1 srfi-13 matchable base64) -(define lambdamail-version "LambdaMail v1.1.0") +(define lambdamail-version "LambdaMail v1.2.0") (define-record config host port spool-dir user group) (define-record message to from text user password) @@ -250,18 +250,18 @@ (let-values (((tcp-in tcp-out) (tcp-connect mail-server 25))) (let ((smtp-session (make-outgoing-smtp-session tcp-in tcp-out))) (let ((result (and - (smtp-session 'expect "220") + (smtp-session 'expect "2") (smtp-session 'send "helo " (config-host config)) - (smtp-session 'expect "250") + (smtp-session 'expect "2") (smtp-session 'send "mail from:" (message-from msg)) - (smtp-session 'expect "250") + (smtp-session 'expect "2") (smtp-session 'send "rcpt to:" (message-to msg)) - (smtp-session 'expect "250") + (smtp-session 'expect "2") (smtp-session 'send "data") (smtp-session 'expect "354") (smtp-session 'send (message-text msg)) (smtp-session 'send ".") - (smtp-session 'expect "250") + (smtp-session 'expect "2" "5") ;Do not try again on rejects. (smtp-session 'send "quit")))) (close-input-port tcp-in) (close-output-port tcp-out) @@ -271,12 +271,15 @@ (print "* REMOTE DELIVERY FAILED (unexpected server response)")) result))))) +(define (or-list l) + (fold (lambda (a b) (or a b)) #f l)) + (define ((make-outgoing-smtp-session tcp-in tcp-out) . command) (match command - (('expect code) + (('expect codes ...) (let ((result (read-line tcp-in))) - (print "Expecting " code " got " result) - (string-prefix? code result))) + (print "Expecting one of " codes " got " result) + (or-list (map (lambda (code) (string-prefix? code result)) codes)))) (('send strings ...) (print "Sending " (if (> (string-length (car strings)) 30) (string-take (car strings) 30) @@ -293,11 +296,15 @@ (define (print-usage progname) (print "Usage:\n" progname " -h/--help\n" + progname " -v/--version\n" progname " [-u/--user UID] [-g/--group GID] hostname [[port [spooldir]]\n" "\n" "The -u and -g options can be used to set the UID and GID of the process\n" "following the creation of the TCP port listener (which often requires root).")) +(define (print-version) + (print lambdamail-version)) + (define (main) (let ((progname (pathname-file (car (argv)))) (config (make-config "" 25 "/var/spool/mail" '() '()))) @@ -319,6 +326,9 @@ ((or (equal? this-arg "-h") (equal? this-arg "--help")) (print-usage progname)) + ((or (equal? this-arg "-v") + (equal? this-arg "--version")) + (print-version)) (else (print "Unknown option " this-arg "\n") (print-usage progname))) @@ -333,4 +343,4 @@ (main) ;; (define (test) -;; (run-server (make-config "localhost" 2525 "spool" '() '()))) + ;; (run-server (make-config "localhost" 2525 "spool" '() '())))