Skip to content

Commit

Permalink
Compute MAPI PR_ENTRYID for messages and attachments
Browse files Browse the repository at this point in the history
In e-discovery applications, messages will often be referred to by a
MAPI PR_ENTRYID.  This is a computed property, as described here:

  http://pstsdk.codeplex.com/Thread/View.aspx?ThreadId=215111

Because this is a fairly useful property, and because it's relatively
hard to calculate, I feel it might be worth including somewhere in
pstsdk.

I wanted to implement a node::get_entry_id function, but because
get_entry_id needs access to the message store property bag, this would
have made the ndb layer depend on the ltp layer.

Thus, this patch provides a property_bag::get_entry_id() function, which
does not require any additional dependencies between layers.
  • Loading branch information
emk committed Jul 9, 2010
1 parent adb4032 commit 82f2bf9
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pstsdk/ltp/propbag.h
Expand Up @@ -79,6 +79,10 @@ class property_bag : public const_property_object
//! \returns The node
node& get_node() { return m_pbth->get_node(); }

//! \brief Get the MAPI entry id for this node's property bag.
//! \returns The MAPI entry id
std::vector<byte> get_entry_id() const;

private:
property_bag& operator=(const property_bag& other); // = delete

Expand Down Expand Up @@ -241,4 +245,25 @@ inline pstsdk::hnid_stream_device pstsdk::property_bag::open_prop_stream(prop_id
else
return m_pbth->get_heap_ptr()->open_stream(h_id);
}

inline std::vector<pstsdk::byte> pstsdk::property_bag::get_entry_id() const {
using namespace std;

// A MAPI entry id contains 4 leading 0 bytes, the data store ID, and
// the node ID.
vector<byte> entry_id(4, 0);

node store(get_node().get_db()->lookup_node(nid_message_store));
property_bag store_props(store);
vector<byte> store_id(store_props.read_prop<vector<byte> >(0x0ff9));
copy(store_id.begin(), store_id.end(),
insert_iterator<vector<byte> >(entry_id, entry_id.end()));

node_id nid(get_node().get_id());
for (int i = sizeof(node_id) - 1; i >= 0; --i)
entry_id.push_back((nid >> 8*i) & 0xff);

return entry_id;
}

#endif
10 changes: 10 additions & 0 deletions pstsdk/pst/message.h
Expand Up @@ -91,6 +91,11 @@ class attachment
const property_bag& get_property_bag() const
{ return m_bag; }

//! \brief Get the MAPI entry ID of this attachment
//! \returns The MAPI entry ID of this attachment
std::vector<byte> get_entry_id() const
{ return m_bag.get_entry_id(); }

private:
attachment& operator=(const attachment&); // = delete
friend class message;
Expand Down Expand Up @@ -346,6 +351,11 @@ class message
node_id get_id() const
{ return m_bag.get_node().get_id(); }

//! \brief Get the MAPI entry ID of this message
//! \returns The MAPI entry ID of this message
std::vector<byte> get_entry_id() const
{ return m_bag.get_entry_id(); }

private:
message& operator=(const message&); // = delete

Expand Down
25 changes: 25 additions & 0 deletions test/pstlevel.cpp
Expand Up @@ -89,6 +89,28 @@ void process_pst(const pstsdk::pst& p)
process_folder(root);
}

void test_entry_id(pstsdk::pst& p) {
using namespace std;
using namespace pstsdk;

message m(*p.message_begin());
attachment a(*m.attachment_begin());

const byte expected1_bytes[24] = {
0x00, 0x00, 0x00, 0x00, 0x6a, 0x55, 0x2b, 0x81, 0x3c, 0x43, 0xf9, 0x43,
0x84, 0xf1, 0x8b, 0x7d, 0xa2, 0x39, 0x3e, 0x95, 0x00, 0x20, 0x00, 0x24
};
vector<byte> expected1(expected1_bytes, expected1_bytes + 24);
assert(expected1 == m.get_entry_id());

const byte expected2_bytes[24] = {
0x00, 0x00, 0x00, 0x00, 0x6a, 0x55, 0x2b, 0x81, 0x3c, 0x43, 0xf9, 0x43,
0x84, 0xf1, 0x8b, 0x7d, 0xa2, 0x39, 0x3e, 0x95, 0x00, 0x00, 0x80, 0x25
};
vector<byte> expected2(expected2_bytes, expected2_bytes + 24);
assert(expected2 == a.get_entry_id());
}

void test_pstlevel()
{
using namespace pstsdk;
Expand All @@ -107,4 +129,7 @@ void test_pstlevel()

// make sure searching by name works
process_folder(uni.open_folder(L"Folder"));

// make sure we can calculate entry_id values
test_entry_id(s1);
}

0 comments on commit 82f2bf9

Please sign in to comment.