-
Notifications
You must be signed in to change notification settings - Fork 0
/
Internal.purs
56 lines (42 loc) · 1.29 KB
/
Internal.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
module Data.RFC2821.Internal
(
Address
, makeAddress
, host
, original
, originalHost
, user
, address
, toString
)
where
import Data.Either (Either(..))
import Effect.Exception (Error)
import FFI.Simple ((..), (...))
import Prelude
foreign import data Address :: Type
foreign import makeAddressImpl :: forall a b. (Error -> Either Error a)
-> (Address -> Either b Address)
-> String
-> Either Error Address
-- | Attempt to parse given string as an email adddress
makeAddress :: String -> Either Error Address
makeAddress email = makeAddressImpl Left Right email
-- | Return the (parsed) host part `Address`
host :: Address -> String
host a = a .. "host"
-- | Return the original string from `Address`
original :: Address -> String
original a = a .. "original"
-- | Return the original host from `Address`
originalHost :: Address -> String
originalHost a = a .. "original_host"
-- | Return the (parsed) user parf of `Address`
user :: Address -> String
user a = a .. "user"
-- | Format `Address` as a string
address :: Address -> String
address a = a ... "address" $ []
-- | Format `Address` as an envelope
toString :: Address -> String
toString a = a ... "toString" $ []