Add-in problem: Process All Marked Header doesn't display email bodies

T

TTT

My add-in is causing a minor problem with large files in Inbox.

I have Download Only Headers For Items Larger Than set to 10k. Any larger emails will display only their headers until I Mark To Download and Process All Marked Headers. This should cause the entire body to display, but with the add-in enabled they will not. I have to click onto another email then back, sometimes repeatedly.

The code that causes the problem is the same as in my previous Post

Add-in problem: First email in outbox gets stuck


It's where we are trying to add items to the context menu if the user has right clicked on an email.

if (_explorer.Selection[1] is Outlook.MailItem)

Touching the email seems to cause this problem, but I can't think of how to avoid this since these are the emails we want to change the menu for.

Is there no way to reset the Selection to its previous state?.
Submitted using http://www.outlookforums.com
 
K

Ken Slovak - [MVP - Outlook]

Only Outlook 2010 allows you to set/clear/add to Selection.

You are also assuming that if a context menu is displayed that it's for
whatever is selected, a logical fallacy. I would get the same response but
with a different context menu displayed if I right-clicked on a non-selected
item, a folder in the Navigation Pane, etc.

I could right-click on the second item in the view but have the first item
selected. You just can't tell.

Only starting with Outlook 2007 do you get to properly handle context menus
and know which is being displayed and what was right-clicked.
 
T

TTT

I didn't explain that very well so I'll try again.

The cast to a MailItem changes the behaviour of the email that is selected (just like it changed them in the Outbox to not send in my previous question). I can't see any way to avoid "touching" the email, since that's what we want to display a new context menu for.

Is there any way to set the email back to an "untouched" state, or to get it to fill out its body correctly even if it has been "touched"?


kenslovak wrote on Tue, 30 March 2010 09:08
Only Outlook 2010 allows you to set/clear/add to Selection.
You are also assuming that if a context menu is displayed that it's for
whatever is selected, a logical fallacy. I would get the same response but
with a different context menu displayed if I right-clicked on a non-selected
item, a folder in the Navigation Pane, etc.
I could right-click on the second item in the view but have the first item
selected. You just can't tell.
Only starting with Outlook 2007 do you get to properly handle context menus
and know which is being displayed and what was right-clicked.
 
K

Ken Slovak - [MVP - Outlook]

So try getting the item as an Object and using Reflection to get the Class
property or MessageClass property and examine the item type that way. See if
that causes the same problem as your cast.
 
T

TTT

Fixed!

if (_explorer.Selection[1] is Outlook.MailItem)

becomes

bool isMailItem = false;

Object objectToInspect = _explorer.Selection[1];

Type type = objectToInspect.GetType();

try
{
if ((Outlook.OlObjectClass)type.InvokeMember("Class", System.Reflection.BindingFlags.GetProperty, null, objectToInspect, null) == Outlook.OlObjectClass.olMail)
{
isMailItem = true;
}
}
catch (Exception ex)
{
//eat
}

if (isMailItem)


Pretty obvious, really
:)

Thanks a lot, Ken
 
K

Ken Slovak - [MVP - Outlook]

Good.

I've found that sometimes casting will have odd effects but testing for
Class or MessageClass as you did before casting prevents the problems, as
you found.
 

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