-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Client support for POP3, SMTP, and IMAP -- -- This package provides client support for the POP3, SMTP, and IMAP -- protocols. -- -- Full examples can be found in the repository. Additional -- documentation on the major updates can be found in the -- Updating.md file @package HaskellNet @version 0.6.0.1 module Network.HaskellNet.Auth type UserName = String type Password = String -- | Authorization types supported by the RFC5954 data AuthType PLAIN :: AuthType LOGIN :: AuthType CRAM_MD5 :: AuthType b64Encode :: String -> String b64Decode :: String -> String showOctet :: [Word8] -> String hashMD5 :: [Word8] -> [Word8] hmacMD5 :: String -> String -> [Word8] plain :: UserName -> Password -> String login :: UserName -> Password -> (String, String) cramMD5 :: String -> UserName -> Password -> String auth :: AuthType -> String -> UserName -> Password -> String instance GHC.Classes.Eq Network.HaskellNet.Auth.AuthType instance GHC.Show.Show Network.HaskellNet.Auth.AuthType -- | This module provides a byte string "stream" interface. This interface -- provides some common operations on a value which supports reading and -- writing byte strings. module Network.HaskellNet.BSStream -- | A byte string stream. data BSStream BSStream :: IO ByteString -> (Int -> IO ByteString) -> (ByteString -> IO ()) -> IO () -> IO () -> IO Bool -> (Int -> IO Bool) -> BSStream -- | Read a line from the stream. Should return the line which was read, -- including the newline. [bsGetLine] :: BSStream -> IO ByteString -- | Read the specified number of bytes from the stream. Should block until -- the requested bytes can be read. [bsGet] :: BSStream -> Int -> IO ByteString -- | Write the specified byte string to the stream. Should flush the stream -- after writing. [bsPut] :: BSStream -> ByteString -> IO () -- | Flush the stream. [bsFlush] :: BSStream -> IO () -- | Close the stream. [bsClose] :: BSStream -> IO () -- | Is the stream open? [bsIsOpen] :: BSStream -> IO Bool -- | Is data available? [bsWaitForInput] :: BSStream -> Int -> IO Bool -- | Build a byte string stream which operates on a Handle. handleToStream :: Handle -> BSStream module Network.HaskellNet.Debug debugStream :: BSStream -> BSStream module Network.HaskellNet.POP3.Connection data POP3Connection stream :: POP3Connection -> BSStream newConnection :: BSStream -> String -> POP3Connection -- | APOP key apopKey :: POP3Connection -> String module Network.HaskellNet.POP3.Types data Command USER :: UserName -> Command PASS :: Password -> Command APOP :: UserName -> Password -> Command AUTH :: AuthType -> UserName -> Password -> Command NOOP :: Command QUIT :: Command STAT :: Command LIST :: Maybe Int -> Command DELE :: Int -> Command RETR :: Int -> Command RSET :: Command TOP :: Int -> Int -> Command UIDL :: Maybe Int -> Command data Response Ok :: Response Err :: Response instance GHC.Show.Show Network.HaskellNet.POP3.Types.Response instance GHC.Classes.Eq Network.HaskellNet.POP3.Types.Response module Network.HaskellNet.POP3 -- | connecting to the pop3 server specified by the hostname and port -- number connectPop3Port :: String -> PortNumber -> IO POP3Connection -- | connecting to the pop3 server specified by the hostname. 110 is used -- for the port number. connectPop3 :: String -> IO POP3Connection -- | connecting to the pop3 server via a stream connectStream :: BSStream -> IO POP3Connection -- | sendCommand sends a pop3 command via a pop3 connection. This action is -- too generic. Use more specific actions sendCommand :: POP3Connection -> Command -> IO (Response, ByteString) closePop3 :: POP3Connection -> IO () user :: POP3Connection -> String -> IO () pass :: POP3Connection -> String -> IO () userPass :: POP3Connection -> UserName -> Password -> IO () apop :: POP3Connection -> String -> String -> IO () auth :: POP3Connection -> AuthType -> UserName -> Password -> IO () stat :: POP3Connection -> IO (Int, Int) dele :: POP3Connection -> Int -> IO () retr :: POP3Connection -> Int -> IO ByteString top :: POP3Connection -> Int -> Int -> IO ByteString rset :: POP3Connection -> IO () allList :: POP3Connection -> IO [(Int, Int)] list :: POP3Connection -> Int -> IO Int allUIDLs :: POP3Connection -> IO [(Int, ByteString)] uidl :: POP3Connection -> Int -> IO ByteString doPop3Port :: String -> PortNumber -> (POP3Connection -> IO a) -> IO a doPop3 :: String -> (POP3Connection -> IO a) -> IO a doPop3Stream :: BSStream -> (POP3Connection -> IO b) -> IO b -- | Authorization types supported by the RFC5954 data AuthType PLAIN :: AuthType LOGIN :: AuthType CRAM_MD5 :: AuthType -- | Internal functions that are used in the SMTP protocol, you may need -- these module in case if you want to implement additional functionality -- that does not exist in the Network.HaskellNet.SMTP. -- -- Example. -- -- One example could be sending multiple emails over the same stream in -- order to use that you may want to use RSET command, so you can -- implement: -- --
-- import Network.HaskellNet.SMTP.Internal -- -- resetConnection :: SMTPConnection -> IO () -- resetConnection conn = do -- (code, _) <- sendCommand conn RSET -- unless (code == 250) $ throwIO $ UnexpectedReply RSET [250] code "" --module Network.HaskellNet.SMTP.Internal -- | All communication with server is done using SMTPConnection -- value. data SMTPConnection SMTPC :: !BSStream -> ![ByteString] -> SMTPConnection -- | Connection communication channel. [bsstream] :: SMTPConnection -> !BSStream -- | Server properties as per reply to the EHLO request. [_response] :: SMTPConnection -> ![ByteString] -- | SMTP commands. -- -- Supports basic and extended SMTP protocol without TLS support. -- -- For each command we provide list of the expected reply codes that -- happens in success and failure cases respectively. data Command -- | The HELO command initiates the SMTP session conversation. The -- client greets the server and introduces itself. As a rule, HELO is -- attributed with an argument that specifies the domain name or IP -- address of the SMTP client. -- -- Success: 250 Failure: 504, 550 HELO :: Text -> Command -- | EHLO is an alternative to HELO for servers that support the -- SMTP service extensions (ESMTP) -- -- Success: 250 Failure: 502, 504, 550 EHLO :: Text -> Command -- | MAIL FROM command initiates a mail transfer. As an argument, -- MAIL FROM includes a sender mailbox (reverse-path) can accept optional -- parameters. -- -- Success: 250 -- -- Failure: 451, 452, 455, 503, 550, 552, 553, 555 MAIL :: Text -> Command -- | The RCPT TO command specifies exactly one recipient. -- -- Success: 250 251 -- -- Failure: 450 451 452 455 503 550 551 552 553 555 RCPT :: Text -> Command -- | With the DATA command, the client asks the server for -- permission to transfer the mail data. -- -- Success: 250, 354 -- -- Failure: 450 451 452 503 550 552 554 -- -- Client just sends data and after receiving 354 starts streaming email, -- terminating transfer by sending rn.rn. DATA :: ByteString -> Command -- | EXPN is used to verify whether a mailing list in the argument -- exists on the local host. The positive response will specify the -- membership of the recipients. -- -- Success: 250 252 -- -- Failure: 502 504 550 EXPN :: Text -> Command -- | VRFY is used to verify whether a mailbox in the argument -- exists on the local host. The server response includes the user’s -- mailbox and may include the user’s full name. -- -- Success: 250 251 252 -- -- Failure: 502 504 550 551 553 VRFY :: Text -> Command -- | With the HELP command, the client requests a list of commands -- the server supports, may request help for specific command -- -- Success: 211 214 -- -- Failure: 502 504 HELP :: Text -> Command -- | Authorization support AUTH :: AuthType -> UserName -> Password -> Command -- | NOOP can be used to verify if the connection is alive -- -- Success: 250 NOOP :: Command -- | RSET Resets the state -- -- Success: 250 RSET :: Command -- | QUIT asks server to close connection. Client should terminate -- the connection when receives status. -- -- Success: 221 QUIT :: Command -- | Exceptions that can happen during communication. data SMTPException -- | Reply code was not in the list of expected. -- --
-- "250-8BITMIME\r" -- "250-PIPELINING\r" -- "250-SIZE 42991616\r" -- "250-AUTH LOGIN PLAIN XOAUTH2\r" -- "250-DSN\r" -- "250 ENHANCEDSTATUSCODES\r" ---- -- Returns: -- --
-- (250, "8BITMIME\nPIPELININGnSIZE 42991616\nAUTH LOGIN PLAIN XOAUTH2\nDSN\nENHANCEDSTATUSCODES") ---- -- Throws SMTPException. parseResponse :: BSStream -> IO (ReplyCode, ByteString) -- | Sends a Command to the server. Function that performs all the -- logic for sending messages. Throws an exception if something goes -- wrong. -- -- Throws SMTPException. sendCommand :: SMTPConnection -> Command -> IO (ReplyCode, ByteString) -- | Sends a mail to the server. -- -- Throws SMTPException. sendMailData :: Address -> [Address] -> ByteString -> SMTPConnection -> IO () -- | Terminates the connection. Quit command is not send in this -- case. It's safe to issue this command at any time if the connection is -- still open. closeSMTP :: SMTPConnection -> IO () -- | Gracefully closes SMTP connection. Connection should be in available -- state. First it sends quit command and then closes connection itself. -- Connection should not be used after this command exits (even if it -- exits with an exception). This command may throw an exception in case -- of network failure or protocol failure when sending QUIT -- command. If it happens connection nevertheless is closed. gracefullyCloseSMTP :: SMTPConnection -> IO () -- | Sends quit to the server. Connection must be terminated afterwards, -- i.e. it's not allowed to issue any command on this connection. quitSMTP :: SMTPConnection -> IO () data Address Address :: Maybe Text -> Text -> Address [addressName] :: Address -> Maybe Text [addressEmail] :: Address -> Text instance GHC.Classes.Eq Network.HaskellNet.SMTP.Internal.Command instance GHC.Show.Show Network.HaskellNet.SMTP.Internal.Command instance GHC.Show.Show Network.HaskellNet.SMTP.Internal.SMTPException instance GHC.Exception.Type.Exception Network.HaskellNet.SMTP.Internal.SMTPException -- | This module provides functions client side of the SMTP protocol. -- -- A basic usage example: -- --
-- {-# LANGUAGE OverloadedStrings #-}
-- import Network.HaskellNet.SMTP
-- import Network.HaskellNet.Auth
-- import Network.Mail.Mime
-- import System.Exit (die)
--
-- main :: IO ()
-- main = doSMTP "your.smtp.server.com" $ \conn -> do -- (1)
-- authSucceed <- authenticate PLAIN "username" "password" conn -- (2)
-- if authSucceed
-- then do
-- let mail = simpleMail'
-- "receiver@server.com"
-- "sender@server.com"
-- "subject"
-- "Hello! This is the mail body!"
-- sendMail mail conn -- (3)
-- else die "Authentication failed."
--
--
-- Notes for the above example:
--
--
-- {-# LANGUAGE OverloadedStrings #-}
-- authSucceed <- authenticate PLAIN "username" "password" conn
-- if authSucceed
-- then sendPlainTextMail "receiver@server.com" "sender@server.com" "subject" "Hello!" conn
-- else print "Authentication failed."
--
authenticate :: AuthType -> UserName -> Password -> SMTPConnection -> IO Bool
-- | Authorization types supported by the RFC5954
data AuthType
PLAIN :: AuthType
LOGIN :: AuthType
CRAM_MD5 :: AuthType
-- | Sends email using Mail type from the mime-mail package.
--
-- Sender is taken from the mailFrom field of the mail.
-- Message is sent to all the recipients in the mailTo,
-- mailCc, mailBcc fields. But mailBcc emails are
-- not visible to other recipients as it should be.
sendMail :: HasCallStack => Mail -> SMTPConnection -> IO ()
-- | Send a plain text mail.
--
-- DEPRECATED. Instead of sendPlainTextMail to from subject
-- plainBody use:
--
-- -- mail = simpleMail' to from subject plainBody -- sendMail mail conn ---- | Deprecated: Use 'sendMail (Network.Mail.Mime.simpleMail' to from -- subject plainBody)' instead sendPlainTextMail :: Address -> Address -> Text -> Text -> SMTPConnection -> IO () -- | Send a mime mail. The attachments are included with the file path. -- -- DEPRECATED. Instead of sendMimeMail to from subject -- plainBody htmlBody attachments use: -- --
-- mail <- simpleMail to from subject plainBody htmlBody attachments -- sendMail mail conn ---- | Deprecated: Use 'Network.Mail.Mime.simpleMail to from subject -- plainBody htmlBody attachments >>= mail -> sendMail mail -- conn' instead sendMimeMail :: Address -> Address -> Text -> Text -> Text -> [(Text, FilePath)] -> SMTPConnection -> IO () -- | Send a mime mail. The attachments are included with in-memory -- ByteString. -- -- DEPRECATED. Instead of sendMimeMail to from subject -- plainBody htmlBody attachments use: -- --
-- let mail = Network.Mail.Mime.simpleMailInMemory to from subject plainBody htmlBody attachments -- sendMail mail conn ---- | Deprecated: Use 'sendMail (Network.Mail.Mime.simpleMailInMemory to -- from subject plainBody htmlBody attachments) conn' sendMimeMail' :: Address -> Address -> Text -> Text -> Text -> [(Text, Text, ByteString)] -> SMTPConnection -> IO () -- | Sends email in generated using 'mime-mail' package. -- -- Throws UserError :: IOError if recipient -- address not specified. -- | Deprecated: Use sendMail instead sendMimeMail2 :: HasCallStack => Mail -> SMTPConnection -> IO () -- | connecting SMTP server with the specified name and port number. connectSMTPPort :: String -> PortNumber -> IO SMTPConnection -- | connecting SMTP server with the specified name and port 25. connectSMTP :: String -> IO SMTPConnection -- | Create SMTPConnection from already connected Stream -- -- Throws CantConnect :: SMTPException in case if got illegal -- greeting. connectStream :: HasCallStack => BSStream -> IO SMTPConnection -- | Terminates the connection. Quit command is not send in this -- case. It's safe to issue this command at any time if the connection is -- still open. closeSMTP :: SMTPConnection -> IO () -- | Gracefully closes SMTP connection. Connection should be in available -- state. First it sends quit command and then closes connection itself. -- Connection should not be used after this command exits (even if it -- exits with an exception). This command may throw an exception in case -- of network failure or protocol failure when sending QUIT -- command. If it happens connection nevertheless is closed. gracefullyCloseSMTP :: SMTPConnection -> IO () -- | Exceptions that can happen during communication. data SMTPException -- | Reply code was not in the list of expected. -- --