views:

805

answers:

2

What I do now with Outlook:

I receive email orders for products. I select a single or multiple emails in Outlook (a single order can have multiple emails associated with it) and then switch to my Delphi coded OrderManager program and click "Import". It uses Outlook's COM automation interface to read the text of each message, parses and processes each one.

The question is, can I do this using Thunderbird instead? Does Thunderbird have a COM interface? I must be googling the wrong keywords because I haven't found anything yet.

Btw, I do have a version of my OrderManager that just reads the emails directly from my email server using Indy, but for several reasons I'd like to try to read them from Firefox.

Any suggestions, links to docs, or code samples will be greatly appreciated!

+3  A: 

Check this link out.

You could write a C or C++ wrapper around XPCOM and then use that wrapper within Delphi.

There is also an open source XPCOM wrapper written in Delphi. You might want to check that out as well. Thanks Stijn for pointing that out.

Hope it helps.

Pablo Santa Cruz
I've been using this XPCOM wrapper in Delphi: http://d-gecko.svn.sourceforge.net/viewvc/d-gecko/trunk/GeckoSDK/
Stijn Sanders
Thanks Pablo and Stijn! That's extremely helpful.
MarkF
+2  A: 

You could also parse Thunderbird's mailbox files yourself.

  • From %APPDATA%\Thunderbird\profiles.ini, read where the profile folder is located (if there's more than one profile, look through sections Profile0..Profilen for the one that has the value Default=1)
  • Each subfolder of the Mail and/or ImapMail subfolders of the profile folder represents an account (Mail contains POP accounts, ImapMail contains IMAP accounts);
  • Look through all files whose names don't end with .dat or .msf, and whose contents start with 'From ' (F, r, o, m, and a space). Those are the mailbox files.
  • Every line that starts with 'From ' indicates a new message. Use the X-Mozilla-Status header to figure out whether the message is still valid, or whether it's been marked for deletion. (You can use the CDO.Message COM object to parse the message for you, if you want).

You should recurse for each subfolder ending on '.sbd', since that will contain that mailbox's subfolders (E.g. Inbox.sbd will contain the mail folders under the Inbox).

Be wary of file locking issues, however.

Martijn