diff options
author | Wojciech Polak <polak@gnu.org> | 2009-01-30 10:42:08 +0100 |
---|---|---|
committer | Wojciech Polak <polak@gnu.org> | 2009-01-30 20:43:44 +0100 |
commit | b2a91252acdd910a3ac5e866c0ecc578d86c4f94 (patch) | |
tree | edc2d26dee289c2e4b575e102cb5aad3b8d49877 /libmu_cpp/folder.cc | |
parent | 24d5aa4cbd4b2aec73dc9b275e8bc172973ed234 (diff) | |
download | mailutils-b2a91252acdd910a3ac5e866c0ecc578d86c4f94.tar.gz mailutils-b2a91252acdd910a3ac5e866c0ecc578d86c4f94.tar.bz2 |
Add Folder class to libmu_cpp. Provide new examples lsf.cc and msg-send.cc.
* examples/cpp/lsf.cc, examples/cpp/msg-send.cc,
include/mailutils/cpp/folder.h, libmu_cpp/folder.cc: New files.
Diffstat (limited to 'libmu_cpp/folder.cc')
-rw-r--r-- | libmu_cpp/folder.cc | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/libmu_cpp/folder.cc b/libmu_cpp/folder.cc new file mode 100644 index 000000000..d4dc2afb5 --- /dev/null +++ b/libmu_cpp/folder.cc | |||
@@ -0,0 +1,136 @@ | |||
1 | /* | ||
2 | GNU Mailutils -- a suite of utilities for electronic mail | ||
3 | Copyright (C) 2009 Free Software Foundation, Inc. | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 3 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library 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 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General | ||
16 | Public License along with this library; if not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301 USA | ||
19 | */ | ||
20 | |||
21 | #include <mailutils/cpp/folder.h> | ||
22 | #include <mailutils/cpp/error.h> | ||
23 | #include <errno.h> | ||
24 | |||
25 | using namespace mailutils; | ||
26 | |||
27 | // | ||
28 | // Folder | ||
29 | // | ||
30 | |||
31 | Folder :: Folder (const std::string& name) | ||
32 | { | ||
33 | int status = mu_folder_create (&folder, name.c_str ()); | ||
34 | if (status) | ||
35 | throw Exception ("Folder::Folder", status); | ||
36 | } | ||
37 | |||
38 | Folder :: Folder (const mu_folder_t folder) | ||
39 | { | ||
40 | if (folder == 0) | ||
41 | throw Exception ("Folder::Folder", EINVAL); | ||
42 | |||
43 | this->folder = folder; | ||
44 | } | ||
45 | |||
46 | Folder& | ||
47 | Folder :: operator = (const Folder& f) | ||
48 | { | ||
49 | if (this != &f) | ||
50 | { | ||
51 | if (this->folder) | ||
52 | mu_folder_destroy (&this->folder); | ||
53 | this->folder = f.folder; | ||
54 | } | ||
55 | return *this; | ||
56 | } | ||
57 | |||
58 | Folder :: ~Folder () | ||
59 | { | ||
60 | mu_folder_destroy (&folder); | ||
61 | } | ||
62 | |||
63 | |||
64 | void | ||
65 | Folder :: open () | ||
66 | { | ||
67 | int status = mu_folder_open (folder, MU_STREAM_READ); | ||
68 | if (status) | ||
69 | throw Exception ("Folder::open", status); | ||
70 | } | ||
71 | |||
72 | void | ||
73 | Folder :: open (int flag) | ||
74 | { | ||
75 | int status = mu_folder_open (folder, flag); | ||
76 | if (status) | ||
77 | throw Exception ("Folder::open", status); | ||
78 | } | ||
79 | |||
80 | void | ||
81 | Folder :: close () | ||
82 | { | ||
83 | int status = mu_folder_close (folder); | ||
84 | if (status) | ||
85 | throw Exception ("Folder::close", status); | ||
86 | } | ||
87 | |||
88 | List& | ||
89 | Folder :: list (const std::string& dirname, void* pattern, size_t max_level) | ||
90 | { | ||
91 | mu_list_t c_list; | ||
92 | |||
93 | int status = mu_folder_list (folder, dirname.c_str (), pattern, | ||
94 | max_level, &c_list); | ||
95 | if (status) | ||
96 | throw Exception ("Folder::list", status); | ||
97 | |||
98 | return *new List (c_list); | ||
99 | } | ||
100 | |||
101 | List& | ||
102 | Folder :: enumerate (const std::string& name, void* pattern, | ||
103 | int flags, size_t max_level, | ||
104 | mu_folder_enumerate_fp enumfun, void* enumdata) | ||
105 | { | ||
106 | mu_list_t c_list; | ||
107 | |||
108 | int status = mu_folder_enumerate (folder, name.c_str (), pattern, | ||
109 | flags, max_level, &c_list, | ||
110 | enumfun, enumdata); | ||
111 | if (status) | ||
112 | throw Exception ("Folder::enumerate", status); | ||
113 | |||
114 | return *new List (c_list); | ||
115 | } | ||
116 | |||
117 | Stream& | ||
118 | Folder :: get_stream () | ||
119 | { | ||
120 | mu_stream_t c_stream; | ||
121 | |||
122 | int status = mu_folder_get_stream (folder, &c_stream); | ||
123 | if (status) | ||
124 | throw Exception ("Folder::get_stream", status); | ||
125 | |||
126 | return *new Stream (c_stream); | ||
127 | } | ||
128 | |||
129 | void | ||
130 | Folder :: set_stream (const Stream& stream) | ||
131 | { | ||
132 | int status = mu_folder_set_stream (folder, stream.stm); | ||
133 | if (status) | ||
134 | throw Exception ("Folder::set_stream", status); | ||
135 | } | ||
136 | |||