You are looking at historical revision 15892 of this page. It may differ significantly from its current revision.
smtp
Description
smtp is a collection of parser combinators and state machine primitives for the grammar defined in RFC 5321 (Simple Mail Transfer Protocol).
Data Types for SMTP Commands
(define-datatype cmd cmd? (Helo (s string?)) (Ehlo (s string?)) (MailFrom (m mailbox?) (parameters list?)) (RcptTo (m mailbox?) (parameters list?)) (Data) (Rset) (Send (m mailbox?)) (Soml (m mailbox?)) (Saml (m mailbox?)) (Vrfy (s string?)) (Expn (s string?)) (Help (s string?)) (Noop) (Quit) (Turn) (WrongArg (cmd string?) (message string?))) (define-datatype mailbox mailbox? (Mailbox (local-part string?) (domain string?)))
Data Types for SMTP Replies
(define-datatype reply reply? (Reply (code code?) (msg list?))) (define-enumerated-type success-code success-code? success-vector success-code-inject success-code-project (Unused) (PreliminarySuccess) (Success) (IntermediateSuccess) (TransientFailure) (PermanentFailure)) (define-enumerated-type category category? category-vector category-inject category-project (Syntax) (Information) (Connection) (Unspecified3) (Unspecified4) (MailSystem)) (define-datatype code code? (Code (suc success-code?) (cat category?) (num integer?)))
An SMTP reply is a three-digit return code plus comments. This is what the list of strings is for; one string per line in the reply. the record printer will ppend an CRLF end-of-line marker to each entry in that list, so that the resulting string is ready to be sent back to the peer.
For example:
> (print (Reply (Code (Success) (MailSystem) 0) (list "worked" "like" "a charm"))) 250-worked 250-like 250 a charm
Command Parsers
(define (parse-cmd cont)
ESMTP State Machine
start-session session-fsm? (define-datatype session-state session-state? (Unknown) (HaveHelo) (HaveMailFrom) (HaveRcptTo) (HaveData) (HaveQuit)) (define-datatype event event? (SayHelo (s string?)) (SayHeloAgain (s string?)) (SayEhlo (s string?)) (SayEhloAgain (s string?)) (SetMailFrom (m mailbox?) (parameters? list)) (AddRcptTo (m mailbox?) (parameters? list)) (StartData) (NeedHeloFirst) (NeedMailFromFirst) (NeedRcptToFirst) (NotImplemented) ;; Turn, Send, Soml, Saml, Vrfy, Expn. (ResetState) (SayOK) (SeeksHelp (s string?)) (Shutdown) (SyntaxErrorIn (s string?)) (Unrecognized (s string?)))
Requires
Version History
- 1.0 Initial release
License
Based on the Haskell Rfc2821 module by Peter Simons.
Copyright 2009 Ivan Raikov. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.