PST File Format SDK v0.4
Loading...
Searching...
No Matches
folder.h
Go to the documentation of this file.
1
11
12#ifndef PSTSDK_PST_FOLDER_H
13#define PSTSDK_PST_FOLDER_H
14
15#include <algorithm>
16#include <boost/iterator/filter_iterator.hpp>
17#include <boost/iterator/transform_iterator.hpp>
18
20#include "pstsdk/util/errors.h"
21
23
24#include "pstsdk/ltp/propbag.h"
25#include "pstsdk/ltp/table.h"
26
27#include "pstsdk/pst/message.h"
28#include "pstsdk/mapitags.h"
29
30namespace pstsdk
31{
32
35
44template<node_id Type>
46{
48 { return get_nid_type(info.id) == Type; }
50 { return get_nid_type(row.get_row_id()) == Type; }
51};
52
63{
64public:
66 typedef boost::transform_iterator<message_transform_row, const_table_row_iter> message_iterator;
67
72 : m_db(db), m_bag(n) { }
75
76#ifndef BOOST_NO_RVALUE_REFERENCES
79 : m_db(std::move(other.m_db)), m_bag(std::move(other.m_bag)), m_contents_table(std::move(other.m_contents_table)) { }
80#endif
81
82 // subobject discovery/enumeration
86 { return boost::make_transform_iterator(get_contents_table().begin(), message_transform_row(m_db)); }
90 { return boost::make_transform_iterator(get_contents_table().end(), message_transform_row(m_db)); }
91
92 // property access
95 std::wstring get_name() const
96 { return m_bag.read_prop<std::wstring>(PR_DISPLAY_NAME_W); }
100 { return m_bag.read_prop<slong>(PR_CONTENT_UNREAD); }
103 size_t get_message_count() const
104 { return m_bag.read_prop<slong>(PR_CONTENT_COUNT); }
105
106 // lower layer access
110 { return m_bag; }
113 { return m_bag; }
117 { return m_db; }
122 const table& get_contents_table() const;
123
127 { return m_bag.get_node().get_id(); }
128
129private:
130 shared_db_ptr m_db;
131 property_bag m_bag;
132 mutable std::shared_ptr<table> m_contents_table;
133};
134
141{
142public:
151 { return search_folder(m_db, m_db->lookup_node(row.get_row_id())); }
152
153private:
154 shared_db_ptr m_db;
155};
156
157class folder;
163{
164public:
168 : m_db(db) { }
172 folder operator()(const const_table_row& row) const;
173
174private:
175 shared_db_ptr m_db;
176};
177
191{
192 typedef boost::filter_iterator<is_nid_type<nid_type_search_folder>, const_table_row_iter> search_folder_filter_iterator;
193 typedef boost::filter_iterator<is_nid_type<nid_type_folder>, const_table_row_iter> folder_filter_iterator;
194
195public:
197 typedef boost::transform_iterator<message_transform_row, const_table_row_iter> message_iterator;
199 typedef boost::transform_iterator<folder_transform_row, folder_filter_iterator> folder_iterator;
201 typedef boost::transform_iterator<search_folder_transform_row, search_folder_filter_iterator> search_folder_iterator;
202
206 folder(const shared_db_ptr& db, const node& n)
207 : m_db(db), m_bag(n) { }
210 folder(const folder& other);
211
212#ifndef BOOST_NO_RVALUE_REFERENCES
216 : m_db(std::move(other.m_db)), m_bag(std::move(other.m_bag)), m_contents_table(std::move(other.m_contents_table)), m_associated_contents_table(std::move(other.m_associated_contents_table)), m_hierarchy_table(std::move(other.m_hierarchy_table)) { }
217#endif
218
219 // subobject discovery/enumeration
223 { return boost::make_transform_iterator(boost::make_filter_iterator<is_nid_type<nid_type_folder> >(get_hierarchy_table().begin(), get_hierarchy_table().end()), folder_transform_row(m_db)); }
227 { return boost::make_transform_iterator(boost::make_filter_iterator<is_nid_type<nid_type_folder> >(get_hierarchy_table().end(), get_hierarchy_table().end()), folder_transform_row(m_db)); }
228
232 { return boost::make_transform_iterator(boost::make_filter_iterator<is_nid_type<nid_type_search_folder> >(get_hierarchy_table().begin(), get_hierarchy_table().end()), search_folder_transform_row(m_db)); }
236 { return boost::make_transform_iterator(boost::make_filter_iterator<is_nid_type<nid_type_search_folder> >(get_hierarchy_table().begin(), get_hierarchy_table().end()), search_folder_transform_row(m_db)); }
237
242 folder open_sub_folder(const std::wstring& name);
243
246 { return boost::make_transform_iterator(get_contents_table().begin(), message_transform_row(m_db)); }
249 { return boost::make_transform_iterator(get_contents_table().end(), message_transform_row(m_db)); }
250
254 { return boost::make_transform_iterator(get_associated_contents_table().begin(), message_transform_row(m_db)); }
258 { return boost::make_transform_iterator(get_associated_contents_table().end(), message_transform_row(m_db)); }
259
260 // property access
262 std::wstring get_name() const
263 { return m_bag.read_prop<std::wstring>(PR_DISPLAY_NAME_W); }
266 size_t get_subfolder_count() const
267 { return get_hierarchy_table().size(); }
270 { return m_bag.read_prop<slong>(PR_CONTENT_UNREAD); }
272 size_t get_message_count() const
273 { return m_bag.read_prop<slong>(PR_CONTENT_COUNT); }
278
279 // lower layer access
282 { return m_bag; }
285 { return m_bag; }
288 { return m_db; }
298 const table& get_hierarchy_table() const;
300 const table& get_contents_table() const;
303
307 { return m_bag.get_node().get_id(); }
308
309private:
310 shared_db_ptr m_db;
311 property_bag m_bag;
312 mutable std::shared_ptr<table> m_contents_table;
313 mutable std::shared_ptr<table> m_associated_contents_table;
314 mutable std::shared_ptr<table> m_hierarchy_table;
315};
316
322{
323public:
327 : m_db(db) { }
332 { return folder(m_db, node(m_db, info)); }
333
334private:
335 shared_db_ptr m_db;
336};
337
338} // end namespace pstsdk
339
341: m_db(other.m_db), m_bag(other.m_bag)
342{
343 if(other.m_contents_table)
344 m_contents_table.reset(new table(*other.m_contents_table));
345}
346
348: m_db(other.m_db), m_bag(other.m_bag)
349{
350 if(other.m_contents_table)
351 m_contents_table.reset(new table(*other.m_contents_table));
352 if(other.m_associated_contents_table)
353 m_contents_table.reset(new table(*other.m_associated_contents_table));
354 if(other.m_hierarchy_table)
355 m_contents_table.reset(new table(*other.m_hierarchy_table));
356}
357
359{
360 return folder(m_db, m_db->lookup_node(row.get_row_id()));
361}
362
364{
365 if(!m_contents_table)
366 m_contents_table.reset(new table(m_db->lookup_node(make_nid(nid_type_search_contents_table, get_nid_index(m_bag.get_node().get_id())))));
367
368 return *m_contents_table;
369}
370
372{
373 return const_cast<table&>(const_cast<const search_folder*>(this)->get_contents_table());
374}
375
376
378{
379
380struct folder_name_equal
381{
382 folder_name_equal(const std::wstring& name) : m_name(name) { }
383 bool operator()(const pstsdk::folder& f) const { return f.get_name() == m_name; }
384 std::wstring m_name;
385};
386
387} // end namespace compiler_workarounds
388
390{
391 folder_iterator iter = std::find_if(sub_folder_begin(), sub_folder_end(), compiler_workarounds::folder_name_equal(name));
392
393 if(iter != sub_folder_end())
394 return *iter;
395
397}
398
400{
401 if(!m_contents_table)
402 m_contents_table.reset(new table(m_db->lookup_node(make_nid(nid_type_contents_table, get_nid_index(m_bag.get_node().get_id())))));
403
404 return *m_contents_table;
405}
406
408{
409 return const_cast<table&>(const_cast<const folder*>(this)->get_contents_table());
410}
411
413{
414 if(!m_hierarchy_table)
415 m_hierarchy_table.reset(new table(m_db->lookup_node(make_nid(nid_type_hierarchy_table, get_nid_index(m_bag.get_node().get_id())))));
416
417 return *m_hierarchy_table;
418}
419
421{
422 return const_cast<table&>(const_cast<const folder*>(this)->get_hierarchy_table());
423}
424
426{
427 if(!m_associated_contents_table)
428 m_associated_contents_table.reset(new table(m_db->lookup_node(make_nid(nid_type_associated_contents_table, get_nid_index(m_bag.get_node().get_id())))));
429
430 return *m_associated_contents_table;
431}
432
434{
435 return const_cast<table&>(const_cast<const folder*>(this)->get_associated_contents_table());
436}
437
438#endif
heap_id get_id() const
Return the heap_id of this bth_node.
Definition heap.h:322
Contains references to other bth_node allocations.
Definition heap.h:364
T read_prop(prop_id id) const
Read a property as a given type.
Definition object.h:188
The iterator type exposed by the table for row iteration.
Definition table.h:94
An abstraction of a table row.
Definition table.h:51
Defines a transform from a node_info to a folder.
Definition folder.h:322
folder_transform_info(const shared_db_ptr &db)
Construct a folder_transform_info object.
Definition folder.h:326
folder operator()(const node_info &info) const
Perform the transform.
Definition folder.h:331
Defines a transform from a row of a hierarchy table to a folder.
Definition folder.h:163
folder_transform_row(const shared_db_ptr &db)
Construct a folder_transform_row object.
Definition folder.h:167
folder operator()(const const_table_row &row) const
Perform the transform.
Definition folder.h:358
A folder in a PST file.
Definition folder.h:191
size_t get_associated_message_count() const
Get the number of associated messages in this folder.
Definition folder.h:276
node_id get_id() const
Get the node_id of this folder.
Definition folder.h:306
size_t get_unread_message_count() const
Get the number of unread messages in this folder.
Definition folder.h:269
table & get_associated_contents_table()
Get the associated contents table of this folder.
Definition folder.h:433
size_t get_subfolder_count() const
Get the number of sub folders in this folder.
Definition folder.h:266
message_iterator message_end() const
Get the end message iterator.
Definition folder.h:248
size_t get_message_count() const
Get the number of messages in this folder.
Definition folder.h:272
shared_db_ptr get_db() const
Get the database pointer used by this folder.
Definition folder.h:287
folder open_sub_folder(const std::wstring &name)
Open a specific subfolder in this folder, not recursive.
Definition folder.h:389
property_bag & get_property_bag()
Get the property bag backing this folder.
Definition folder.h:281
search_folder_iterator sub_search_folder_begin() const
Get an iterator to the first search folder in this folder.
Definition folder.h:231
table & get_hierarchy_table()
Get the hierarchy table of this folder.
Definition folder.h:420
message_iterator associated_message_begin() const
Get an iterator to the first associated message in this folder.
Definition folder.h:253
message_iterator message_begin() const
Get an iterator to the first message in this folder.
Definition folder.h:245
boost::transform_iterator< search_folder_transform_row, search_folder_filter_iterator > search_folder_iterator
Search folder iterator type; a transform iterator over a filter iterator over table row iterator.
Definition folder.h:201
const property_bag & get_property_bag() const
Get the property bag backing this folder.
Definition folder.h:284
folder(folder &&other)
Move construct a folder object.
Definition folder.h:215
std::wstring get_name() const
Get the display name of this folder.
Definition folder.h:262
boost::transform_iterator< message_transform_row, const_table_row_iter > message_iterator
Message iterator type; a transform iterator over a table row iterator.
Definition folder.h:197
folder_iterator sub_folder_begin() const
Get an iterator to the first folder in this folder.
Definition folder.h:222
folder_iterator sub_folder_end() const
Get the end folder iterator.
Definition folder.h:226
table & get_contents_table()
Get the contents table of this folder.
Definition folder.h:407
boost::transform_iterator< folder_transform_row, folder_filter_iterator > folder_iterator
Folder iterator type; a transform iterator over a filter iterator over table row iterator.
Definition folder.h:199
search_folder_iterator sub_search_folder_end() const
Get the end search folder iterator.
Definition folder.h:235
folder(const shared_db_ptr &db, const node &n)
Construct a folder object.
Definition folder.h:206
message_iterator associated_message_end() const
Get the end associated message iterator.
Definition folder.h:257
An in memory representation of the "node" concept in a PST data file.
Definition node.h:320
Property Context (PC) Implementation.
Definition propbag.h:41
const node & get_node() const
Get the node underlying this property_bag.
Definition propbag.h:77
Defines a transform from a row of a hierarchy table to a search_folder.
Definition folder.h:141
search_folder_transform_row(const shared_db_ptr &db)
Construct a search_folder_transform object.
Definition folder.h:145
search_folder operator()(const const_table_row &row) const
Perform the transform.
Definition folder.h:150
Search Folder object.
Definition folder.h:63
size_t get_message_count() const
Get the number of messages in this folder.
Definition folder.h:103
search_folder(const shared_db_ptr &db, const node &n)
Construct a search folder object.
Definition folder.h:71
const property_bag & get_property_bag() const
Get the property bag backing this folder.
Definition folder.h:112
search_folder(search_folder &&other)
Move construct a search folder.
Definition folder.h:78
message_iterator message_end() const
Get the end message iterator.
Definition folder.h:89
shared_db_ptr get_db() const
Get the database pointer used by this folder.
Definition folder.h:116
node_id get_id() const
Get the node_id of this search folder.
Definition folder.h:126
std::wstring get_name() const
Get the display name of this folder.
Definition folder.h:95
boost::transform_iterator< message_transform_row, const_table_row_iter > message_iterator
Message iterator type; a transform iterator over a table row iterator.
Definition folder.h:66
message_iterator message_begin() const
Get an iterator to the first message in this folder.
Definition folder.h:85
size_t get_unread_message_count() const
Get the number of unread messages in this folder.
Definition folder.h:99
property_bag & get_property_bag()
Get the property bag backing this folder.
Definition folder.h:109
table & get_contents_table()
Get the contents table of this folder.
Definition folder.h:371
The actual table object that clients reference.
Definition table.h:308
size_t size() const
Get the number of rows in this table.
Definition table.h:362
Database interface.
The exceptions used by pstsdk.
ulong get_nid_index(node_id id)
Get a node index from a node id.
Definition primitives.h:231
nid_type get_nid_type(node_id id)
Get a node type from a node id.
Definition primitives.h:223
ulong node_id
Definition primitives.h:86
boost::int32_t slong
Definition primitives.h:69
#define make_nid(nid_type, nid_index)
Construct a node_id (NID) from a node type and index.
Definition primitives.h:160
@ nid_type_hierarchy_table
Definition primitives.h:134
@ nid_type_contents_table
Definition primitives.h:135
@ nid_type_search_contents_table
Definition primitives.h:137
@ nid_type_associated_contents_table
Definition primitives.h:136
#define PR_CONTENT_UNREAD
Definition mapitags.h:433
#define PR_DISPLAY_NAME_W
Definition mapitags.h:359
#define PR_CONTENT_COUNT
Definition mapitags.h:432
#define PR_ASSOC_CONTENT_COUNT
Definition mapitags.h:455
Message related classes.
Contains the definition of all in memory representations of disk structures.
Definition disk.h:19
std::shared_ptr< db_context > shared_db_ptr
Primitive structures defined by MS-PST and MAPI.
Property Bag (or Property Context, or PC) implementation.
Functor to determine if an object is of the specified node type.
Definition folder.h:46
bool operator()(const node_info &info)
Definition folder.h:47
bool operator()(const const_table_row &row)
Definition folder.h:49
An in memory, database format agnostic version of disk::nbt_leaf_entry.
Table (or Table Context, or TC) implementation.