From 917de9c6df342d032e2b05238c7ea923da2772db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Benencia?= Date: Sun, 1 Sep 2013 13:16:54 -0300 Subject: towards mime library --- Handlers.hs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'Handlers.hs') diff --git a/Handlers.hs b/Handlers.hs index 3e27b79..503358b 100644 --- a/Handlers.hs +++ b/Handlers.hs @@ -7,16 +7,18 @@ module Handlers where -import Data.List(intercalate) +import Codec.MIME.Parse(parseMIMEMessage) +import Codec.MIME.Type(MIMEValue(..)) import Control.Monad.State -import Data.List(stripPrefix) +import Data.List(intercalate, stripPrefix) import System.FilePath(FilePath, takeFileName, dropTrailingPathSeparator) +import qualified System.IO.UTF8 as UTF8 -import Email(parseEmail, getFields, getSubject, getFrom, getBody, formatBody) +--import Email(parseEmail, getFields, getSubject, getFrom, getBody, formatBody) +import Email(lookupField, getBody, formatBody) import Maildir import Print import State -import qualified System.IO.UTF8 as UTF8 import Types (LazymailCurses) previousMode :: Mode -> LazymailCurses () @@ -32,7 +34,7 @@ changeMode EmailMode = return () changeMode IndexMode = do st <- get msg <- liftIO $ UTF8.readFile . selectedEmailPath . indexState $ st - let email = parseEmail msg + let email = parseMIMEMessage msg let body = getBody $ email let el = formatBody body $ screenColumns st let est = (emailState st) { currentEmail = email, emailLines = el, scrollRowEm = 0 } @@ -151,12 +153,12 @@ scrollCrop top rows xs = take rows $ drop top xs formatIndexModeRows st = mapM formatRow where formatRow fp = do msg <- UTF8.readFile fp - let email = parseEmail msg - let fs = getFields email + let email = parseMIMEMessage msg + let hs = mime_val_headers email let str = normalizeLen (screenColumns st) $ intercalate ppSep $ [ ppFlags . getFlags $ fp - , ppIndexNameAddr . getFrom $ fs - , ppSubject . getSubject $ fs + , normalizeLen fromLen $ ppField $ lookupField "from" hs + , ppField $ lookupField "subject" hs ] return (fp, str) -- cgit v1.2.3