-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Parsing and rendering of email and MIME headers -- -- Parsing and rendering of email and MIME headers @package email-header @version 0.4.0 -- | Email header types. module Network.Email.Header.Types -- | An email header name. type HeaderName = CI ByteString -- | An email header. type Header = (HeaderName, ByteString) -- | A set of email headers, in order. type Headers = [Header] -- | An email address. newtype Address Address :: ByteString -> Address -- | A Mailbox receives mail. data Mailbox Mailbox :: Maybe Text -> Address -> Mailbox [displayName] :: Mailbox -> Maybe Text [mailboxAddress] :: Mailbox -> Address -- | A Recipient is used to indicate senders and recipients of -- messages. It may either be an individual Mailbox, or a named -- group of Mailboxes. data Recipient Individual :: Mailbox -> Recipient Group :: Text -> [Mailbox] -> Recipient -- | A message identifier, which has a similar format to an email address. newtype MessageID MessageID :: ByteString -> MessageID -- | A MIME type. data MimeType MimeType :: CI ByteString -> CI ByteString -> MimeType [mimeType] :: MimeType -> CI ByteString [mimeSubtype] :: MimeType -> CI ByteString -- | MIME content type parameters. type Parameters = Map (CI ByteString) ByteString -- | Email header exceptions. data HeaderException -- | A required header is missing. MissingHeader :: HeaderName -> HeaderException -- | A header field could not be parsed. HeaderParseError :: Header -> String -> HeaderException instance GHC.Show.Show Network.Email.Header.Types.HeaderException instance GHC.Show.Show Network.Email.Header.Types.MimeType instance GHC.Classes.Ord Network.Email.Header.Types.MimeType instance GHC.Classes.Eq Network.Email.Header.Types.MimeType instance GHC.Show.Show Network.Email.Header.Types.MessageID instance GHC.Classes.Ord Network.Email.Header.Types.MessageID instance GHC.Classes.Eq Network.Email.Header.Types.MessageID instance GHC.Show.Show Network.Email.Header.Types.Recipient instance GHC.Classes.Eq Network.Email.Header.Types.Recipient instance GHC.Show.Show Network.Email.Header.Types.Mailbox instance GHC.Classes.Eq Network.Email.Header.Types.Mailbox instance GHC.Show.Show Network.Email.Header.Types.Address instance GHC.Classes.Ord Network.Email.Header.Types.Address instance GHC.Classes.Eq Network.Email.Header.Types.Address instance GHC.Exception.Exception Network.Email.Header.Types.HeaderException -- | A layout that keeps track of line positions. module Network.Email.Header.Layout -- | An abstract type representing a lazy layout. data Layout a -- | Run a layout with an initial position. layout :: Monoid a => Int -> Layout a -> a -- | Layout an element of a given length. span :: Monoid a => Int -> a -> Layout a -- | Layout a new line and set the initial position. break :: Int -> Layout a -- | Use the current line position to produce a layout. position :: (Int -> Layout a) -> Layout a -- | Choose the first layout if the first line fits within the given -- length, and the second otherwise. nicest :: Int -> Layout a -> Layout a -> Layout a instance GHC.Base.Monoid (Network.Email.Header.Layout.Layout a) -- | Charset conversions. module Network.Email.Charset -- | A charset. Charset names are compared fuzzily e.g. UTF-8 is -- equivalent to utf8. data Charset -- | The name of a charset. charsetName :: Charset -> String -- | All canonical charset names and aliases. charsets :: Set Charset -- | Lookup a charset from a name or alias, or Nothing if no such -- charset exists. lookupCharset :: String -> Maybe Charset -- | The default charset, UTF-8. defaultCharset :: Charset -- | Convert a Unicode string into a codepage string. fromUnicode :: Charset -> Text -> ByteString -- | Convert a codepage string into a Unicode string. toUnicode :: Charset -> ByteString -> Text instance GHC.Show.Show Network.Email.Charset.Charset instance GHC.Classes.Eq Network.Email.Charset.Charset instance GHC.Classes.Ord Network.Email.Charset.Charset -- | Header formatting and pretty-printing. module Network.Email.Header.Doc -- | Rendering options. data RenderOptions RenderOptions :: Int -> Int -> Charset -> Encoding -> RenderOptions -- | The maximum line width. [lineWidth] :: RenderOptions -> Int -- | The indent of each line, in spaces. [indent] :: RenderOptions -> Int -- | The charset used to encode text outside US-ASCII range. [charset] :: RenderOptions -> Charset -- | The header encoding used for encoded words. [encoding] :: RenderOptions -> Encoding -- | The encoding used for binary characters in an encoded word. data Encoding -- | Quoted-printable encoding. Spaces are represented with underscores, -- and undisplayable characters are represented as hex pairs. QP :: Encoding -- | Base 64 encoding of all characters. Base64 :: Encoding -- | Default rendering options, which uses a line width of 80, and indent -- of 2, and utf-8 quated-printable encoding. defaultRenderOptions :: RenderOptions -- | A formatted email header. data Doc -- | Render a document with the given options and initial position. render :: RenderOptions -> Int -> Doc -> Builder -- | Construct a primitive document from a layout function. The function -- takes two parameters: the rendering options, and a Bool which -- indicates whether the containing group is laid out horizontally -- instead of vertically. prim :: (RenderOptions -> Bool -> Layout Builder) -> Doc -- | Specify an alternative layout with all line breaks flattened. group :: Doc -> Doc -- | Construct a Doc from a Builder and a length. builder :: Int -> Builder -> Doc -- | Construct a Doc from a String. string :: String -> Doc -- | Construct a Doc from a ByteString. byteString :: ByteString -> Doc -- | Construct a Builder from a Text. text :: Text -> Doc -- | A space layout. space :: Layout Builder -- | A newline layout. This will emit a CRLF pair, break to a new -- line, and indent. newline :: RenderOptions -> Layout Builder -- | A line break. If undone, behaves like a space. line :: Doc -- | A line break. If undone, behaves like mempty. linebreak :: Doc -- | A space if the remaining layout fits, and a line break otherwise. softline :: Doc -- | mempty if the remaining layout fits, and a line break -- otherwise. softbreak :: Doc -- | Concatenate with a softline in between. () :: Doc -> Doc -> Doc infixr 6 -- | Separate a list with spaces if it fits. Otherwise, separate with -- lines. sep :: [Doc] -> Doc -- | punctuate p xs appends p to every element of -- xs but the last. punctuate :: Monoid a => a -> [a] -> [a] instance GHC.Show.Show Network.Email.Header.Doc.RenderOptions instance GHC.Classes.Eq Network.Email.Header.Doc.RenderOptions instance GHC.Enum.Bounded Network.Email.Header.Doc.Encoding instance GHC.Enum.Enum Network.Email.Header.Doc.Encoding instance GHC.Show.Show Network.Email.Header.Doc.Encoding instance GHC.Read.Read Network.Email.Header.Doc.Encoding instance GHC.Classes.Ord Network.Email.Header.Doc.Encoding instance GHC.Classes.Eq Network.Email.Header.Doc.Encoding instance GHC.Base.Monoid Network.Email.Header.Doc.Doc instance Data.String.IsString Network.Email.Header.Doc.Doc -- | Header parsers. Most exported parsers (with the exception of -- fws, cfws, and unstructured) are for parsing -- structured header fields. They expect no leading space and will eat an -- trailing white space. module Network.Email.Header.Parser -- | Skip folding whitespace. fws :: Parser () -- | Skip any comments or folding whitespace. cfws :: Parser () -- | Parse a value followed by whitespace. lexeme :: Parser a -> Parser a -- | Parse a character followed by whitespace. symbol :: Char -> Parser Char -- | Parse a list of elements, separated by commas. commaSep :: Parser a -> Parser [a] -- | Parse a date and time. TODO: non-numeric timezones (such as "PDT") are -- considered equivalent to UTC time. dateTime :: Parser ZonedTime -- | Parse an email address. address :: Parser Address -- | Parse a Mailbox. mailbox :: Parser Mailbox -- | Parse a list of Mailboxes. mailboxList :: Parser [Mailbox] -- | Parse a Recipient. recipient :: Parser Recipient -- | Parse a list of Recipients. recipientList :: Parser [Recipient] -- | Parse a message identifier. messageID :: Parser MessageID -- | Parse a list of message identifiers. messageIDList :: Parser [MessageID] -- | Parse a phrase. Adjacent encoded words are concatenated. White space -- is reduced to a single space, except when quoted or part of an encoded -- word. phrase :: Parser Text -- | Parse a comma-separated list of phrases. phraseList :: Parser [Text] -- | Parse unstructured text. Adjacent encoded words are concatenated. -- White space is reduced to a single space, except when part of an -- encoded word. unstructured :: Parser Text -- | Parse the MIME version (which should be 1.0). mimeVersion :: Parser (Int, Int) -- | Parse the content type. contentType :: Parser (MimeType, Parameters) -- | Parse the content transfer encoding. contentTransferEncoding :: Parser (CI ByteString) -- | Reading common header fields. This module is intended to be imported -- qualified: -- --
--   import qualified Network.Email.Header.Read as H
--   
module Network.Email.Header.Read -- | Lookup and parse a header with a parser. field :: MonadThrow m => HeaderName -> Parser a -> Headers -> m a -- | Lookup and parse a structured header with a parser. This skips initial -- comments and folding white space, and ensures that the entire body is -- consumed by the parser. structuredField :: MonadThrow m => HeaderName -> Parser a -> Headers -> m a -- | Get the value of the Date: field. date :: MonadThrow m => Headers -> m ZonedTime -- | Get the value of the From: field. from :: MonadThrow m => Headers -> m [Mailbox] -- | Get the value of the Sender: field. sender :: MonadThrow m => Headers -> m Mailbox -- | Get the value of the Reply-To: field. replyTo :: MonadThrow m => Headers -> m [Recipient] -- | Get the value of the To: field. to :: MonadThrow m => Headers -> m [Recipient] -- | Get the value of the Cc: field. cc :: MonadThrow m => Headers -> m [Recipient] -- | Get the value of the Bcc: field. bcc :: MonadThrow m => Headers -> m (Maybe [Recipient]) -- | Get the value of the Message-ID: field. messageID :: MonadThrow m => Headers -> m MessageID -- | Get the value of the In-Reply-To: field. inReplyTo :: MonadThrow m => Headers -> m [MessageID] -- | Get the value of the References: field. references :: MonadThrow m => Headers -> m [MessageID] -- | Get the value of the Subject: field. subject :: MonadThrow m => Headers -> m Text -- | Get the value of the Comments: field. comments :: MonadThrow m => Headers -> m Text -- | Get the value of the Keywords: field. keywords :: MonadThrow m => Headers -> m [Text] -- | Get the value of the Resent-Date: field. resentDate :: MonadThrow m => Headers -> m ZonedTime -- | Get the value of the Resent-From: field. resentFrom :: MonadThrow m => Headers -> m [Mailbox] -- | Get the value of the Resent-Sender: field. resentSender :: MonadThrow m => Headers -> m Mailbox -- | Get the value of the Resent-To: field. resentTo :: MonadThrow m => Headers -> m [Recipient] -- | Get the value of the Resent-Cc: field. resentCc :: MonadThrow m => Headers -> m [Recipient] -- | Get the value of the Resent-Bcc: field. resentBcc :: MonadThrow m => Headers -> m (Maybe [Recipient]) -- | Get the value of the Resent-Message-ID: field. resentMessageID :: MonadThrow m => Headers -> m MessageID -- | Get the value of the MIME-Version: field. mimeVersion :: MonadThrow m => Headers -> m (Int, Int) -- | Get the value of the Content-Type: field. contentType :: MonadThrow m => Headers -> m (MimeType, Parameters) -- | Get the value of the Content-Transfer-Encoding: field. contentTransferEncoding :: MonadThrow m => Headers -> m (CI ByteString) -- | Get the value of the Content-ID: field. contentID :: MonadThrow m => Headers -> m MessageID -- | Formatting and pretty-printing header types. module Network.Email.Header.Pretty -- | Separate a group with commas. commaSep :: (a -> Doc) -> [a] -> Doc -- | Format a date and time. dateTime :: ZonedTime -> Doc -- | Format an address. address :: Address -> Doc -- | Format a Mailbox. mailbox :: Mailbox -> Doc -- | Format a list of Mailboxes. mailboxList :: [Mailbox] -> Doc -- | Format a Recipient. recipient :: Recipient -> Doc -- | Format a list of Recipients. recipientList :: [Recipient] -> Doc -- | Format a message identifier messageID :: MessageID -> Doc -- | Format a list of message identifiers. messageIDList :: [MessageID] -> Doc -- | Format a phrase. The text is encoded as is, unless: -- -- phrase :: Text -> Doc -- | Format a list of phrases. phraseList :: [Text] -> Doc -- | Format unstructured text. The text is encoded as is, unless: -- -- unstructured :: Text -> Doc -- | Format the MIME version. mimeVersion :: Int -> Int -> Doc -- | Format the content type and parameters. contentType :: MimeType -> Parameters -> Doc -- | Format the content transfer encoding. contentTransferEncoding :: CI ByteString -> Doc -- | Rendering common header fields. This module is intended to be imported -- qualified: -- --
--   import qualified Network.Email.Header.Render as R
--   
module Network.Email.Header.Render -- | Rendering options. data RenderOptions RenderOptions :: Int -> Int -> Charset -> Encoding -> RenderOptions -- | The maximum line width. [lineWidth] :: RenderOptions -> Int -- | The indent of each line, in spaces. [indent] :: RenderOptions -> Int -- | The charset used to encode text outside US-ASCII range. [charset] :: RenderOptions -> Charset -- | The header encoding used for encoded words. [encoding] :: RenderOptions -> Encoding -- | The encoding used for binary characters in an encoded word. data Encoding -- | Quoted-printable encoding. Spaces are represented with underscores, -- and undisplayable characters are represented as hex pairs. QP :: Encoding -- | Base 64 encoding of all characters. Base64 :: Encoding -- | Default rendering options, which uses a line width of 80, and indent -- of 2, and utf-8 quated-printable encoding. defaultRenderOptions :: RenderOptions -- | A formatted email header. data Doc -- | Render a list of headers. renderHeaders :: RenderOptions -> [(HeaderName, Doc)] -> Headers -- | Create a Date: field. date :: ZonedTime -> (HeaderName, Doc) -- | Create a From: field. from :: [Mailbox] -> (HeaderName, Doc) -- | Create a Sender: field. sender :: Mailbox -> (HeaderName, Doc) -- | Create a Reply-To: field. replyTo :: [Recipient] -> (HeaderName, Doc) -- | Create a To: field. to :: [Recipient] -> (HeaderName, Doc) -- | Create a Cc: field. cc :: [Recipient] -> (HeaderName, Doc) -- | Create a Bcc: field. bcc :: Maybe [Recipient] -> (HeaderName, Doc) -- | Create a Message-ID: field. messageID :: MessageID -> (HeaderName, Doc) -- | Create a In-Reply-To: field. inReplyTo :: [MessageID] -> (HeaderName, Doc) -- | Create a References: field. references :: [MessageID] -> (HeaderName, Doc) -- | Create a Subject: field. subject :: Text -> (HeaderName, Doc) -- | Create a Comments: field. comments :: Text -> (HeaderName, Doc) -- | Create a Keywords: field. keywords :: [Text] -> (HeaderName, Doc) -- | Create a Resent-Date: field. resentDate :: ZonedTime -> (HeaderName, Doc) -- | Create a Resent-From: field. resentFrom :: [Mailbox] -> (HeaderName, Doc) -- | Create a Resent-Sender: field. resentSender :: Mailbox -> (HeaderName, Doc) -- | Create a Resent-To: field. resentTo :: [Recipient] -> (HeaderName, Doc) -- | Create a Resent-Cc: field. resentCc :: [Recipient] -> (HeaderName, Doc) -- | Create a Resent-Bcc: field. resentBcc :: Maybe [Recipient] -> (HeaderName, Doc) -- | Create a Resent-Message-ID: field. resentMessageID :: MessageID -> (HeaderName, Doc) -- | Create a MIME-Version: field. mimeVersion :: Int -> Int -> (HeaderName, Doc) -- | Create a Content-Type: field. contentType :: MimeType -> Parameters -> (HeaderName, Doc) -- | Create a Content-Transfer-Encoding: field. contentTransferEncoding :: CI ByteString -> (HeaderName, Doc) -- | Create a Content-ID: field. contentID :: MessageID -> (HeaderName, Doc)