Closed singpolyma closed 4 years ago
@singpolyma I have a general question. What is your use case? i.e. in what context are you turning Text into ByteString?
As part of fix for #50 I now have a function buildPhrase :: T.Text -> B.Builder
. Note some productions from RFC 5322 and RFC 2047:
phrase = 1*( encoded-word / word )
word = atom / quoted-string
atom = [CFWS] 1*atext [CFWS]
buildPhrase
uses atom if possible, otherwise quoted-string if possible, otherwise encoded-word. Is it suitable for your use case?
My main usecase is encoding the Subject
header, so I wouldn't want it to be wrapped in quotes.
@singpolyma thanks for clarifying. I might introduce a specific optic to expose the subject header as 'Maybe Text', since it seems like a pretty common need :)
@singpolyma I'm sorry it has been a while. I have made a few enhancements, including encoding only those words that require it rather than the whole input. Are you happy with what's in https://github.com/purebred-mua/purebred-email/tree/fix/50-mailbox-display-name-unicode ?
The comment:
-- Currently turns the whole text into a single encoded word, if necessary.
is wrong now, but otherwise seems good (passes the tests in my application anyway, with appropriate changes).
@singpolyma thanks for testing, and for picking up on the haddock needing fixing :+1:
This was merged separately from the PR.
Takes in the Text that you want in the header and returns either the same text as an ASCII ByteString or an appropriate encoded-word that will decode to the original.