module Config where import Network.SMTP import Network.POP3 import System.Directory import System.IO data SMTPHost = SMTPHost { hostname :: String , portNum :: Maybe Int , isSSL :: Bool , smtpAuth :: Maybe (AuthType, String) } deriving (Show, Read) data ReceiveSource = Maildir String | POP3Server String Int Pop3Auth Bool -- delete after receive ? deriving (Show, Read) data Config = Config { smtphost :: SMTPHost , mailaddr :: String , receive :: [ (ReceiveSource, [String]) ] , mailheader :: [String] , encode :: String } deriving (Show, Read) defaultConfig :: Config defaultConfig = Config { smtphost = SMTPHost { hostname = "localhost" , portNum = Nothing , isSSL = False , smtpAuth = Nothing } , mailaddr = "" , receive = [] , mailheader = [ "User-Agent: hazakura/0.0" ] , encode = "ISO-2022-JP" } saveConfig :: Config -> IO () saveConfig c = do curDir <- getCurrentDirectory getHomeDirectory >>= setCurrentDirectory setCurrentDirectory ".hazakura" writeFile "_config" $ show c setCurrentDirectory curDir loadConfig :: IO Config loadConfig = do curDir <- getCurrentDirectory getHomeDirectory >>= setCurrentDirectory setCurrentDirectory ".hazakura" exist <- doesFileExist "_config" if not exist then saveConfig defaultConfig else return () config <- readFile "_config" >>= readIO setCurrentDirectory curDir return config