3 Folder Class implementation.
5 Copyright (C) Alan Alvarez 2008.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <libmapi++/folder.h>
25 folder::message_container_type folder::fetch_messages() throw(mapi_exception)
27 uint32_t contents_table_row_count = 0;
28 mapi_object_t contents_table;
30 mapi_object_init(&contents_table);
31 if (GetContentsTable(&m_object, &contents_table, 0, &contents_table_row_count) != MAPI_E_SUCCESS) {
32 mapi_object_release(&contents_table);
33 throw mapi_exception(GetLastError(), "folder::fetch_messages : GetContentsTable");
36 SPropTagArray* property_tag_array = set_SPropTagArray(m_session.get_memory_ctx(), 0x2, PR_FID,
39 if (SetColumns(&contents_table, property_tag_array) != MAPI_E_SUCCESS) {
40 MAPIFreeBuffer(property_tag_array);
41 mapi_object_release(&contents_table);
42 throw mapi_exception(GetLastError(), "folder::fetch_messages : SetColumns");
45 MAPIFreeBuffer(property_tag_array);
47 uint32_t rows_to_read = contents_table_row_count;
50 message_container_type message_container;
51 message_container.reserve(contents_table_row_count);
53 while( (QueryRows(&contents_table, rows_to_read, TBL_ADVANCE, &row_set) == MAPI_E_SUCCESS) && row_set.cRows) {
54 rows_to_read -= row_set.cRows;
55 for (unsigned int i = 0; i < row_set.cRows; ++i) {
57 message_container.push_back(message_shared_ptr(new message(m_session,
59 row_set.aRow[i].lpProps[1].value.d)));
60 } catch(mapi_exception e) {
61 mapi_object_release(&contents_table);
67 mapi_object_release(&contents_table);
69 return message_container;
72 folder::hierarchy_container_type folder::fetch_hierarchy() throw(mapi_exception)
74 mapi_object_t hierarchy_table;
75 uint32_t hierarchy_table_row_count = 0;
77 mapi_object_init(&hierarchy_table);
78 if (GetHierarchyTable(&m_object, &hierarchy_table, 0, &hierarchy_table_row_count) != MAPI_E_SUCCESS) {
79 mapi_object_release(&hierarchy_table);
80 throw mapi_exception(GetLastError(), "folder::fetch_hierarchy : GetHierarchyTable");
83 SPropTagArray* property_tag_array = set_SPropTagArray(m_session.get_memory_ctx(), 0x1, PR_FID);
85 if (SetColumns(&hierarchy_table, property_tag_array)) {
86 MAPIFreeBuffer(property_tag_array);
87 mapi_object_release(&hierarchy_table);
88 throw mapi_exception(GetLastError(), "folder::fetch_hierarchy : SetColumns");
91 MAPIFreeBuffer(property_tag_array);
93 uint32_t rows_to_read = hierarchy_table_row_count;
96 hierarchy_container_type hierarchy_container;
97 hierarchy_container.reserve(hierarchy_table_row_count);
99 while( (QueryRows(&hierarchy_table, rows_to_read, TBL_ADVANCE, &row_set) == MAPI_E_SUCCESS) && row_set.cRows) {
100 rows_to_read -= row_set.cRows;
101 for (unsigned int i = 0; i < row_set.cRows; ++i) {
103 hierarchy_container.push_back(folder_shared_ptr(new folder(*this,
104 row_set.aRow[i].lpProps[0].value.d)));
105 } catch(mapi_exception e) {
106 mapi_object_release(&hierarchy_table);
112 mapi_object_release(&hierarchy_table);
114 return hierarchy_container;
117 } // namespace libmapipp