Calling Save() twice raice MAPI_E_OBJECT_CHANGED error. The weird thing is if I select another mail on the grid and go back and then select the first one again and perform the action it works fine. This only happens with imap accounts. Code:
public void UpdateMailObject(bool linked)
{
Outlook._Application outlookApplication = null;
Redemption.RDOMail rdoEmail = null;
Redemption.RDOSession rdoSession = null;
RDOFolder folder = null;
RDOStores stores = null;
RDOStore store = null;
RDOStore unwStore = null;
Outlook.Explorer outlookExplorer = null;
Outlook.MailItem selectedMail = null;
try
{
outlookApplication = new Outlook.Application();
rdoSession = new Redemption.RDOSession();
object MAPIOBJECT = outlookApplication.Session.GetType().InvokeMember("MAPIOBJECT", BindingFlags.GetProperty, null,
outlookApplication.Session, null);
rdoSession.MAPIOBJECT = MAPIOBJECT;
outlookExplorer = outlookApplication.ActiveExplorer();
selectedMail = outlookExplorer.Selection.OfType<Outlook.MailItem>().FirstOrDefault();
RDOMail rdoMailAux = rdoSession.GetRDOObjectFromOutlookObject(selectedMail, true) as RDOMail;
folder = rdoMailAux.Parent as RDOFolder;
Marshal.ReleaseComObject(rdoMailAux);
string storeId = folder.StoreID;
stores = rdoSession.Stores;
store = stores.GetStoreFromID(storeId);
unwStore = stores.UnwrapStore(store);
rdoEmail = unwStore.GetMessageFromID(selectedMail.EntryID, null);
string sGUID = PS_PUBLIC_STRINGS.ToString("B");
int iID = rdoEmail.GetIDsFromNames(sGUID, GMLINK);
if (iID != 0)
{
rdoEmail.set_Fields(iID, linked);
}
rdoEmail.Save();
}
finally
{
if (outlookApplication != null)
{
Marshal.ReleaseComObject(outlookApplication);
}
if (folder != null)
{
Marshal.ReleaseComObject(folder);
}
if (stores != null)
{
Marshal.ReleaseComObject(stores);
}
if (store != null)
{
Marshal.ReleaseComObject(store);
}
if (unwStore != null)
{
Marshal.ReleaseComObject(unwStore);
}
if (rdoEmail != null)
{
Marshal.ReleaseComObject(rdoEmail);
}
if (outlookExplorer != null)
{
Marshal.ReleaseComObject(outlookExplorer);
}
if (rdoSession != null)
{
Marshal.ReleaseComObject(rdoSession);
}
}
}