aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Email.hs20
-rw-r--r--Handlers.hs3
2 files changed, 20 insertions, 3 deletions
diff --git a/Email.hs b/Email.hs
index c1c524f..4d310c4 100644
--- a/Email.hs
+++ b/Email.hs
@@ -7,7 +7,7 @@
-}
module Email where
-import Codec.MIME.Type(MIMEValue(..), MIMEContent(..))
+import Codec.MIME.Type(MIMEValue(..), MIMEContent(..), showMIMEType, Type(..), MIMEType(..))
import Data.Char(toLower)
import Data.List(find)
@@ -15,7 +15,23 @@ getBody :: MIMEValue -> String
getBody msg =
case mime_val_content msg of
Single c -> c
- _ -> "Buggity Buggity Buggity!"
+ Multi mvs -> case firstTextPart mvs of
+ Just mv -> unwrapContent . mime_val_content $ mv
+ Nothing -> "Buggity Buggity Buggity!"
+ where
+ unwrapContent (Single c) = c
+
+-- hackish function for showing the email. In he future the logic of this
+-- function should be improved.
+firstTextPart [] = Nothing
+firstTextPart (mv:mvs) = case mime_val_content mv of
+ Single c -> if isText mv then Just mv else firstTextPart mvs
+ Multi mvs' -> firstTextPart mvs'
+
+ where
+ isText = \mv -> case (mimeType $ mime_val_type mv) of
+ Text text -> True
+ _ -> False
getHeaders :: MIMEValue -> [(String,String)]
getHeaders = mime_val_headers
diff --git a/Handlers.hs b/Handlers.hs
index 503358b..ccce1d0 100644
--- a/Handlers.hs
+++ b/Handlers.hs
@@ -9,6 +9,7 @@ module Handlers where
import Codec.MIME.Parse(parseMIMEMessage)
import Codec.MIME.Type(MIMEValue(..))
+import Control.Exception(evaluate)
import Control.Monad.State
import Data.List(intercalate, stripPrefix)
import System.FilePath(FilePath, takeFileName, dropTrailingPathSeparator)
@@ -33,7 +34,7 @@ changeMode :: Mode -> LazymailCurses ()
changeMode EmailMode = return ()
changeMode IndexMode = do
st <- get
- msg <- liftIO $ UTF8.readFile . selectedEmailPath . indexState $ st
+ msg <- liftIO $ UTF8.readFile (selectedEmailPath . indexState $ st)
let email = parseMIMEMessage msg
let body = getBody $ email
let el = formatBody body $ screenColumns st
nihil fit ex nihilo