- (let loop ((msg (make-empty-message)))
- (let ((line-orig (smtp-session 'get-line)))
- (if (string? line-orig)
- (let ((line (string-downcase line-orig)))
- (print "got " line-orig)
- (cond
- ((string-prefix? "helo" line)
- (message-helo-set! msg (string-drop line (string-length "helo")))
- (smtp-session 'ok)
- (loop msg))
- ((string-prefix? "ehlo" line)
- (smtp-session 'ehlo (string-drop line (+ 1 (string-length "ehlo"))))
- (loop msg))
- ((string-prefix? "auth plain" line)
- (let* ((auth-string (string-drop line-orig (+ 1 (string-length "auth plain"))))
- (auth-decoded (base64-decode auth-string))
- (auth-list (string-split auth-decoded "\x00"))
- (user (car auth-list))
- (password (cadr auth-list)))
- (smtp-session 'set-user! user)
- (smtp-session 'set-password! password)
- (print "Attempted login, user: " user ", password: " password)
- (smtp-session 'auth-success)
- (loop msg)))
- ((string-prefix? "mail from:" line)
- (message-from-set! msg (string-drop line (string-length "mail from:")))
- (smtp-session 'ok)
- (loop msg))
- ((string-prefix? "rcpt to:" line)
- (message-to-set! msg (string-drop line (string-length "rcpt to:")))
- (smtp-session 'ok)
- (loop msg))
- ((string-prefix? "data" line)
- (smtp-session 'intermediate)
- (let text-loop ((text-line (smtp-session 'get-line))
- (text ""))
+ (smtp-session 'send "220 " (config-host config) " " lambdamail-version)
+ (let loop ((mmsg (make-empty-multi-message))
+ (received-messages '()))
+ (let ((line (smtp-session 'get-line)))
+ (print "got " line)
+ (if (not (string? line))
+ '() ; Don't keep anything on unexpected termination.
+ (cond
+ ((smtp-command? "helo" line)
+ (smtp-session 'set-helo! (smtp-command-args "helo" line))
+ (smtp-session 'send "250 ok")
+ (loop mmsg received-messages))
+ ((smtp-command? "ehlo" line)
+ (smtp-session 'set-helo! (smtp-command-args "helo" line))
+ (smtp-session 'send
+ "250-" (config-host config)
+ " Hello " (smtp-command-args "ehlo" line))
+ (smtp-session 'send "250 AUTH PLAIN")
+ ;; (smtp-session 'send "250 STARTTLS")
+ (loop mmsg received-messages))
+ ((smtp-command? "auth plain" line)
+ (let* ((auth-string (smtp-command-args "auth plain" line))
+ (auth-decoded (base64-decode auth-string))
+ (auth-list (string-split auth-decoded "\x00"))
+ (user (car auth-list))
+ (password (cadr auth-list)))
+ (multi-message-user-set! mmsg user)
+ (multi-message-password-set! mmsg password)
+ (print "Attempted login, user: " user ", password: " password)
+ (smtp-session 'send "235 authentication successful")
+ (loop mmsg received-messages)))
+ ((smtp-command? "mail from:" line)
+ (multi-message-from-set! mmsg (smtp-command-args "mail from:" line))
+ (smtp-session 'send "250 ok")
+ (loop mmsg received-messages))
+ ((smtp-command? "rcpt to:" line)
+ (let* ((to (smtp-command-args "rcpt to:" line))
+ (stamp (make-message-stamp to mmsg config)))
+ (print to)
+ (if (car stamp)
+ (begin
+ (multi-message-tos-set! mmsg (cons to (multi-message-tos mmsg)))
+ (multi-message-stamps-set! mmsg (cons stamp (multi-message-stamps mmsg)))
+ (smtp-session 'send "250 ok"))
+ (begin
+ (smtp-session 'send "551 relay forbidden"))))
+ (loop mmsg received-messages))
+ ((smtp-command? "data" line)
+ (smtp-session 'send "354 intermediate")
+ (let text-loop ((text ""))
+ (let ((text-line (smtp-session 'get-line)))