domain-auth-0.2.2: Domain authentication library

Safe HaskellNone
LanguageHaskell2010

Network.DomainAuth.PRD

Description

Utilities to decide Purported Responsible Domain (http://www.ietf.org/rfc/rfc4407.txt).

Synopsis

Documentation

data PRD Source #

Abstract type for context to decide PRD(purported responsible domain) according to RFC 4407.

Instances

Show PRD Source # 

Methods

showsPrec :: Int -> PRD -> ShowS #

show :: PRD -> String #

showList :: [PRD] -> ShowS #

initialPRD :: PRD Source #

Initial context of PRD.

pushPRD :: RawFieldKey -> RawFieldValue -> PRD -> PRD Source #

Pushing a field key and its value in to the PRD context.

decidePRD :: PRD -> Maybe Domain Source #

Deciding PRD from the RPD context.

>>> let maddr1 = "alice@alice.example.jp"
>>> let maddr2 = "bob@bob.example.jp"
>>> let maddr3 = "chris@chris.example.jp"
>>> let maddr4 = "dave@dave.example.jp"
>>> decidePRD (pushPRD "from" "alice@alice.example.jp" initialPRD)
Just "alice.example.jp"
>>> :{
decidePRD (pushPRD "from" maddr1
         $ pushPRD "from" maddr1 initialPRD)
:}
Nothing
>>> :{
decidePRD (pushPRD "sender" maddr2
         $ pushPRD "from" maddr1
         $ pushPRD "from" maddr1 initialPRD)
:}
Just "bob.example.jp"
>>> :{
decidePRD (pushPRD "sender" maddr2
         $ pushPRD "sender" maddr2
         $ pushPRD "from" maddr1
         $ pushPRD "from" maddr1 initialPRD)
:}
Nothing
>>> :{
decidePRD (pushPRD "resent-from" maddr3
         $ pushPRD "sender" maddr2
         $ pushPRD "sender" maddr2
         $ pushPRD "from" maddr1
         $ pushPRD "from" maddr1 initialPRD)
:}
Just "chris.example.jp"
>>> :{
decidePRD (pushPRD "resent-sender" maddr4
          $ pushPRD "resent-from" maddr3
          $ pushPRD "sender" maddr2
          $ pushPRD "sender" maddr2
          $ pushPRD "from" maddr1
          $ pushPRD "from" maddr1 initialPRD)
:}
Just "dave.example.jp"
>>> :{
decidePRD (pushPRD "resent-sender" maddr4
         $ pushPRD "resent-from" maddr3
         $ pushPRD "sender" maddr2
         $ pushPRD "received" "dummy"
         $ pushPRD "from" maddr1 initialPRD)
:}
Just "dave.example.jp"
>>> :{
decidePRD (pushPRD "resent-sender" maddr4
         $ pushPRD "received" "dummy"
         $ pushPRD "resent-from" maddr3
         $ pushPRD "sender" maddr2
         $ pushPRD "from" maddr1 initialPRD)
:}
Just "chris.example.jp"
>>> :{
decidePRD (pushPRD "received" "dummy"
          $ pushPRD "resent-sender" maddr4
          $ pushPRD "resent-from" maddr3
          $ pushPRD "sender" maddr2
          $ pushPRD "from" maddr1 initialPRD)
:}
Just "dave.example.jp"

decideFrom :: PRD -> Maybe Domain Source #

Taking the value of From: from the RPD context.

>>> decideFrom (pushPRD "from" "alice@alice.example.jp" initialPRD)
Just "alice.example.jp"

extractDomain :: RawFieldValue -> Maybe Domain Source #

Extract a domain from a value of a header field.

>>> extractDomain "Alice Brown <alice.brown@example.com>"
Just "example.com"
>>> extractDomain "\"Alice . Brown\" <alice.brown@example.com> (Nickname here)"
Just "example.com"
>>> extractDomain "alice.brown@example.com"
Just "example.com"
>>> extractDomain "Alice Brown <example.com>"
Nothing