Click here to Skip to main content
6,822,123 members and growing! (18,267 online)
Email Password   helpLost your password?
General Programming » Algorithms & Recipes » Parsers     Intermediate License: The Code Project Open License (CPOL)

DBX Parser

By Unruled Boy

Read Outlook Express DBX file, extract mail to EML file
C# (C#1.0, C#2.0, C#3.0), .NET, Visual-Studio, Dev
Revision:12 (See All)
Posted:30 Apr 2009
Updated:2 Jul 2009
Views:9,526
Bookmarked:33 times
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
15 votes for this article.
Popularity: 5.06 Rating: 4.30 out of 5
1 vote, 6.7%
1

2
2 votes, 13.3%
3
2 votes, 13.3%
4
10 votes, 66.7%
5

Introduction

The DBXParser can read an Outlook Express DBX file, and extract the raw content (MIME) to EML file, then you can use MIME parsers to get the actual subject body and attachments. It's the first and only (as far as Google tells) pure C# source code that provides simple methods to read and extract, free, pure, without over-headed third-party DLLs. ;)

Background

I've been searching for source code to read an Outlook Express DBX file for a very long time (believe me, it's really long). I have found quite a few DBX readers/codes in other languages, such as:

But none of them are pure C#, so I made my own. It's a good way to port similar codes from another language, here I choose the DBX Parser(PHP), because it's much simpler than the C++ version:)

Where Are My DBX Files?

Your DBX files will normally be found here:

C:\Documents and Settings\{UserName}\Local Settings\
	Application Data\Identities\{Guid}\Microsoft\Outlook Express 

Take a look at {Guid}, it's different on different computers, so all you need to do is to use Directory.GetFiles() to go through all the sub folders for searching *.dbx files.

File Format

I am not going to go deep into the file format here, because there are already quite a few documents there:

How It Works

It reads the raw DBX file, without any third-party or related DLLs provided by Outlook Express. It only reads through the file, decoding byte by byte, then internally stores the position and sizes of chunks of each message in order to be used by the Extract method, because it only stores the positions, so it uses very little memory.

Using the Code

First create a new instance of DBX, then use the Parse function to read the file, it will return how many messages the DBX file contains. If it returns -1, then it means there is something wrong with the file. Then you could use the Extract method to save the content to a file or to read the content to memory.

Here goes a sample code:

using (DBX DBX = new DBX())
{
    int count = DBX.Parse(@"test.dbx");	//specify your DBX file here
    if (count > 0)
    {
        for (int i = 0; i < count; i++)
        {
            DBX.Extract(i, (i + 1) + ".eml"); //specify file to extract to
            				//or just read the content to memory
            				//string content = DBX.Extract(i);
        }
    }
}

How to Decode MIME (EML File)?

Choose any one of the following codes that you like:

Points of Interest

Because I suffered a lot while finding such code, I contribute it here as others won't have to get crazy looking for it. After porting the code from PHP, I feel that PHP is really mature. There are different kinds of PHP codes out there, and I'm really surprised to see that even PHP has such a sample code, but Java/VB/C# do not. I try to keep this code as simple as possible, read and extract, that's all, which I think fits most of the situations. If you have any comments or suggestions, please feel free to tell me, or just modify the code yourself.

History

  • Version 1.0 - 2009-5-1
  • Version 1.1 - 2009-5-5: some code clean up, added a VC++ code
  • Version 1.2 - 2009-7-2: fixed a problem not correctly return the exact amount of mails in some special situations, thanks to Cato.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Unruled Boy


Member
I live in the south of China, started to write GWBASIC code since 1993 when I was 13 years old, with professional .net(c#) and vb, founder of www.xnlab.com
Occupation: Architect
Company: www.xnlab.com
Location: China China

Other popular Algorithms & Recipes articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 19 of 19 (Total in Forum: 19) (Refresh)FirstPrevNext
GeneralInteresting happenings... PinmemberDerek J Rouleau10:49 5 Feb '10  
GeneralEmail count always -1 Pinmembermhota21:18 30 Nov '09  
GeneralRe: Email count always -1 PinmemberUnruled Boy21:55 30 Nov '09  
Generaldbx error PinmemberPeso23:25 19 Aug '09  
GeneralRe: dbx error PinmemberUnruled Boy0:43 20 Aug '09  
GeneralMy vote of 1 Pinmemberabcd1234f9:37 10 Aug '09  
GeneralThank you PinmemberPepsibot14:08 22 Jul '09  
Generalnice Pinmemberpita200022:37 2 Jul '09  
GeneralRe: nice PinmemberUnruled Boy0:20 3 Jul '09  
GeneralIs it Extract only 10 Mails ? PinmemberLaxmilal Menaria22:15 30 Jun '09  
GeneralRe: Is it Extract only 10 Mails ? PinmemberUnruled Boy22:23 30 Jun '09  
GeneralRe: Is it Extract only 10 Mails ? PinmemberUnruled Boy16:52 2 Jul '09  
QuestionHow is it? Pinmembersjun117:15 27 May '09  
GeneralRe: How is it? PinmemberUnruled Boy1:01 30 May '09  
GeneralGreat! PinmemberSouthmountain7:11 1 May '09  
GeneralRe: Great! PinmemberUnruled Boy17:46 1 May '09  
Generalplease give comment or suggestions PinmemberUnruled Boy5:20 1 May '09  
GeneralUnveil ... Pinmemberkanu@adatapost0:26 1 May '09  
GeneralRe: Unveil ... PinmemberUnruled Boy5:19 1 May '09  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.

PermaLink | Privacy | Terms of Use
Last Updated: 2 Jul 2009
Editor: Sean Ewington
Copyright 2009 by Unruled Boy
Everything else Copyright © CodeProject, 1999-2010
Web17 | Advertise on the Code Project