{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.SES.Types.ReceiptRule
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.SES.Types.ReceiptRule where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import Amazonka.SES.Types.ReceiptAction
import Amazonka.SES.Types.TlsPolicy

-- | Receipt rules enable you to specify which actions Amazon SES should take
-- when it receives mail on behalf of one or more email addresses or
-- domains that you own.
--
-- Each receipt rule defines a set of email addresses or domains that it
-- applies to. If the email addresses or domains match at least one
-- recipient address of the message, Amazon SES executes all of the receipt
-- rule\'s actions on the message.
--
-- For information about setting up receipt rules, see the
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-receipt-rules.html Amazon SES Developer Guide>.
--
-- /See:/ 'newReceiptRule' smart constructor.
data ReceiptRule = ReceiptRule'
  { -- | An ordered list of actions to perform on messages that match at least
    -- one of the recipient email addresses or domains specified in the receipt
    -- rule.
    ReceiptRule -> Maybe [ReceiptAction]
actions :: Prelude.Maybe [ReceiptAction],
    -- | If @true@, the receipt rule is active. The default value is @false@.
    ReceiptRule -> Maybe Bool
enabled :: Prelude.Maybe Prelude.Bool,
    -- | The recipient domains and email addresses that the receipt rule applies
    -- to. If this field is not specified, this rule will match all recipients
    -- under all verified domains.
    ReceiptRule -> Maybe [Text]
recipients :: Prelude.Maybe [Prelude.Text],
    -- | If @true@, then messages that this receipt rule applies to are scanned
    -- for spam and viruses. The default value is @false@.
    ReceiptRule -> Maybe Bool
scanEnabled :: Prelude.Maybe Prelude.Bool,
    -- | Specifies whether Amazon SES should require that incoming email is
    -- delivered over a connection encrypted with Transport Layer Security
    -- (TLS). If this parameter is set to @Require@, Amazon SES will bounce
    -- emails that are not received over TLS. The default is @Optional@.
    ReceiptRule -> Maybe TlsPolicy
tlsPolicy :: Prelude.Maybe TlsPolicy,
    -- | The name of the receipt rule. The name must:
    --
    -- -   This value can only contain ASCII letters (a-z, A-Z), numbers (0-9),
    --     underscores (_), or dashes (-).
    --
    -- -   Start and end with a letter or number.
    --
    -- -   Contain less than 64 characters.
    ReceiptRule -> Text
name :: Prelude.Text
  }
  deriving (ReceiptRule -> ReceiptRule -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ReceiptRule -> ReceiptRule -> Bool
$c/= :: ReceiptRule -> ReceiptRule -> Bool
== :: ReceiptRule -> ReceiptRule -> Bool
$c== :: ReceiptRule -> ReceiptRule -> Bool
Prelude.Eq, ReadPrec [ReceiptRule]
ReadPrec ReceiptRule
Int -> ReadS ReceiptRule
ReadS [ReceiptRule]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ReceiptRule]
$creadListPrec :: ReadPrec [ReceiptRule]
readPrec :: ReadPrec ReceiptRule
$creadPrec :: ReadPrec ReceiptRule
readList :: ReadS [ReceiptRule]
$creadList :: ReadS [ReceiptRule]
readsPrec :: Int -> ReadS ReceiptRule
$creadsPrec :: Int -> ReadS ReceiptRule
Prelude.Read, Int -> ReceiptRule -> ShowS
[ReceiptRule] -> ShowS
ReceiptRule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReceiptRule] -> ShowS
$cshowList :: [ReceiptRule] -> ShowS
show :: ReceiptRule -> String
$cshow :: ReceiptRule -> String
showsPrec :: Int -> ReceiptRule -> ShowS
$cshowsPrec :: Int -> ReceiptRule -> ShowS
Prelude.Show, forall x. Rep ReceiptRule x -> ReceiptRule
forall x. ReceiptRule -> Rep ReceiptRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ReceiptRule x -> ReceiptRule
$cfrom :: forall x. ReceiptRule -> Rep ReceiptRule x
Prelude.Generic)

-- |
-- Create a value of 'ReceiptRule' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'actions', 'receiptRule_actions' - An ordered list of actions to perform on messages that match at least
-- one of the recipient email addresses or domains specified in the receipt
-- rule.
--
-- 'enabled', 'receiptRule_enabled' - If @true@, the receipt rule is active. The default value is @false@.
--
-- 'recipients', 'receiptRule_recipients' - The recipient domains and email addresses that the receipt rule applies
-- to. If this field is not specified, this rule will match all recipients
-- under all verified domains.
--
-- 'scanEnabled', 'receiptRule_scanEnabled' - If @true@, then messages that this receipt rule applies to are scanned
-- for spam and viruses. The default value is @false@.
--
-- 'tlsPolicy', 'receiptRule_tlsPolicy' - Specifies whether Amazon SES should require that incoming email is
-- delivered over a connection encrypted with Transport Layer Security
-- (TLS). If this parameter is set to @Require@, Amazon SES will bounce
-- emails that are not received over TLS. The default is @Optional@.
--
-- 'name', 'receiptRule_name' - The name of the receipt rule. The name must:
--
-- -   This value can only contain ASCII letters (a-z, A-Z), numbers (0-9),
--     underscores (_), or dashes (-).
--
-- -   Start and end with a letter or number.
--
-- -   Contain less than 64 characters.
newReceiptRule ::
  -- | 'name'
  Prelude.Text ->
  ReceiptRule
newReceiptRule :: Text -> ReceiptRule
newReceiptRule Text
pName_ =
  ReceiptRule'
    { $sel:actions:ReceiptRule' :: Maybe [ReceiptAction]
actions = forall a. Maybe a
Prelude.Nothing,
      $sel:enabled:ReceiptRule' :: Maybe Bool
enabled = forall a. Maybe a
Prelude.Nothing,
      $sel:recipients:ReceiptRule' :: Maybe [Text]
recipients = forall a. Maybe a
Prelude.Nothing,
      $sel:scanEnabled:ReceiptRule' :: Maybe Bool
scanEnabled = forall a. Maybe a
Prelude.Nothing,
      $sel:tlsPolicy:ReceiptRule' :: Maybe TlsPolicy
tlsPolicy = forall a. Maybe a
Prelude.Nothing,
      $sel:name:ReceiptRule' :: Text
name = Text
pName_
    }

-- | An ordered list of actions to perform on messages that match at least
-- one of the recipient email addresses or domains specified in the receipt
-- rule.
receiptRule_actions :: Lens.Lens' ReceiptRule (Prelude.Maybe [ReceiptAction])
receiptRule_actions :: Lens' ReceiptRule (Maybe [ReceiptAction])
receiptRule_actions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReceiptRule' {Maybe [ReceiptAction]
actions :: Maybe [ReceiptAction]
$sel:actions:ReceiptRule' :: ReceiptRule -> Maybe [ReceiptAction]
actions} -> Maybe [ReceiptAction]
actions) (\s :: ReceiptRule
s@ReceiptRule' {} Maybe [ReceiptAction]
a -> ReceiptRule
s {$sel:actions:ReceiptRule' :: Maybe [ReceiptAction]
actions = Maybe [ReceiptAction]
a} :: ReceiptRule) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | If @true@, the receipt rule is active. The default value is @false@.
receiptRule_enabled :: Lens.Lens' ReceiptRule (Prelude.Maybe Prelude.Bool)
receiptRule_enabled :: Lens' ReceiptRule (Maybe Bool)
receiptRule_enabled = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReceiptRule' {Maybe Bool
enabled :: Maybe Bool
$sel:enabled:ReceiptRule' :: ReceiptRule -> Maybe Bool
enabled} -> Maybe Bool
enabled) (\s :: ReceiptRule
s@ReceiptRule' {} Maybe Bool
a -> ReceiptRule
s {$sel:enabled:ReceiptRule' :: Maybe Bool
enabled = Maybe Bool
a} :: ReceiptRule)

-- | The recipient domains and email addresses that the receipt rule applies
-- to. If this field is not specified, this rule will match all recipients
-- under all verified domains.
receiptRule_recipients :: Lens.Lens' ReceiptRule (Prelude.Maybe [Prelude.Text])
receiptRule_recipients :: Lens' ReceiptRule (Maybe [Text])
receiptRule_recipients = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReceiptRule' {Maybe [Text]
recipients :: Maybe [Text]
$sel:recipients:ReceiptRule' :: ReceiptRule -> Maybe [Text]
recipients} -> Maybe [Text]
recipients) (\s :: ReceiptRule
s@ReceiptRule' {} Maybe [Text]
a -> ReceiptRule
s {$sel:recipients:ReceiptRule' :: Maybe [Text]
recipients = Maybe [Text]
a} :: ReceiptRule) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | If @true@, then messages that this receipt rule applies to are scanned
-- for spam and viruses. The default value is @false@.
receiptRule_scanEnabled :: Lens.Lens' ReceiptRule (Prelude.Maybe Prelude.Bool)
receiptRule_scanEnabled :: Lens' ReceiptRule (Maybe Bool)
receiptRule_scanEnabled = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReceiptRule' {Maybe Bool
scanEnabled :: Maybe Bool
$sel:scanEnabled:ReceiptRule' :: ReceiptRule -> Maybe Bool
scanEnabled} -> Maybe Bool
scanEnabled) (\s :: ReceiptRule
s@ReceiptRule' {} Maybe Bool
a -> ReceiptRule
s {$sel:scanEnabled:ReceiptRule' :: Maybe Bool
scanEnabled = Maybe Bool
a} :: ReceiptRule)

-- | Specifies whether Amazon SES should require that incoming email is
-- delivered over a connection encrypted with Transport Layer Security
-- (TLS). If this parameter is set to @Require@, Amazon SES will bounce
-- emails that are not received over TLS. The default is @Optional@.
receiptRule_tlsPolicy :: Lens.Lens' ReceiptRule (Prelude.Maybe TlsPolicy)
receiptRule_tlsPolicy :: Lens' ReceiptRule (Maybe TlsPolicy)
receiptRule_tlsPolicy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReceiptRule' {Maybe TlsPolicy
tlsPolicy :: Maybe TlsPolicy
$sel:tlsPolicy:ReceiptRule' :: ReceiptRule -> Maybe TlsPolicy
tlsPolicy} -> Maybe TlsPolicy
tlsPolicy) (\s :: ReceiptRule
s@ReceiptRule' {} Maybe TlsPolicy
a -> ReceiptRule
s {$sel:tlsPolicy:ReceiptRule' :: Maybe TlsPolicy
tlsPolicy = Maybe TlsPolicy
a} :: ReceiptRule)

-- | The name of the receipt rule. The name must:
--
-- -   This value can only contain ASCII letters (a-z, A-Z), numbers (0-9),
--     underscores (_), or dashes (-).
--
-- -   Start and end with a letter or number.
--
-- -   Contain less than 64 characters.
receiptRule_name :: Lens.Lens' ReceiptRule Prelude.Text
receiptRule_name :: Lens' ReceiptRule Text
receiptRule_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReceiptRule' {Text
name :: Text
$sel:name:ReceiptRule' :: ReceiptRule -> Text
name} -> Text
name) (\s :: ReceiptRule
s@ReceiptRule' {} Text
a -> ReceiptRule
s {$sel:name:ReceiptRule' :: Text
name = Text
a} :: ReceiptRule)

instance Data.FromXML ReceiptRule where
  parseXML :: [Node] -> Either String ReceiptRule
parseXML [Node]
x =
    Maybe [ReceiptAction]
-> Maybe Bool
-> Maybe [Text]
-> Maybe Bool
-> Maybe TlsPolicy
-> Text
-> ReceiptRule
ReceiptRule'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x
                      forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"Actions"
                      forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                      forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (forall a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"member")
                  )
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"Enabled")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( [Node]
x
                      forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"Recipients"
                      forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                      forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (forall a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"member")
                  )
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"ScanEnabled")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"TlsPolicy")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"Name")

instance Prelude.Hashable ReceiptRule where
  hashWithSalt :: Int -> ReceiptRule -> Int
hashWithSalt Int
_salt ReceiptRule' {Maybe Bool
Maybe [Text]
Maybe [ReceiptAction]
Maybe TlsPolicy
Text
name :: Text
tlsPolicy :: Maybe TlsPolicy
scanEnabled :: Maybe Bool
recipients :: Maybe [Text]
enabled :: Maybe Bool
actions :: Maybe [ReceiptAction]
$sel:name:ReceiptRule' :: ReceiptRule -> Text
$sel:tlsPolicy:ReceiptRule' :: ReceiptRule -> Maybe TlsPolicy
$sel:scanEnabled:ReceiptRule' :: ReceiptRule -> Maybe Bool
$sel:recipients:ReceiptRule' :: ReceiptRule -> Maybe [Text]
$sel:enabled:ReceiptRule' :: ReceiptRule -> Maybe Bool
$sel:actions:ReceiptRule' :: ReceiptRule -> Maybe [ReceiptAction]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [ReceiptAction]
actions
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
enabled
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
recipients
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
scanEnabled
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe TlsPolicy
tlsPolicy
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name

instance Prelude.NFData ReceiptRule where
  rnf :: ReceiptRule -> ()
rnf ReceiptRule' {Maybe Bool
Maybe [Text]
Maybe [ReceiptAction]
Maybe TlsPolicy
Text
name :: Text
tlsPolicy :: Maybe TlsPolicy
scanEnabled :: Maybe Bool
recipients :: Maybe [Text]
enabled :: Maybe Bool
actions :: Maybe [ReceiptAction]
$sel:name:ReceiptRule' :: ReceiptRule -> Text
$sel:tlsPolicy:ReceiptRule' :: ReceiptRule -> Maybe TlsPolicy
$sel:scanEnabled:ReceiptRule' :: ReceiptRule -> Maybe Bool
$sel:recipients:ReceiptRule' :: ReceiptRule -> Maybe [Text]
$sel:enabled:ReceiptRule' :: ReceiptRule -> Maybe Bool
$sel:actions:ReceiptRule' :: ReceiptRule -> Maybe [ReceiptAction]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [ReceiptAction]
actions
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
enabled
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
recipients
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
scanEnabled
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe TlsPolicy
tlsPolicy
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name

instance Data.ToQuery ReceiptRule where
  toQuery :: ReceiptRule -> QueryString
toQuery ReceiptRule' {Maybe Bool
Maybe [Text]
Maybe [ReceiptAction]
Maybe TlsPolicy
Text
name :: Text
tlsPolicy :: Maybe TlsPolicy
scanEnabled :: Maybe Bool
recipients :: Maybe [Text]
enabled :: Maybe Bool
actions :: Maybe [ReceiptAction]
$sel:name:ReceiptRule' :: ReceiptRule -> Text
$sel:tlsPolicy:ReceiptRule' :: ReceiptRule -> Maybe TlsPolicy
$sel:scanEnabled:ReceiptRule' :: ReceiptRule -> Maybe Bool
$sel:recipients:ReceiptRule' :: ReceiptRule -> Maybe [Text]
$sel:enabled:ReceiptRule' :: ReceiptRule -> Maybe Bool
$sel:actions:ReceiptRule' :: ReceiptRule -> Maybe [ReceiptAction]
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Actions"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: forall a. ToQuery a => a -> QueryString
Data.toQuery
            (forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Data.toQueryList ByteString
"member" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [ReceiptAction]
actions),
        ByteString
"Enabled" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Bool
enabled,
        ByteString
"Recipients"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: forall a. ToQuery a => a -> QueryString
Data.toQuery
            (forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Data.toQueryList ByteString
"member" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
recipients),
        ByteString
"ScanEnabled" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Bool
scanEnabled,
        ByteString
"TlsPolicy" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe TlsPolicy
tlsPolicy,
        ByteString
"Name" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
name
      ]