module Network.Mail.Postie.Types
  ( HandlerResponse (..),
    Mail (..),
    Application,
  )
where

import Data.ByteString (ByteString)
import Pipes (Producer)
import Network.Mail.Postie.Address
import Network.Mail.Postie.SessionID (SessionID)

-- | Handler response indicating validity of email transaction.
data HandlerResponse
  = -- | Accepted, allow further processing.
    Accepted
  | -- | Rejected, stop transaction.
    Rejected

-- | Received email
data Mail
  = Mail
      { Mail -> SessionID
mailSessionID :: SessionID,
        Mail -> Maybe ByteString
mailAuth :: Maybe ByteString,
        -- | Sender
        Mail -> Address
mailSender :: Address,
        -- | Recipients
        Mail -> [Address]
mailRecipients :: [Address],
        -- | Mail content
        Mail -> Producer ByteString IO ()
mailBody :: Producer ByteString IO ()
      }

-- | Application which receives Mails from postie
--   An Application has to fully consume the mailBody part of a mail, the behaviour is undefined if not.
type Application = Mail -> IO HandlerResponse