-- -- Copyright Michael Orlitzky -- -- http://michael.orlitzky.com/ -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation, either version 3 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- http://www.fsf.org/licensing/licenses/gpl.html -- module Tnef.Attachment where import Tnef.Object data TnefAttachment = TnefAttachment { att_mod_date :: TnefObject, att_data :: TnefObject, att_file_name :: TnefObject, att_meta_file :: TnefObject, att_attachment :: TnefObject } | NilAttachment deriving (Show) get_attachment_list :: [TnefObject] -> [TnefAttachment] get_attachment_list [] = [] get_attachment_list [Nil] = [] get_attachment_list (x:xs) | (show (obj_name x) == "Attachment Rendering Data") = (make_attachment xs) : get_attachment_list xs | otherwise = get_attachment_list xs make_attachment :: [TnefObject] -> TnefAttachment make_attachment xs | length xs < 5 = NilAttachment | otherwise = TnefAttachment m d f mf a where m = get_first_with_name xs "Attachment Modification Date" d = get_first_with_name xs "Attachment Data" f = get_first_with_name xs "Attachment File Name" mf = get_first_with_name xs "Attachment Meta File" a = get_first_with_name xs "Attachment" safe_head :: [TnefObject] -> TnefObject safe_head xs | ((length xs) == 0) = Nil | otherwise = head xs get_first_with_name :: [TnefObject] -> String -> TnefObject get_first_with_name xs name = safe_head (dropWhile ((/= name) . show . obj_name) xs) write_attachment :: TnefAttachment -> IO () write_attachment NilAttachment = putStrLn "NilAttachment" write_attachment x = do write_tnef_object (show_data (att_file_name x)) (att_data x)