{-# 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.MessageDsn
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.SES.Types.MessageDsn where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SES.Types.ExtensionField

-- | Message-related information to include in the Delivery Status
-- Notification (DSN) when an email that Amazon SES receives on your behalf
-- bounces.
--
-- For information about receiving email through Amazon SES, see the
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email.html Amazon SES Developer Guide>.
--
-- /See:/ 'newMessageDsn' smart constructor.
data MessageDsn = MessageDsn'
  { -- | When the message was received by the reporting mail transfer agent
    -- (MTA), in <https://www.ietf.org/rfc/rfc0822.txt RFC 822> date-time
    -- format.
    MessageDsn -> Maybe ISO8601
arrivalDate :: Prelude.Maybe Core.ISO8601,
    -- | Additional X-headers to include in the DSN.
    MessageDsn -> Maybe [ExtensionField]
extensionFields :: Prelude.Maybe [ExtensionField],
    -- | The reporting MTA that attempted to deliver the message, formatted as
    -- specified in <https://tools.ietf.org/html/rfc3464 RFC 3464>
    -- (@mta-name-type; mta-name@). The default value is
    -- @dns; inbound-smtp.[region].amazonaws.com@.
    MessageDsn -> Text
reportingMta :: Prelude.Text
  }
  deriving (MessageDsn -> MessageDsn -> Bool
(MessageDsn -> MessageDsn -> Bool)
-> (MessageDsn -> MessageDsn -> Bool) -> Eq MessageDsn
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MessageDsn -> MessageDsn -> Bool
$c/= :: MessageDsn -> MessageDsn -> Bool
== :: MessageDsn -> MessageDsn -> Bool
$c== :: MessageDsn -> MessageDsn -> Bool
Prelude.Eq, ReadPrec [MessageDsn]
ReadPrec MessageDsn
Int -> ReadS MessageDsn
ReadS [MessageDsn]
(Int -> ReadS MessageDsn)
-> ReadS [MessageDsn]
-> ReadPrec MessageDsn
-> ReadPrec [MessageDsn]
-> Read MessageDsn
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MessageDsn]
$creadListPrec :: ReadPrec [MessageDsn]
readPrec :: ReadPrec MessageDsn
$creadPrec :: ReadPrec MessageDsn
readList :: ReadS [MessageDsn]
$creadList :: ReadS [MessageDsn]
readsPrec :: Int -> ReadS MessageDsn
$creadsPrec :: Int -> ReadS MessageDsn
Prelude.Read, Int -> MessageDsn -> ShowS
[MessageDsn] -> ShowS
MessageDsn -> String
(Int -> MessageDsn -> ShowS)
-> (MessageDsn -> String)
-> ([MessageDsn] -> ShowS)
-> Show MessageDsn
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MessageDsn] -> ShowS
$cshowList :: [MessageDsn] -> ShowS
show :: MessageDsn -> String
$cshow :: MessageDsn -> String
showsPrec :: Int -> MessageDsn -> ShowS
$cshowsPrec :: Int -> MessageDsn -> ShowS
Prelude.Show, (forall x. MessageDsn -> Rep MessageDsn x)
-> (forall x. Rep MessageDsn x -> MessageDsn) -> Generic MessageDsn
forall x. Rep MessageDsn x -> MessageDsn
forall x. MessageDsn -> Rep MessageDsn x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MessageDsn x -> MessageDsn
$cfrom :: forall x. MessageDsn -> Rep MessageDsn x
Prelude.Generic)

-- |
-- Create a value of 'MessageDsn' 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:
--
-- 'arrivalDate', 'messageDsn_arrivalDate' - When the message was received by the reporting mail transfer agent
-- (MTA), in <https://www.ietf.org/rfc/rfc0822.txt RFC 822> date-time
-- format.
--
-- 'extensionFields', 'messageDsn_extensionFields' - Additional X-headers to include in the DSN.
--
-- 'reportingMta', 'messageDsn_reportingMta' - The reporting MTA that attempted to deliver the message, formatted as
-- specified in <https://tools.ietf.org/html/rfc3464 RFC 3464>
-- (@mta-name-type; mta-name@). The default value is
-- @dns; inbound-smtp.[region].amazonaws.com@.
newMessageDsn ::
  -- | 'reportingMta'
  Prelude.Text ->
  MessageDsn
newMessageDsn :: Text -> MessageDsn
newMessageDsn Text
pReportingMta_ =
  MessageDsn' :: Maybe ISO8601 -> Maybe [ExtensionField] -> Text -> MessageDsn
MessageDsn'
    { $sel:arrivalDate:MessageDsn' :: Maybe ISO8601
arrivalDate = Maybe ISO8601
forall a. Maybe a
Prelude.Nothing,
      $sel:extensionFields:MessageDsn' :: Maybe [ExtensionField]
extensionFields = Maybe [ExtensionField]
forall a. Maybe a
Prelude.Nothing,
      $sel:reportingMta:MessageDsn' :: Text
reportingMta = Text
pReportingMta_
    }

-- | When the message was received by the reporting mail transfer agent
-- (MTA), in <https://www.ietf.org/rfc/rfc0822.txt RFC 822> date-time
-- format.
messageDsn_arrivalDate :: Lens.Lens' MessageDsn (Prelude.Maybe Prelude.UTCTime)
messageDsn_arrivalDate :: (Maybe UTCTime -> f (Maybe UTCTime)) -> MessageDsn -> f MessageDsn
messageDsn_arrivalDate = (MessageDsn -> Maybe ISO8601)
-> (MessageDsn -> Maybe ISO8601 -> MessageDsn)
-> Lens MessageDsn MessageDsn (Maybe ISO8601) (Maybe ISO8601)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MessageDsn' {Maybe ISO8601
arrivalDate :: Maybe ISO8601
$sel:arrivalDate:MessageDsn' :: MessageDsn -> Maybe ISO8601
arrivalDate} -> Maybe ISO8601
arrivalDate) (\s :: MessageDsn
s@MessageDsn' {} Maybe ISO8601
a -> MessageDsn
s {$sel:arrivalDate:MessageDsn' :: Maybe ISO8601
arrivalDate = Maybe ISO8601
a} :: MessageDsn) ((Maybe ISO8601 -> f (Maybe ISO8601))
 -> MessageDsn -> f MessageDsn)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe ISO8601 -> f (Maybe ISO8601))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> MessageDsn
-> f MessageDsn
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso ISO8601 ISO8601 UTCTime UTCTime
-> Iso
     (Maybe ISO8601) (Maybe ISO8601) (Maybe UTCTime) (Maybe UTCTime)
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 AnIso ISO8601 ISO8601 UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | Additional X-headers to include in the DSN.
messageDsn_extensionFields :: Lens.Lens' MessageDsn (Prelude.Maybe [ExtensionField])
messageDsn_extensionFields :: (Maybe [ExtensionField] -> f (Maybe [ExtensionField]))
-> MessageDsn -> f MessageDsn
messageDsn_extensionFields = (MessageDsn -> Maybe [ExtensionField])
-> (MessageDsn -> Maybe [ExtensionField] -> MessageDsn)
-> Lens
     MessageDsn
     MessageDsn
     (Maybe [ExtensionField])
     (Maybe [ExtensionField])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MessageDsn' {Maybe [ExtensionField]
extensionFields :: Maybe [ExtensionField]
$sel:extensionFields:MessageDsn' :: MessageDsn -> Maybe [ExtensionField]
extensionFields} -> Maybe [ExtensionField]
extensionFields) (\s :: MessageDsn
s@MessageDsn' {} Maybe [ExtensionField]
a -> MessageDsn
s {$sel:extensionFields:MessageDsn' :: Maybe [ExtensionField]
extensionFields = Maybe [ExtensionField]
a} :: MessageDsn) ((Maybe [ExtensionField] -> f (Maybe [ExtensionField]))
 -> MessageDsn -> f MessageDsn)
-> ((Maybe [ExtensionField] -> f (Maybe [ExtensionField]))
    -> Maybe [ExtensionField] -> f (Maybe [ExtensionField]))
-> (Maybe [ExtensionField] -> f (Maybe [ExtensionField]))
-> MessageDsn
-> f MessageDsn
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [ExtensionField] [ExtensionField] [ExtensionField] [ExtensionField]
-> Iso
     (Maybe [ExtensionField])
     (Maybe [ExtensionField])
     (Maybe [ExtensionField])
     (Maybe [ExtensionField])
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 AnIso
  [ExtensionField] [ExtensionField] [ExtensionField] [ExtensionField]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The reporting MTA that attempted to deliver the message, formatted as
-- specified in <https://tools.ietf.org/html/rfc3464 RFC 3464>
-- (@mta-name-type; mta-name@). The default value is
-- @dns; inbound-smtp.[region].amazonaws.com@.
messageDsn_reportingMta :: Lens.Lens' MessageDsn Prelude.Text
messageDsn_reportingMta :: (Text -> f Text) -> MessageDsn -> f MessageDsn
messageDsn_reportingMta = (MessageDsn -> Text)
-> (MessageDsn -> Text -> MessageDsn)
-> Lens MessageDsn MessageDsn Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MessageDsn' {Text
reportingMta :: Text
$sel:reportingMta:MessageDsn' :: MessageDsn -> Text
reportingMta} -> Text
reportingMta) (\s :: MessageDsn
s@MessageDsn' {} Text
a -> MessageDsn
s {$sel:reportingMta:MessageDsn' :: Text
reportingMta = Text
a} :: MessageDsn)

instance Prelude.Hashable MessageDsn

instance Prelude.NFData MessageDsn

instance Core.ToQuery MessageDsn where
  toQuery :: MessageDsn -> QueryString
toQuery MessageDsn' {Maybe [ExtensionField]
Maybe ISO8601
Text
reportingMta :: Text
extensionFields :: Maybe [ExtensionField]
arrivalDate :: Maybe ISO8601
$sel:reportingMta:MessageDsn' :: MessageDsn -> Text
$sel:extensionFields:MessageDsn' :: MessageDsn -> Maybe [ExtensionField]
$sel:arrivalDate:MessageDsn' :: MessageDsn -> Maybe ISO8601
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"ArrivalDate" ByteString -> Maybe ISO8601 -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe ISO8601
arrivalDate,
        ByteString
"ExtensionFields"
          ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe QueryString -> QueryString
forall a. ToQuery a => a -> QueryString
Core.toQuery
            ( ByteString -> [ExtensionField] -> QueryString
forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Core.toQueryList ByteString
"member"
                ([ExtensionField] -> QueryString)
-> Maybe [ExtensionField] -> Maybe QueryString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [ExtensionField]
extensionFields
            ),
        ByteString
"ReportingMta" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
reportingMta
      ]