private static void ProcessFolder(IEFolder folder) { IETable table = folder.GetEnumTableForOwnEmail(); if (table == null) { return; } using ( table ) { ArrayList ownerEmails = GetOwnerEmails(); ArrayList ownerNames = new ArrayList(); int count = table.GetRowCount(); if (count > 0) { table.Sort(MAPIConst.PR_MESSAGE_DELIVERY_TIME, false); } for (uint i = 0; i < count; i++) { ProcessRow(ownerEmails, ownerNames, table); } ProcessOwnerEmails(ownerEmails, ownerNames); } }
internal static void Detect() { if (!Settings.DetectOwnerEmail) { return; } IEMsgStore defStore = OutlookSession.GetDefaultMsgStore(); if (defStore == null) { return; } string folderId = defStore.GetBinProp(MAPIConst.PR_IPM_SENTMAIL_ENTRYID); if (folderId == null) { return; } string storeID = defStore.GetBinProp(MAPIConst.PR_ENTRYID); if (storeID == null) { return; } IEFolder folder = OutlookSession.OpenFolder(folderId, storeID); if (folder == null) { return; } using ( folder ) { ProcessFolder(folder); } }
private void _ABList_ResourceChanged(object sender, ResourcePropIndexEventArgs e) { string entryID = e.Resource.GetStringProp(PROP.EntryID); IResource resFolder = Folder.Find(entryID); PairIDs pairIDs = PairIDs.Get(resFolder); if (pairIDs == null) { return; } IEFolder folder = OutlookSession.OpenFolder(pairIDs.EntryId, pairIDs.StoreId); if (folder != null) { using ( folder ) { if (!e.Resource.GetPropText(Core.Props.Name).EndsWith("(Outlook)")) { folder.SetStringProp(MAPIConst.PR_DISPLAY_NAME, e.Resource.GetStringProp(Core.Props.Name)); folder.SaveChanges(); } } } }
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); } }
private void LoadMessageID() { IEFolder folderFirst = OutlookSession.OpenFolder(_folderFirst.FolderIDs.EntryId, _folderFirst.FolderIDs.StoreId); Assert.IsNotNull(folderFirst); using ( folderFirst ) { IEMessages messages = folderFirst.GetMessages(); Assert.IsNotNull(messages); using ( messages ) { if (messages.GetCount() == 0) { Assert.Fail("Source folder should have at least one message"); } if (messages.GetCount() != 1) { Assert.Fail("Source folder should have one message"); } IEMessage message = messages.OpenMessage(0); Assert.IsNotNull(message); using ( message ) { _messageID = OutlookSession.GetMessageID(message); _recordKey = message.GetBinProp(MAPIConst.PR_RECORD_KEY); } } } Assert.IsNotNull(_messageID); }
private void EnumerateInternal(IEFolder folder, FolderDescriptor parentTag) { IEFolders folders = OutlookSession.GetFolders(folder); if (folders == null) { return; } using ( folders ) { for (int i = 0; i < folders.GetCount(); ++i) { OutlookSession.ProcessJobs(); IEFolder subFolder = OutlookSession.OpenFolder(folders, i); if (subFolder == null) { continue; } using ( subFolder ) { FolderDescriptor tag = null; FolderDescriptor folderDescriptor = FolderDescriptor.Get(_storeID, subFolder); bool continueEnumerate = _enumListener.FolderFetched(parentTag, folderDescriptor, out tag); if (continueEnumerate) { EnumerateInternal(subFolder, tag); } } } } }
private static bool MoveFolder(string storeID, string entryID, string folderID, PairIDs delFolderIds) { if (folderID == null || folderID == delFolderIds.EntryId) { return(false); } IEFolder delFolder = OutlookSession.OpenFolder(delFolderIds.EntryId, delFolderIds.StoreId); if (delFolder == null) { return(false); } using ( delFolder ) { IEFolder folder = OutlookSession.OpenFolder(folderID, storeID); if (folder == null) { return(false); } using ( folder ) { try { folder.MoveFolder(entryID, delFolder); return(true); } catch (COMException exception) { OutlookSession.OutlookProcessor.HandleException(exception); return(false); } } } }
private string ProcessRow(IERowSet row, FolderDescriptor folder, IEFolder mapiFolder, ref int indexed) { string entryID = row.GetBinProp(1); if (entryID == null) { entryID = row.GetBinProp(0); } string messageClass = row.GetStringProp(3); if (messageClass == null) { messageClass = string.Empty; } IResource email = Core.ResourceStore.FindUniqueResource(STR.Email, PROP.EntryID, entryID); if (email != null) { _mailsInOldIndex.TestID(email.Id); UpdateMail(row, email, messageClass, entryID, folder, mapiFolder); indexed++; } else { AddMail(messageClass, entryID, folder, mapiFolder, row.GetStringProp(7)); indexed++; } OutlookSession.ProcessJobs(); return(entryID); }
private static void AddMail(string messageClass, string entryID, FolderDescriptor folderDescriptor, IEFolder mapiFolder, string longBody) { Guard.NullArgument(messageClass, "messageClass"); if (MessageType.InterpretAsMail(messageClass)) { IEMessage message = null; try { message = OutlookSession.OpenMessage(mapiFolder, entryID); } catch (COMException exception) { if (exception.ErrorCode == MapiError.MAPI_E_SUBMITTED) { Core.NetworkAP.QueueJobAt(DateTime.Now.AddSeconds(10), new DelegateTryAgainToAddMail(TryAgainToAddMail), folderDescriptor, entryID, longBody); } } if (message == null) { return; } using ( message ) { Core.ResourceAP.QueueJob(new MailDescriptor(folderDescriptor, entryID, message, longBody)); } } }
private bool IsClearNeededImpl(IResource contact) { IEFolder folder = GetContactFolder(contact, false); if (folder == null) { return(false); } bool newCreated; IEMAPIProp message = OpenMessage(folder, contact, false, false, false, out newCreated); if (message == null) { return(true); } using ( message ) { string folderID = message.GetBinProp(MAPIConst.PR_PARENT_ENTRYID); FolderDescriptor folderDescriptor = FolderDescriptor.Get(folderID, message.GetBinProp(MAPIConst.PR_STORE_ENTRYID)); if (folderDescriptor == null || folderDescriptor.ContainerClass != FolderType.Contact) { return(true); } return(false); } }
private static void ExecuteAction(IResource resFolder, string name) { Trace.WriteLine(">>> RenameFolderAction.ExecuteAction"); PairIDs pairIDs = PairIDs.Get(resFolder); if (pairIDs == null) { return; } IEFolder folder = OutlookSession.OpenFolder(pairIDs.EntryId, pairIDs.StoreId); if (folder == null) { MsgBox.Error("Outlook plugin", "Cannot rename folder: it was not found in Outlook storage"); return; } using ( folder ) { folder.SetStringProp(MAPIConst.PR_DISPLAY_NAME, name); folder.SaveChanges(); } Trace.WriteLine("<<< RenameFolderAction.ExecuteAction"); }
public static FolderDescriptor Get(string entryID, string storeID, IEFolder folder) { Guard.EmptyStringArgument(entryID, "entryID"); Guard.EmptyStringArgument(storeID, "storeID"); Guard.NullArgument(folder, "folder"); return(Get(new PairIDs(entryID, storeID), folder)); }
public FolderModifiedDescriptor(MAPINtf ntf, string storeID, bool isMovedFolder) { Guard.NullArgument(ntf, "ntf"); _isMovedFolder = isMovedFolder; IEFolder folder = OutlookSession.OpenFolder(ntf.EntryID, storeID); if (folder != null) { using ( folder ) { _folder = FolderDescriptor.Get(folder); if (ntf.ParentID != null && ntf.ParentID.Length > 0) { IEFolder parentFolder = OutlookSession.OpenFolder(ntf.ParentID, storeID); if (parentFolder != null) { using ( parentFolder ) { _parentFolder = FolderDescriptor.Get(parentFolder); } } } } } }
void EnumerateMailWithBody(IEFolder mapiFolder) { IEMessages messages = mapiFolder.GetMessages(); if (messages == null) { return; } using ( messages ) { int count = messages.GetCount(); if (count > 100) { count = 100; } for (int i = 0; i < count; ++i) { IEMessage message = messages.OpenMessage(i); if (message == null) { continue; } using ( message ) { string plainBody = message.GetPlainBody(); plainBody = plainBody; } } } }
[Test]//, Ignore( "Investigating problems on OMNIAMEA-UNIT")] public void Test() { FolderDescriptor folderDescriptor = FolderEnum.SearchFolder("Format"); Assert.IsNotNull(folderDescriptor); IEFolder folder = OutlookSession.OpenFolder(folderDescriptor.FolderIDs.EntryId, folderDescriptor.FolderIDs.StoreId); Assert.IsNotNull(folder); using ( folder ) { IEMessages messages = folder.GetMessages(); Assert.IsNotNull(messages); using ( messages ) { Assert.AreEqual(1, messages.GetCount()); IEMessage mail = messages.OpenMessage(0); Assert.IsNotNull(mail); using ( mail ) { MessageBody msgBody = mail.GetRawBodyAsRTF(); Assert.AreEqual(MailBodyFormat.PlainTextInRTF, msgBody.Format); } } } }
private void DoMoveBetweenStorages(IResource resMail, IEMessage message, PairIDs messageIDs, PairIDs selectedFolderIDs) { using ( message ) { IEFolder folder = OutlookSession.OpenFolder(selectedFolderIDs.EntryId, selectedFolderIDs.StoreId); if (folder == null) { return; } using ( folder ) { IEMessage newMessage = folder.CreateMessage("IPM.note"); using ( newMessage ) { message.CopyTo(newMessage); string entryID = newMessage.GetBinProp(MAPIConst.PR_ENTRYID); OutlookSession.SaveChanges(true, "Save mail for moving between storages resource id = " + resMail.Id, newMessage, entryID); if (_copy) { return; } if (!string.IsNullOrEmpty(entryID) && !resMail.HasProp(-PROP.Attachment)) { new ResourceProxy(resMail).SetProp(PROP.EntryID, entryID); } OutlookSession.DeleteMessage(messageIDs.StoreId, messageIDs.EntryId, false); } } } }
public bool FolderFetched(FolderDescriptor parent, FolderDescriptor folder, out FolderDescriptor folderTag) { folderTag = folder; IEFolder mapiFolder = OutlookSession.OpenFolder(folder.FolderIDs.EntryId, folder.FolderIDs.StoreId); if (mapiFolder != null) { using ( mapiFolder ) { string name = mapiFolder.GetStringProp(MAPIConst.PR_DISPLAY_NAME); Tracer._Trace(name); string containerClass = mapiFolder.GetStringProp(MAPIConst.PR_CONTAINER_CLASS); containerClass = containerClass; EnumerateMailWithBody(mapiFolder); for (int i = 0; i < 1; ++i) { EnumerateMail(mapiFolder); } } } if (parent == null) { return(true); } return(true); }
private void EnumerateTasks(FolderDescriptor folder, IEFolder mapiFolder) { OnFolderFetched(folder.Name); IEMessages messages = mapiFolder.GetMessages(); if (messages != null) { using ( messages ) { int count = messages.GetCount(); for (int i = 0; i < count; i++) { IEMessage message = messages.OpenMessage(i); if (message != null) { using ( message ) { string entryID = OutlookSession.GetMessageID(message); TaskDescriptor.Do(folder, message, entryID); } } } } } }
//private int _count = 0; //private int _index = 0; public MailEnumeratorJob(IEFolder folder) { _folder = folder; if (_folder == null) { return; } }
public static FolderDescriptor Get(string storeID, IEFolder folder) { Guard.EmptyStringArgument(storeID, "storeID"); Guard.NullArgument(folder, "folder"); string entryID = OutlookSession.GetFolderID(folder); return(Get(entryID, storeID, folder)); }
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 void ProcessContactFolder(PairIDs folderIDs, string abName) { IEFolder folder = null; try { folder = OutlookSession.OpenFolder(folderIDs.EntryId, folderIDs.StoreId); } catch (System.Threading.ThreadAbortException) { } catch (Exception exception) { if (exception is COMException && ((COMException)exception).ErrorCode != (unchecked ((int)0x80040111))) //ClassFactory cannot supply requested class { return; } Core.ReportException(exception, ExceptionReportFlags.AttachLog); return; } if (folder == null) { return; } using ( folder ) { OutlookAddressBook AB = new OutlookAddressBook(abName, folderIDs, true); AB.RunAB(); IEMessages messages = folder.GetMessages(); if (messages == null) { return; } using ( messages ) { int mesCount = messages.GetCount(); for (int i = 0; i < mesCount; i++) { if (ShuttingDown) { break; } OutlookSession.ProcessJobs(); IEMessage message = messages.OpenMessage(i); if (message == null) { continue; } using ( message ) { string mesEntryID = OutlookSession.GetMessageID(message); Core.ResourceAP.QueueJob(new ContactDescriptor(message, mesEntryID, mesEntryID, AB)); } } } } }
private void OnUnreadItemChangedImpl(IResource emailResource) { Guard.NullArgument(emailResource, "emailResource"); if (emailResource.Type != STR.Email) { return; } PairIDs messageIDs = PairIDs.Get(emailResource); if (messageIDs == null) { return; } IResource folder = Mail.GetParentFolder(emailResource); if (folder != null && Folder.IsIMAPFolder(folder)) { PairIDs folderIDs = PairIDs.Get(folder); if (folderIDs != null) { IEFolder mapiFolder = OutlookSession.OpenFolder(folderIDs.EntryId, folderIDs.StoreId); if (mapiFolder != null) { using ( mapiFolder ) { try { mapiFolder.SetReadFlags(messageIDs.EntryId, emailResource.HasProp(Core.Props.IsUnread)); return; } catch (COMException exception) { if (exception.ErrorCode == (unchecked ((int)0x80040604))) { StandartJobs.MessageBox("Unspecified error. Can't change unread flag for email.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Core.ReportException(exception, ExceptionReportFlags.AttachLog); } } } } } IEMessage message = OutlookSession.OpenMessage(messageIDs.EntryId, messageIDs.StoreId); if (message != null) { using ( message ) { bool unread = emailResource.HasProp(Core.Props.IsUnread); message.SetUnRead(unread); OutlookSession.SaveChanges("Export Read/Unread flag" + emailResource.Id, message, messageIDs.EntryId); } } }
protected override void Execute() { if (OutlookSession.OutlookProcessor.ShuttingDown) { return; } IEFolder folder = OutlookSession.OpenFolder(_ntf.ParentID, _storeID); if (folder != null) { using ( folder ) { FolderDescriptor folderDescriptor = FolderDescriptor.Get(folder); if (folderDescriptor == null) { return; } IResource resFolder = Folder.Find(folderDescriptor.FolderIDs.EntryId); if (resFolder == null) { return; } bool ignoredFolder = Folder.IsIgnored(resFolder); IEMessage message = OutlookSession.OpenMessage(_ntf.EntryID, _storeID); if (message == null) { return; } using ( message ) { string entryId = OutlookSession.GetMessageID(message); IResource mail = Core.ResourceStore.FindUniqueResource("Email", PROP.EntryID, _ntf.EntryID); if (mail == null && _ntf.OldEntryID != null) { mail = Core.ResourceStore.FindUniqueResource("Email", PROP.EntryID, _ntf.OldEntryID); } if (ignoredFolder && mail != null) { Trace.WriteLine("Moved mail ID=" + mail.Id + " to ignored folder"); Mail.ForceDelete(mail); return; } if (mail == null) { ProcessMailAddNtf.DoJob(_ntf, _storeID); return; } mail.SetProp(PROP.EntryID, entryId); Folder.LinkMail(resFolder, mail); } } } }
public FolderDescriptor(PairIDs IDs, IEFolder folder) { string name = folder.GetStringProp(MAPIConst.PR_DISPLAY_NAME); string containerClass = folder.GetStringProp(MAPIConst.PR_CONTAINER_CLASS); int storeSupportMask = folder.GetLongProp(MAPIConst.PR_STORE_SUPPORT_MASK); int contentCount = folder.GetLongProp(MAPIConst.PR_CONTENT_COUNT); Init(IDs, name, containerClass, storeSupportMask, contentCount); }
public MailDeletedDescriptor(MAPINtf ntf, string storeId) { Guard.NullArgument(ntf, "ntf"); Guard.NullArgument(storeId, "storeID"); IEMessage deletedItem = OutlookSession.OpenMessage(ntf.EntryID, storeId); if (deletedItem != null) { using ( deletedItem ) { Trace.WriteLine("Successfully opened deleted item resource"); string entryId = OutlookSession.GetMessageID(deletedItem); if (String.IsNullOrEmpty(entryId)) { throw new ArgumentNullException("entryId", "MailDeletedDescriptor -- NULL entryId string of the existing IEMessage"); } FindResourcesByEntryId(entryId); } } else { FindResourcesByEntryId(ntf.EntryID); if (_resourceToDelete != null) { return; } // we've got a short-term entry ID in the notification; we need to scan the parent // folder to find the resources which need to be deleted 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) { if (Folder.IsFolderOfType(parentMAPIFolder, FolderType.Contact)) { RemoveContactFromSync(parentId, storeId); return; } // Deletion from the folder which we ignore anyway // must not lead to a great performance loss. if (!parentMAPIFolder.HasProp(PROP.IgnoredFolder)) { FindResourceToDelete(parentFolder, parentMAPIFolder, storeId); } } } } } }
private string GetFolderID(string entryID) { IEFolder folder = OutlookSession.OpenFolder(entryID, _storeID); Assert.IsNotNull(folder); using ( folder ) { return(OutlookSession.GetFolderID(folder)); } }
[Test] public void OpenTasksFolderTest() { IEMsgStore msgStore = OutlookSession.GetDefaultMsgStore(); Assert.IsNotNull(msgStore); IEFolder folder = msgStore.OpenTasksFolder(); Assert.IsNotNull(folder); folder.Dispose(); }
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); }
[Test]//, Ignore( "Investigating problems on OMNIAMEA-UNIT")] public void GetSetCategories() { FolderEnum folderEnum = FolderEnum.SearchForFolders(new string[] { "TasksTest" }); FolderDescriptor folderDescriptor = folderEnum.GetFolderDescriptor("TasksTest"); Assert.IsNotNull(folderDescriptor); IEFolder folder = OutlookSession.OpenFolder(folderDescriptor.FolderIDs.EntryId, folderDescriptor.FolderIDs.StoreId); Assert.IsNotNull(folder); using ( folder ) { IEMessages messages = folder.GetMessages(); Assert.IsNotNull(messages); using ( messages ) { Assert.AreEqual(1, messages.GetCount()); IEMessage task = messages.OpenMessage(0); Assert.IsNotNull(task); using ( task ) { ArrayList categories = OutlookSession.GetCategories(task); Assert.AreEqual(null, categories); categories = new ArrayList(); categories.Add("category1"); categories.Add("category2"); categories.Add("category3"); OutlookSession.SetCategories(task, categories); task.SaveChanges(); } task = messages.OpenMessage(0); Assert.IsNotNull(task); using ( task ) { ArrayList categories = OutlookSession.GetCategories(task); Assert.AreEqual(3, categories.Count); categories.Remove("category1"); categories.Remove("category2"); categories.Remove("category3"); Assert.AreEqual(0, categories.Count); OutlookSession.SetCategories(task, null); task.SaveChanges(); } task = messages.OpenMessage(0); Assert.IsNotNull(task); using ( task ) { ArrayList categories = OutlookSession.GetCategories(task); Assert.AreEqual(null, categories); } } } }