diff --git a/configs/purebred.hs b/configs/purebred.hs index 64dc2d79..328c2f7a 100644 --- a/configs/purebred.hs +++ b/configs/purebred.hs @@ -37,6 +37,7 @@ import System.Environment (lookupEnv) import System.Exit (die) import System.IO.Unsafe +import Data.MIME (defaultCharsets) import Purebred import Purebred.Storage.AddressBook.MuttAliasFile @@ -86,7 +87,7 @@ main = do let addrsFile = fromMaybe cwd confdir <> "/aliases" addressBook <- - initMuttAliasFileAddressBook addrsFile + initMuttAliasFileAddressBook defaultCharsets addrsFile >>= either (die . show) pure purebred diff --git a/src/Purebred.hs b/src/Purebred.hs index 61b57438..4cb7f2b4 100644 --- a/src/Purebred.hs +++ b/src/Purebred.hs @@ -129,6 +129,7 @@ module Purebred , module Purebred.Plugin, module Purebred.Plugin.TweakConfig, module Purebred.Storage.Tags, + module Purebred.Storage.AddressBook.MuttAliasFile, module Purebred.Types, module Purebred.Types.Error, module Purebred.UI.Actions, @@ -187,6 +188,7 @@ import Purebred.Plugin.Internal import Purebred.Plugin.TweakConfig import Purebred.Storage.Server import Purebred.Storage.Tags (TagOp(..)) +import Purebred.Storage.AddressBook.MuttAliasFile import Purebred.Types.Error -- re-exports for configuration diff --git a/src/Purebred/Storage/AddressBook/MuttAliasFile.hs b/src/Purebred/Storage/AddressBook/MuttAliasFile.hs index 93bb9320..7934089c 100644 --- a/src/Purebred/Storage/AddressBook/MuttAliasFile.hs +++ b/src/Purebred/Storage/AddressBook/MuttAliasFile.hs @@ -31,16 +31,16 @@ module Purebred.Storage.AddressBook.MuttAliasFile , parseMuttAliasFile ) where -import Data.Attoparsec.ByteString (Parser, parseOnly, sepBy, string, takeTill) -import Data.Attoparsec.ByteString.Char8 (endOfLine, isSpace_w8, skipSpace, space) +import Data.Attoparsec.Text (Parser, parseOnly, sepBy, string, takeTill, space, skipSpace, endOfLine) +import Data.Char (isSpace) import Data.Bifunctor (bimap) import qualified Data.ByteString as B import qualified Data.Text as T import qualified Data.Text.Internal.Search as T import Control.Lens (Lens', lens, toListOf, folded, filtered, view) -import Data.MIME (defaultCharsets) -import Data.IMF (address, Address) +import Data.MIME (Address) +import Data.IMF.Text (address) import Purebred.Types.Error (Error(ParseError)) import Purebred.Types.AddressBook (AddressBook(..)) @@ -59,7 +59,7 @@ initMuttAliasFileAddressBook filePath = do let mk addrs = AddressBook (\substr -> pure $ filterMuttAliases substr addrs) Nothing - pure $ bimap ParseError mk $ parseMuttAliasFile contents + pure $ bimap ParseError mk $ parseMuttAliasFile (decodeLenient contents) filterMuttAliases :: T.Text -> [MuttAlias] -> [Address] filterMuttAliases substr = @@ -73,14 +73,14 @@ matchesSubstring :: T.Text -> T.Text -> Bool matchesSubstring needle haystack = not $ null $ T.indices needle haystack -- | Parser functions to parse a mutt alias file -parseMuttAliasFile :: B.ByteString -> Either String [MuttAlias] +parseMuttAliasFile :: T.Text -> Either String [MuttAlias] parseMuttAliasFile = parseOnly (muttalias `sepBy` endOfLine) muttalias :: Parser MuttAlias muttalias = do - nick <- string "alias" *> space *> takeTill isSpace_w8 - add <- skipSpace *> address defaultCharsets - pure $ MuttAlias (decodeLenient nick) add + nick <- string "alias" *> space *> takeTill isSpace + add <- skipSpace *> address + pure $ MuttAlias nick add -- | Parser Datatypes data MuttAlias = MuttAlias diff --git a/test/TestAddressBook.hs b/test/TestAddressBook.hs index 42854e85..6d93ea0f 100644 --- a/test/TestAddressBook.hs +++ b/test/TestAddressBook.hs @@ -23,7 +23,7 @@ module TestAddressBook ( import Test.Tasty (TestTree, testGroup) import Test.Tasty.HUnit ((@?=), testCase) -import Data.IMF (Address(..)) +import Data.MIME (Address(..)) import Purebred.Storage.AddressBook.MuttAliasFile @@ -50,11 +50,11 @@ testParseMuttAlias = } ] , testCase "with long names" $ - parseMuttAliasFile "alias nick1 Mr Nick Name \nalias nick2 Nick Test Name " + parseMuttAliasFile "alias nick1 Mr Nück Name \nalias nick2 Nick Test Name " @?= Right [ MuttAlias { _muttAliasNick = "nick1" - , _muttAliasAddress = Single "Mr Nick Name " + , _muttAliasAddress = Single "Mr Nück Name " } , MuttAlias { _muttAliasNick = "nick2"