Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Types for use with SMTP.
Notes
Some notes on the underlying bits of the SMTP protocol they model (see RFC 5321 for more details):
- The protocol consists of commands and replies.
Replies can be single-line or multiline. Single lines start with
<reply-code> <SP>
; for multiple lines, every line except the last starts with<reply-code> '-'
, and the last is a single line.The
<SP>
or'-'
can be followed by optional text. OurReplyLine
andReply
store the code and the optional text (or an empty string if there was none), but not the<SP>
or'-'
separator.- A reply is a list of one or more of these reply lines; but we just represent it as a list; it's an invariant that such a list should never be empty (and the parser promises never to return an empty list).
Synopsis
- type ReplyCode = Int
- type Reply = [ReplyLine]
- data ReplyLine = ReplyLine {
- replyCode :: !ReplyCode
- replyText :: !ByteString
- data SmtpCommand
- = HELO ByteString
- | EHLO ByteString
- | MAIL ByteString
- | RCPT ByteString
- | DATA
- | EXPN ByteString
- | VRFY ByteString
- | HELP (Maybe ByteString)
- | NOOP
- | RSET
- | QUIT
- | STARTTLS
- data SmtpError
- = UnexpectedResponse { }
- | ParseError String
- toByteString :: SmtpCommand -> ByteString
Documentation
One line of a reply from a server, consisting of a ReplyCode
and US-ASCII message.
ReplyLine | |
|
data SmtpCommand Source #
SMTP commands. This type does not
include the 'AUTH
' command, which
has a flexible form.
HELO ByteString | |
EHLO ByteString | |
MAIL ByteString | |
RCPT ByteString | |
DATA | |
EXPN ByteString | |
VRFY ByteString | |
HELP (Maybe ByteString) | |
NOOP | |
RSET | |
QUIT | |
STARTTLS |
Instances
Eq SmtpCommand Source # | |
Defined in Network.Mail.Assumpta.Types (==) :: SmtpCommand -> SmtpCommand -> Bool # (/=) :: SmtpCommand -> SmtpCommand -> Bool # | |
Show SmtpCommand Source # | |
Defined in Network.Mail.Assumpta.Types showsPrec :: Int -> SmtpCommand -> ShowS # show :: SmtpCommand -> String # showList :: [SmtpCommand] -> ShowS # |
Errors that can occur during SMTP operations.
These don't include connectivity and other IO errors which might occur in the underlying transport mechanism; those should be handled elsewhere (if necessary).
The possible errors are that either (a) we couldn't parse the server's response at all, or (b) we could, but it wasn't what we expected.
UnexpectedResponse | We received a response contrary to what we expected. The first field is a description of what we expected, the second of what we got. |
ParseError String | We couldn't parse the server's
response; the parser gave the
error message contained in the |
Instances
Show SmtpError Source # | |
Monad m => MonadError SmtpError (SmtpT conn m) # | |
Defined in Network.Mail.Assumpta.Trans.Smtp throwError :: SmtpError -> SmtpT conn m a # catchError :: SmtpT conn m a -> (SmtpError -> SmtpT conn m a) -> SmtpT conn m a # |
toByteString :: SmtpCommand -> ByteString Source #
Dump an SMTP command to a bytestring, suitable for transmission to a server. No CRLF is appended.
For commands like 'MAIL FROM:<somesender@somedomain>
':
this adds in the 'FROM:<' etc
>>>
:set -XOverloadedStrings
>>>
toByteString $ HELO "my-computer.org"
"HELO my-computer.org">>>
toByteString $ MAIL "some-sender@my-org.com"
"MAIL FROM:<some-sender@my-org.com>">>>
toByteString $ RCPT "delighted-recipient@dunder-mifflin.com"
"RCPT TO:<delighted-recipient@dunder-mifflin.com>"