Permalink
Browse files

Encode all special characters from RFC 2822.

Many (but not all) of these went wrong with some mail servers when used as 'name' part of an address header (from, to, cc, bcc).
  • Loading branch information...
1 parent 2e2df7d commit cf4685b2ab012180f5c7110f07891443d71d165a @hesselink committed Nov 3, 2011
Showing with 22 additions and 5 deletions.
  1. +22 −5 mime-mail/Network/Mail/Mime.hs
@@ -218,7 +218,7 @@ showAddressHeader (k, as) =
showAddress :: Address -> Builder
showAddress a = mconcat
- [ maybe mempty ((`mappend` fromByteString " ") . encodeIfNeeded) (addressName a)
+ [ maybe mempty ((`mappend` fromByteString " ") . encodedWord) (addressName a)
, fromByteString "<"
, fromText (addressEmail a)
, fromByteString ">"
@@ -346,10 +346,27 @@ encodedWord t = mconcat
]
where
go front w = front `mappend` go' w
- go' 32 = fromWord8 95
- go' 95 = go'' 95
- go' 63 = go'' 63
- go' 61 = go'' 61
+ go' 32 = fromWord8 95 -- space
+ go' 95 = go'' 95 -- _
+ go' 63 = go'' 63 -- ?
+ go' 61 = go'' 61 -- =
+
+ -- The special characters from RFC 2822. Not all of these always give
+ -- problems, but at least @[];"<>, gave problems with some mail servers
+ -- when used in the 'name' part of an address.
+ go' 34 = go'' 34 -- "
+ go' 40 = go'' 40 -- (
+ go' 41 = go'' 41 -- )
+ go' 44 = go'' 44 -- ,
+ go' 46 = go'' 46 -- .
+ go' 58 = go'' 58 -- ;
+ go' 59 = go'' 59 -- ;
+ go' 60 = go'' 60 -- <
+ go' 62 = go'' 62 -- >
+ go' 64 = go'' 64 -- @
+ go' 91 = go'' 91 -- [
+ go' 92 = go'' 92 -- \
+ go' 93 = go'' 93 -- ]
go' w
| 33 <= w && w <= 126 = fromWord8 w
| otherwise = go'' w

0 comments on commit cf4685b

Please sign in to comment.