0
votes

I'm working on an Outlook 2013 plugin that needs to access the emails currently displayed in the email list pane.

I already searched around a lot but I could only find ways to list emails within the current selected folder:

Outlook.MAPIFolder curFolder = this.Application.ActiveExplorer().CurrentFolder;
Outlook.Items mailItems = curFolder.Items;
MailItem item = mailItems.GetFirst();

This would work fine if the user didn't apply any search filters; but if a filter is applied via the instant search bar this code would produce the same list of MailItems as if the filter wasn't applied.

I thought of two ways of potentially solving this but couldn't find any resources online that worked for either. 1) Preferably, get direct read access to the MailItem list currently rendered within the email list pane. 2) Alternatively, read the value in the instant search text-box and apply that to the currently selected folder using the Items.Find() command.

Any guidance or explanations would be greatly appreciated; thanks in advance.

1

1 Answers

0
votes

The Outlook object model doesn't provide any direct access to the filter line or items shown in Outlook.

But the Explorer class provides the CurrentView property which returns an object representing the current view. The View class provides the Filter property which is applied to the current view.

Sub ResetView()  
   Dim v as Outlook.View  
   ' Save a reference to the current view object  
   Set v = Application.ActiveExplorer.CurrentView  

   ' v.Filter
End Sub 

So, you can apply the filter to the Items collection and get the same set of items.