2 -- Copyright Michael Orlitzky
4 -- http://michael.orlitzky.com/
6 -- This program is free software: you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation, either version 3 of the License, or
9 -- (at your option) any later version.
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
16 -- http://www.fsf.org/licensing/licenses/gpl.html
19 module Tnef.Attachment where
23 data TnefAttachment = TnefAttachment { att_mod_date :: TnefObject,
24 att_data :: TnefObject,
25 att_file_name :: TnefObject,
26 att_meta_file :: TnefObject,
27 att_attachment :: TnefObject }
32 get_attachment_list :: [TnefObject] -> [TnefAttachment]
33 get_attachment_list [] = []
34 get_attachment_list [Nil] = []
35 get_attachment_list (x:xs)
36 | (show (obj_name x) == "Attachment Rendering Data") = (make_attachment xs) : get_attachment_list xs
37 | otherwise = get_attachment_list xs
40 make_attachment :: [TnefObject] -> TnefAttachment
42 | length xs < 5 = NilAttachment
43 | otherwise = TnefAttachment m d f mf a
45 m = get_first_with_name xs "Attachment Modification Date"
46 d = get_first_with_name xs "Attachment Data"
47 f = get_first_with_name xs "Attachment File Name"
48 mf = get_first_with_name xs "Attachment Meta File"
49 a = get_first_with_name xs "Attachment"
51 safe_head :: [TnefObject] -> TnefObject
53 | ((length xs) == 0) = Nil
57 get_first_with_name :: [TnefObject] -> String -> TnefObject
58 get_first_with_name xs name =
59 safe_head (dropWhile ((/= name) . show . obj_name) xs)
62 write_attachment :: TnefAttachment -> IO ()
63 write_attachment NilAttachment = putStrLn "NilAttachment"
64 write_attachment x = do
65 write_tnef_object (show_data (att_file_name x)) (att_data x)