Removing headers from email, replacing rules with code

T

Tony Gravagno

Is there a standard way to remove headers from inbound mail items?
Can I do something with Redemption like this?:
sItem.Fields(PR_TRANSPORT_MESSAGE_HEADERS).Item(x).Delete()

Can I do this with PIA and C#?

The problem I'm trying to solve is that the Outlook 2003 rules
sometimes don't process. This could be because I have way too many
rules (about 150 now) but I think it's more because our mail server is
now adding a lot more header info to inbound mail. There is a long
stream of Received headers, headers to tell us how the server
anti-spam rated each mail item, and others. I think Outlook 2003 is
confused by so many headers because my filtering no longer works on
many items since we changed servers.

So before rules are processed, I want to remove selected headers.

I found some code by Ken Slovak for reading the headers:
Dim oPropAccessor As Outlook.PropertyAccessor
Const PR_MAIL_HEADER_TAG = _
"http://schemas.microsoft.com/mapi/proptag/0x007D001E"
'only works if Application.IsTrusted is True
Set oPropAccessor = oItem.PropertyAccessor


Another way to do this is with CDO:
Const CdoPR_TRANSPORT_MESSAGE_HEADERS = &H7D001E
strID = myItem.EntryID
Set objMessage = objCDO.GetMessage(strID)
Set objFields = objMessage.Fields
txt = objFields.Item(CdoPR_TRANSPORT_MESSAGE_HEADERS).Value
strHeaders = oPropAccessor.GetProperty(PR_MAIL_HEADER_TAG)

The question is whether or not we can modify the resulting header
string and then write back into these header fields.


This is the first part of a two-part effort. I've never liked Outlook
rules. I have about 150 of them (I know, too many) and they never
really did process properly, so I'm going to write C# code (maybe open
source) to replace the Outlook rules (unless someone can tell me
Outlook 2007 is VASTLY better). My first step is to remove junk
headers. The second step is to use the remaining headers and mail
item to match on user-defined strings and regexp patterns, sort mail
based on specs in Contact items and config files, etc.

Thanks!
Tony
TG@ removethisNebula-RnD.com
 
D

Dmitry Streblechenko

You can of course modify the headers using CDO 1.21/Redemption/MAPI, but you
will have to read the whole header as a string, modify it, then set back;
you cannot retrieve just a single line.
That won't help you at all however - chances are the rules will run before
your code gets a chance to execute.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
T

Tony Gravagno

As long as I know the collection of Headers is writable (get/set
rather than readonly) then I don't have a problem. I'll see what I
can do with CDO but for general use I would tend toward Redemption. I
haven't used it in a couple years, and never sold a commerical
offering with it but my experience was all good and I'm still itching
to make use of it...

Thanks again Dmitry,
Tony

Dmitry Streblechenko said:
You can of course modify the headers using CDO 1.21/Redemption/MAPI, but you
will have to read the whole header as a string, modify it, then set back;
you cannot retrieve just a single line.
That won't help you at all however - chances are the rules will run before
your code gets a chance to execute.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"Tony Gravagno" wrote
[snip]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top