- (when (string? line)
- (print "got " line)
- (cond
- ((smtp-command? "helo" line)
- (smtp-session 'set-helo! (smtp-command-args "helo" line))
- (smtp-session 'send "250 ok")
- (loop msg 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 msg 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)))
- (smtp-session 'set-user! user)
- (smtp-session 'set-password! password)
- (print "Attempted login, user: " user ", password: " password)
- (smtp-session 'send "235 authentication successful")
- (loop msg received-messages)))
- ((smtp-command? "mail from:" line)
- (message-from-set! msg (smtp-command-args "mail from:" line))
- (smtp-session 'send "250 ok")
- (loop msg received-messages))
- ((smtp-command? "rcpt to:" line)
- (message-to-set! msg (smtp-command-args "rcpt to:" line))
- (smtp-session 'send "250 ok")
- (loop msg received-messages))
- ((smtp-command? "data" line)
- (smtp-session 'send "354 intermediate")
- (let text-loop ((text (conc "Received: from " (smtp-session 'helo) "\n"
- " by " (config-host config) "\n"
- " for " (message-from msg)
- "; " (time-stamp) "\n")))
- (let ((text-line (smtp-session 'get-line)))
- (if (string=? "." text-line)
- (message-text-set! msg text)
- (text-loop (conc text text-line "\n")))))
- (message-user-set! msg (smtp-session 'user))
- (message-password-set! msg (smtp-session 'password))
- (smtp-session 'send "250 ok")
- (loop (make-empty-message) (cons msg received-messages)))
- ((smtp-command? "quit" line)
- (smtp-session 'send "221 closing transmission channel")
- received-messages)
- ((string=? "" (string-trim line))
- (loop msg received-messages))
- (else
- (smtp-session 'send "502 command not implemented")
- (loop msg received-messages)))))))
-
-
-;;; Sending/Delivering messages
-;;
-
-(define (deliver-messages config messages)
- (print "\n"
- "**** Attempting delivery of " (length messages) " mail items.")
- (filter (lambda (msg) (not (deliver-message msg config)))
- messages))
-
-(define (deliver-message msg config)
- (condition-case
- (begin
- (let* ((local-addresses (get-local-addresses config))
- (dest (assoc (message-to msg) local-addresses))
- (orig (assoc (message-from msg) local-addresses)))