internal static IEMAPIProp OpenMessage(IEFolder folder, IResource contact, bool create, bool forceCreate, bool trace, out bool newCreated, out bool createdAsMailUser) { createdAsMailUser = false; newCreated = false; using ( folder ) { IEMAPIProp message = null; if (!create) { string mesEntryId = contact.GetPropText(PROP.EntryID); if (mesEntryId.Length > 0) { message = OutlookSession.OpenMessage(folder, mesEntryId); if (message == null) { Contact.RemoveFromSync(contact, true); } } if (!forceCreate) { return(message); } } if (message == null) { string folderId = folder.GetBinProp(MAPIConst.PR_ENTRYID); _tracer.Trace(folderId); IEAddrBook ab = OutlookSession.GetAddrBook(); if (ab != null) { for (int i = 0; i < ab.GetCount(); ++i) { string abEntryId = ab.FindBinProp(i, MAPIConst.PR_ENTRYID_ASSOCIATED_WITH_AB); if (abEntryId == folderId) { IEABContainer abContainer = ab.OpenAB(i); if (abContainer != null) { using ( abContainer ) { message = abContainer.CreateMailUser( ); if (message != null) { createdAsMailUser = true; return(message); } } } break; } } } message = folder.CreateMessage("IPM.Contact"); newCreated = true; } return(message); } }
public static FolderDescriptor Get(IEFolder folder) { Guard.NullArgument(folder, "folder"); string entryId = OutlookSession.GetFolderID(folder); string storeId = folder.GetBinProp(MAPIConst.PR_STORE_ENTRYID); return(Get(new PairIDs(entryId, storeId), folder)); }
private IEMessage OpenMessage(ref bool wasChanges) { if (_createNew && _OMTaskId == null) { return(null); } wasChanges = false; IEMessage message = null; if (!_createNew) { PairIDs IDs = PairIDs.Get(_task); if (IDs == null) { if (_task.HasProp(PROP.EntryID)) { IEFolder taskFolder = OutlookSession.OpenDefaultTaskFolder(); if (taskFolder == null) { return(null); } using ( taskFolder ) { IDs = new PairIDs(_task.GetStringProp(PROP.EntryID), taskFolder.GetBinProp(MAPIConst.PR_STORE_ENTRYID)); } } if (IDs == null) { return(null); } } message = OutlookSession.OpenMessage(IDs.EntryId, IDs.StoreId); } if (message == null) { IEFolder taskFolder = OutlookSession.OpenDefaultTaskFolder(); if (taskFolder == null) { return(null); } wasChanges = true; using ( taskFolder ) { message = taskFolder.CreateMessage("IPM.Task"); _created = true; } } return(message); }
public static string GetFolderID(IEFolder folder) { return(folder.GetBinProp(MAPIConst.PR_ENTRYID)); }
public MAPIInfoStoreDescriptor(IEMsgStore msgStore) { _name = msgStore.GetStringProp(MAPIConst.PR_DISPLAY_NAME); _entryId = msgStore.GetBinProp(MAPIConst.PR_ENTRYID); _deletedItemsId = msgStore.GetBinProp(MAPIConst.PR_IPM_WASTEBASKET_ENTRYID); MAPIIDs mapiIds = msgStore.GetInboxIDs(); if (mapiIds != null) { AddDefaultFolderEntryID(mapiIds.EntryID); } AddDefaultFolderEntryID(_deletedItemsId); AddDefaultFolderEntryID(msgStore.GetBinProp(MAPIConst.PR_IPM_SENTMAIL_ENTRYID)); AddDefaultFolderEntryID(msgStore.GetBinProp(MAPIConst.PR_IPM_OUTBOX_ENTRYID)); IEFolder rootFolder = msgStore.GetRootFolder(); if (rootFolder != null) { using ( rootFolder ) { string parentEntryId = rootFolder.GetBinProp(MAPIConst.PR_PARENT_ENTRYID); if (parentEntryId != null) { IEFolder parentFolder = msgStore.OpenFolder(parentEntryId); if (parentFolder != null) { using ( parentFolder ) { AddDefaultFolderEntryID(parentFolder.GetBinProp(MAPIConst.PR_IPM_APPOINTMENT_ENTRYID)); AddDefaultFolderEntryID(parentFolder.GetBinProp(MAPIConst.PR_IPM_CONTACT_ENTRYID)); AddDefaultFolderEntryID(parentFolder.GetBinProp(MAPIConst.PR_IPM_DRAFTS_ENTRYID)); AddDefaultFolderEntryID(parentFolder.GetBinProp(MAPIConst.PR_IPM_JOURNAL_ENTRYID)); AddDefaultFolderEntryID(parentFolder.GetBinProp(MAPIConst.PR_IPM_NOTE_ENTRYID)); AddDefaultFolderEntryID(parentFolder.GetBinProp(MAPIConst.PR_IPM_TASK_ENTRYID)); ArrayList additionalRenEntryIDs = parentFolder.GetBinArray(MAPIConst.PR_ADDITIONAL_REN_ENTRYIDS); if (additionalRenEntryIDs != null && additionalRenEntryIDs.Count > 4) { _junkEmailId = additionalRenEntryIDs[4] as string; } if (additionalRenEntryIDs != null) { foreach (string id in additionalRenEntryIDs) { AddDefaultFolderEntryID(id); } } } } } } } _supportMask = msgStore.GetLongProp(MAPIConst.PR_STORE_SUPPORT_MASK); _resource = Core.ResourceStore.FindUniqueResource(STR.MAPIInfoStore, PROP.EntryID, _entryId); _storeTypeChecked = _resource == null?false:_resource.HasProp(PROP.StoreTypeChecked); if (_resource == null || !_storeTypeChecked) { try { _supported = OutlookSession.IsStorageSupported(msgStore); _storeTypeChecked = true; } catch (COMException exception) { Tracer._TraceException(exception); } } else { _supported = _resource.HasProp(PROP.StoreSupported); } }
public FolderDeletedDescriptor(MAPINtf ntf, string storeID) { Guard.NullArgument(ntf, "ntf"); Guard.EmptyStringArgument(storeID, "storeID"); _ntf = ntf; _storeID = storeID; // The notification contains only the short-term entry ID, and since the // folder has already been deleted, it is no longer possible to get the // long-term entry ID. Thus, we need to scan the children of the parent of // the deleted folder and check if all of them still exist. IResource resFolder = Folder.Find(ntf.EntryID); if (resFolder == null) { IEFolder parentFolder = OutlookSession.OpenFolder(ntf.ParentID, storeID); if (parentFolder != null) { using ( parentFolder ) { string parentId = OutlookSession.GetFolderID(parentFolder); IResource parentMAPIFolder = Folder.Find(parentId); if (parentMAPIFolder == null) { parentMAPIFolder = Folder.Find(ntf.ParentID); } if (parentMAPIFolder != null) { IResourceList childFolders = parentMAPIFolder.GetLinksTo("MAPIFolder", "Parent"); foreach (IResource childFolderRes in childFolders) { IEFolder childFolder = OutlookSession.OpenFolder(childFolderRes.GetStringProp("EntryID"), storeID); if (childFolder != null) { childFolder.Dispose(); } else { _entryId = childFolderRes.GetStringProp("EntryID"); } } if (_entryId == null) { HashSet set = new HashSet(childFolders.Count); foreach (IResource childFolderRes in childFolders) { set.Add(childFolderRes.GetStringProp("EntryID")); } IEFolders folders = OutlookSession.GetFolders(parentFolder); if (folders != null) { using ( folders ) { for (int i = 0; i < folders.GetCount(); ++i) { IEFolder folder = OutlookSession.OpenFolder(folders, i); if (folder != null) { using ( folder ) { string entryId = folder.GetBinProp(MAPIConst.PR_ENTRYID); if (entryId != null) { set.Remove(entryId); } } } } } } foreach (HashSet.Entry entry in set) { _entryId = (string)entry.Key; break; } if (_entryId == null && Retry) { OutlookSession.OutlookProcessor.QueueJobAt(DateTime.Now.AddMinutes(2), "Delete folder", new MethodInvoker(CreateFolderDeletedDescriptor)); } } } } } } else { _entryId = ntf.EntryID; } }