Outlook.Store.GetDefaultFolder Outlook is creating strange folders in a new .pst file

懵懂的女人 提交于 2020-02-02 16:29:11

问题


After creating a new .pst file only 2 folders are created with the new Outlook.Store(.pst).

Example 1:

After you close Outlook and reopen it, several folders are created. Some are standard folders, such as Recycle Bin, RSSFeed, and more. But some are strange and have strange names (with strange characters).

Example 2:

When I was debugging the routine of my COM Addin I have identified that in Addin's 'Startup' event, there is a code that checks the default folders of the Outlook.Store.

The 'GetDefaultFolder' method of the Outlook.Store object is used. This method is recommended by Microsoft to identify the default folders of an Outlook.Store.

When this method is executed, depending on the parameter, it creates the folder in Outlook.Store. I created a simple COM Addin to exemplify:

In the Startup event I did this:

        private StringBuilder sb = new StringBuilder("##Log##");

        //Startup
        Outlook.NameSpace ns = OutlookApp.Session;
        Outlook.Store lastStore = ns.Stores[1];//Just to get the new Store

        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderCalendar);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderConflicts);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderContacts);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderDeletedItems);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderDrafts);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderInbox);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderJournal);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderJunk);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderLocalFailures);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderManagedEmail);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderNotes);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderOutbox);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderRssFeeds);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderSentMail);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderServerFailures);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderSuggestedContacts);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderSyncIssues);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderTasks);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderToDo);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olPublicFoldersAllPublicFolders);

        System.Diagnostics.Debug.Write(sb.ToString());

        private void GetDefaultFolder(Outlook.Store newStore, Outlook.OlDefaultFolders olFolderKind)
    {
        Outlook.MAPIFolder rootFolder = null;

        rootFolder = newStore.GetRootFolder();
        sb.AppendLine($"qtd: {rootFolder.Folders.Count}");

        try
        {
            sb.AppendLine($"Folder kind: {olFolderKind.ToString()}");
            newStore.GetDefaultFolder(olFolderKind);
        }
        catch
        {
        }
        finally
        {
            sb.AppendLine($"qtd: {rootFolder.Folders.Count}");
            sb.AppendLine();
            sb.AppendLine();

            if (rootFolder != null)
                Marshal.ReleaseComObject(rootFolder);
        }
    }

I load the new .pst file (Outlook.Store) and fetch all default folders. But in a few cases new Folders are added.

The log of this code is:

Log

Ex

qtd: 1 Folder kind: olFolderCalendar qtd: 2

qtd: 2 Folder kind: olFolderConflicts qtd: 2

qtd: 2 Folder kind: olFolderContacts qtd: 3

qtd: 3 Folder kind: olFolderDeletedItems qtd: 3

qtd: 3 Folder kind: olFolderDrafts qtd: 4

qtd: 4 Folder kind: olFolderInbox qtd: 4

qtd: 4 Folder kind: olFolderJournal qtd: 5

qtd: 5 Folder kind: olFolderJunk qtd: 6

qtd: 6 Folder kind: olFolderLocalFailures qtd: 6

qtd: 6 Folder kind: olFolderManagedEmail qtd: 6

qtd: 6 Folder kind: olFolderNotes qtd: 7

qtd: 7 Folder kind: olFolderOutbox qtd: 8

qtd: 8 Folder kind: olFolderRssFeeds qtd: 9

qtd: 9 Folder kind: olFolderSentMail qtd: 9

qtd: 9 Folder kind: olFolderServerFailures qtd: 9

qtd: 9 Folder kind: olFolderSuggestedContacts qtd: 9

qtd: 9 Folder kind: olFolderSyncIssues qtd: 9

qtd: 9 Folder kind: olFolderTasks qtd: 10

qtd: 10 Folder kind: olFolderToDo qtd: 10

qtd: 10 Folder kind: olPublicFoldersAllPublicFolders qtd: 10

Questions

What is this strange folder created by Outlook? Why is the Outlook.Store.GetDefaultFolder method creating folders? Is there another method that can be used that returns the same information as the GetDefaultFolder but DOES NOT create folders?


回答1:


The GetDefaultFolder method of the Store or Namespace class doesn't and shouldn't create folders in Outlook.

First of all, I see a custom add-ins running in Outlook (DocSite). Before creating any test with OOM I'd suggest to disable all of them.

Also I see an interesting domain name configured in Outlook. Is it IMAP or Exchange profile? If so, I'd suggest configuring any SMTP mail box instead.

Is a custom store provider?



来源:https://stackoverflow.com/questions/43790507/outlook-store-getdefaultfolder-outlook-is-creating-strange-folders-in-a-new-pst

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!