1 //
2 // VMime library (http://www.vmime.org)
3 // Copyright (C) 2002-2013 Vincent Richard <vincent@vmime.org>
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 3 of
8 // the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // Linking this library statically or dynamically with other modules is making
20 // a combined work based on this library.  Thus, the terms and conditions of
21 // the GNU General Public License cover the whole combination.
22 //
23 
24 #ifndef VMIME_FILECONTENTHANDLER_HPP_INCLUDED
25 #define VMIME_FILECONTENTHANDLER_HPP_INCLUDED
26 
27 
28 #include "vmime/config.hpp"
29 
30 
31 #if VMIME_HAVE_FILESYSTEM_FEATURES
32 
33 
34 #include "vmime/streamContentHandler.hpp"
35 #include "vmime/utility/file.hpp"
36 
37 
38 namespace vmime
39 {
40 
41 
42 /** A content handler which obtains its data from a file.
43   */
44 
45 class VMIME_EXPORT fileContentHandler : public streamContentHandler
46 {
47 public:
48 
49 	/** Creates a new empty content handler. No data can be extracted until
50 	  * a file is attached using setData() function.
51 	  *
52 	  * @return a reference to a new content handler
53 	  */
54 	fileContentHandler();
55 
56 	/** Creates a new content handler using a file.
57 	  *
58 	  * @param file file from which data will be obtained
59 	  * @param enc set to anything other than NO_ENCODING if the data contained
60 	  * in the file is already encoded with the specified encoding
61 	  *
62 	  * @return a reference to a new content handler
63 	  */
64 	fileContentHandler
65 		(shared_ptr <utility::file> file,
66 		 const vmime::encoding& enc = NO_ENCODING);
67 
68 	~fileContentHandler();
69 
70 	fileContentHandler(const fileContentHandler& cts);
71 	fileContentHandler& operator=(const fileContentHandler& cts);
72 
73 	shared_ptr <contentHandler> clone() const;
74 
75 	/** Sets the data managed by this content handler.
76 	  *
77 	  * @param file file from which data will be obtained
78 	  * @param enc set to anything other than NO_ENCODING if the data contained
79 	  * in the file is already encoded with the specified encoding
80 	  */
81 	void setData
82 		(shared_ptr <utility::file> file,
83 		 const vmime::encoding& enc = NO_ENCODING);
84 
85 private:
86 
87 	// Equals to NO_ENCODING if data is not encoded, otherwise this
88 	// specifies the encoding that have been used to encode the data.
89 	vmime::encoding m_encoding;
90 
91 	// Actual data
92 	shared_ptr <utility::file> m_file;
93 };
94 
95 
96 } // vmime
97 
98 
99 #endif // VMIME_HAVE_FILESYSTEM_FEATURES
100 
101 
102 #endif // VMIME_FILECONTENTHANDLER_HPP_INCLUDED
103