Hacking Outlook Express - COM Interop
Written by Mike James   
Thursday, 23 July 2009
Article Index
Hacking Outlook Express - COM Interop
Creating a COM object
Exposing COM
OE Analysis
Mail analysis

 

Mail analysis

 

Now that we have the GetNextSubFolder method it is fairly easy to write an analysis program. This makes use of a TreeView component and recursion and both of these topics were discussed in some detail in issue 220 as part of the DiskAlyse project. Add a button and a TreeView control to the form and arrange them to make a reasonable user interface.

form

A TreeView control and a button ready to be used.

 

The recursive function subTree starts off by getting the first folder into a folder properties struct:

void subTree(
 Int32 FolderId,
TreeNode CurrentNode)
{
TreeNode node;
OE.FOLDERPROPS fp =
new OE.FOLDERPROPS();
fp = oe.GetNextSubFolder(
FolderId,fp.hEnum);

As long as there is a sub-folder we add its details to a new TreeNode and add this to the current node:

while (fp.hEnum!=0)
{
node = new TreeNode();
node.Text = fp.szName +
" (" +
fp.cMessage.ToString() + ")";
CurrentNode.Nodes.Add(node);

Of course this sub-folder might have sub-folders of its own so we call subTree again to deal with these:

subTree(fp.dwFolderId, node);

 

This is the magic of recursion and yes it does work. When subTree returns the program has dealt with all of the sub-folders of the current folder so we see if there is another one to process and repeat the loop:

 fp = oe.GetNextSubFolder(
 FolderId,fp.hEnum);
}
}

The While loop terminates as soon as we have run out of sub-folders.

All we need to analyse the entire folder structure is to give subTree a starting point in the hierarchy:

private void button1_Click(
object sender, EventArgs e)
{
oe = new OE();
TreeNode root=new TreeNode();
root.Text="Local Folders";
treeView1.Nodes.Add(root);
subTree(0,root);
}

When the user clicks the button a new OE object is created and the TreeView component is initialised with a root node called “Local Folders”. Then subTree is called with an initial folder ID of 0, i.e. the root folder, and a reference to the root node. Following this the subTree function does its work adding sub-folder details as additional nodes to the root node.

mail

A complicated mail folder structure.

 

Of course this is just the start of what you can do with the OE API. There is another entire interface that deals with manipulating messages including attachments, mail headers and bodies and you can create this from the IDL or header file in much the same way.

There are also lots of primitive COM objects that are still very much a part of the Windows API that you can now gain access to using the same techniques.

If you would like the code for this project then register and click on CodeBin.

<ASIN:0321562992>

<ASIN:0596001037>

<ASIN:0735607281>



Last Updated ( Wednesday, 16 September 2009 )
 
 

   
RSS feed of all content
I Programmer - full contents
Copyright © 2014 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.