I've created an Outlook addin that uses AdvancedSearch to find all emails with a UserProperty defined by my addin.
This works on my own desktop and laptop, but doesn't work on my customer's device. We're both using the newest version of Outlook from Office 365, however he's on Windows 7 and I'm on Windows 10. I suspect this might be a Group Policy issue since he's part of an organisation, but telling him that isn't useful unless I can point at what specific policy needs to be changed, or what exactly is causing the issue, so he can tell the IT department exactly what's wrong.
I've enabled error messages so I can see any exceptions, but none show up. The only time an exception is thrown (to my knowledge) is when the addin attempts to create the folders if they're already there; if the folders are deleted, no exceptions are thrown by the addin.
This is the code that adds the search folders
private void SearchFolders(Outlook.Application application)
{
string scope = "Inbox";
string filter = $"http://schemas.microsoft.com/mapi/string/{{00020329-0000-0000-C000-000000000046}}/{userProperty} = true";
Outlook.Search search = null;
Outlook.MAPIFolder folderInbox = null;
Outlook.MAPIFolder folderSentMail = null;
Outlook.NameSpace ns = null;
try
{
ns = application.GetNamespace("MAPI");
folderInbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
//MessageBox.Show(folderInbox.FolderPath.ToString());
folderSentMail = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
scope = "\'" + folderInbox.FolderPath + "\'";
search = application.AdvancedSearch(scope, filter, true);
search.Save("GDPR - indbakke");
scope = "\'" + folderSentMail.FolderPath + "\'";
search = application.AdvancedSearch(scope, filter, true);
search.Save("GDPR - Sendt post");
}
catch (Exception e)
{
MessageBox.Show(e.StackTrace, "An exception was thrown");
}
finally
{
if (search != null) Marshal.ReleaseComObject(search);
if (folderInbox != null) Marshal.ReleaseComObject(folderInbox);
if (folderSentMail != null) Marshal.ReleaseComObject(folderSentMail);
if (ns != null) Marshal.ReleaseComObject(ns);
}
}
The variable userProperty is instantiated as a string at the top of the file, and is simply the name of the UserProperty.
The search folders are supposed to include any mails that have the UserProperty set to true. However, the inbox search folder will sometimes include all emails in the inbox, while the "sent mail" search folder will just include nothing at all.
I know that marking the emails works on his device, since the column I added to show this property shows up, and shows that the email is marked correctly. It's just the search folders that don't work.
Looking at the search criteria in OutlookSpy shows me that the criteria are different on my computer compared to his. My PC shows the following:
rt : RES_PROPERTY
res.resProperty :
relop : RELOP_EQ
ulPropTag : GDPRMarked (0x8532000B)
lpProp :
ulPropTag : GDPRMarked (0x8532000B)
Value : true
while his PC shows this for the inbox:
rt : RES_EXIST
res.resExist :
ulPropTag : PR_SUBJECT_W (0x0037001F)
and this for the outgoing:
rt : RES_PROPERTY
res.resProperty :
relop : RELOP_EQ
ulPropTag : http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/GDPRMarked (0x8569001F)
lpProp :
ulPropTag : http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/GDPRMarked (0x8569001F)
Value : true