How to programmatically test if message is digitally signed?

D

deko

I use automation with Access 2003 to search and inspect email messages (to
get sender, recipients, etc.) in Outlook folders. But if a message is
encrypted or digitally signed, it cannot be inspected. I want to test to
see if a message is encrypted or digitally signed so I can skip or otherwise
indicate in the search results that some messages could not be inspected.
What is happening now is that when the For Loop comes to an encrypted or
digitally signed message, it gets a Type Mismatch error and exits the loop -
so the search is incomplete, especially if the error is received early in
the search. Here is the For Loop I am using:

Dim olmi As Outlook.MailItem
Dim olrs As Outlook.Recipients
Dim olR as Outlook.Recipient
strE = email address I am looking for
For Each olmi In olFolder.Items 'look at every message in folder
Set olrs = olmi.Recipients
For Each olR In olrs
'check every recipient the message was sent to
If olR.Address = strE And olmi.SenderEmailAddress <> olR.Address
Then
[code omitted]
Next
'check sender address
If strFn <> "Sent Items" And olmi.SenderEmailAddress = strE Then
[code omitted]
End If
Next olmi

What property can I inspect to check to see if a message is digitally signed
or encrypted? Or is it possible to automate Outlook in some way so I don't
have to use this loop, but rather use Outlook's own search capabilities?

Thanks in advance.
 
D

deko

What property can I inspect to check to see if a message is digitally
signed
or encrypted? Or is it possible to automate Outlook in some way so I don't
have to use this loop, but rather use Outlook's own search capabilities?

It appears that you cannot automate the Advanced Find feature. And I doubt
there is anything that can be done with VBA to inspect a digitally signed or
encrypted message. More functionality sacrificed on the altar of
security...

http://support.microsoft.com/default.aspx?scid=kb;EN-US;170783
Q: How can I programmatically search for items and folders based on the
contents of a field?
A: You cannot programmatically use the Find or Advanced Find features in
Outlook, but you can use the Find method in the Outlook object model to
retrieve a single item based on the contents of one or more fields. You can
also use the Restrict method to retrieve a set of items that match certain
criteria. For additional information about how to use the Find and Restrict
methods, click the article numbers below to view the articles in the
Microsoft Knowledge Base:
171115 OL97: How to Use the Restrict Method 174476 OL97: How to Use
Variables with Find and Restrict Filters

Still looking for a way to test if a message is digitally signed or not...
 
K

Ken Slovak - [MVP - Outlook]

You can certainly tell if a message is signed or encrypted by looking at its
MessageClass. It will usually be something like IPM.Note.SMIME.xxx or
IPM.Note.Secure.xxx and so on. Look at KB article Q194623 for information
related to checking things using CDO 1.21 code.

You can program the equivalent of AdvancedSearch if you are using Outlook
2002 or later using the Application.AdvancedSearch method.

You are better off posting programming questions in a group like
microsoft.public.outlook.program_vba, where the developers hang out.
 
D

deko

You can certainly tell if a message is signed or encrypted by looking at
its
MessageClass. It will usually be something like IPM.Note.SMIME.xxx or
IPM.Note.Secure.xxx and so on. Look at KB article Q194623 for information
related to checking things using CDO 1.21 code.

I looked at that KB article - it was helpful, but shows how to do it with an
Exchange server, rahter than with local PST folders (which is what I'm
using). I assume I can use CDO with local PSTs, so I'm working on this now,
and have posted to the microsoft.public.outlook.program_vba newsgroup as you
suggested.
You can program the equivalent of AdvancedSearch if you are using Outlook
2002 or later using the Application.AdvancedSearch method.

That sounds interesting. I'm guessing that would be quicker than looping
through and inspecting porperties with VBA as I am donig now. But would
results only be returned in the Outhlok interface? I'm trying to populate
an Access table with message header info like sender. recipient, subject,
date sent, etc.

Thanks for the help.
 
K

Ken Slovak - [MVP - Outlook]

CDO 1.21 can be used from Outlook code but it's an optional installation for
Outlook 2000 and later so you have to make sure it's installed. An
alternative, that isn't limited by the Outlook security, is Redemption (3rd
party library located at www.dimastr.com/redemption). Redemption coding is
similar to CDO 1.21 coding.

The results of the AdvancedSearch method isn't displayed in the UI. You can
get the results using code however. That method returns a Search object and
the Search object's Results collection can be iterated to get data from each
item in Results. It's definitely quicker than looping over an Items
collection and can be used to search in more than one folder.
 
D

deko

CDO 1.21 can be used from Outlook code but it's an optional installation
for
Outlook 2000 and later so you have to make sure it's installed. An
alternative, that isn't limited by the Outlook security, is Redemption (3rd
party library located at www.dimastr.com/redemption). Redemption coding is
similar to CDO 1.21 coding.

Hi and thanks for the reply. I have looked at Redemption, but would like to
avoid adding additional complexity to my app. Being able to circumvent the
annoying security prompt is a bit plus, however.
The results of the AdvancedSearch method isn't displayed in the UI. You can
get the results using code however. That method returns a Search object and
the Search object's Results collection can be iterated to get data from each
item in Results. It's definitely quicker than looping over an Items
collection and can be used to search in more than one folder.

That sounds like what I'm looking for. I found this KB article -
http://support.microsoft.com/?kbid=307922
"How to Use the Query Builder for View Filters and Advanced Searches" - is
this the kind of thing you are referring to? What I want to do is search
all messages (including digitally signed and encrypted messages) in local
PSTs (including user-defined PSTs) for stuff like sender and recipient email
addresses, subject line, date sent/received - and populate an Access table
with the results. The problem I ran into with VBA and the standard Outlook
object model was that I could not inspect the properties of
encrypted/digitally signed messages. Also, Speed was not that great. I am
hoping I can find a way to solve both the speed issue and the encrypted
message problem using the Advanced Search method. If you can point me to
any code samples, that would be great. I am using Outlook 2003, by the way.
 
K

Ken Slovak - [MVP - Outlook]

There might be some code samples on www.outlookcode.com and in the MSDN
library. You won't get anywhere inspecting signed or encrypted messages, if
you could that would negate their security completely. An AdvancedSearch can
search across multiple folders in the same InfoStore (PST file or Exchange
mailbox) but cannot search across multiple InfoStores. You would have to set
up individual searches for each InfoStore that's loaded. Speed should be
much faster using that than other methods.
 

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