AgingProperties

OK- everyone reading my blog knows that I love NewsGator. (Hey- NG dudes: why aren’t you advertising on Office Online Marketplace? Someone posted a comment to one of my earlier blogs asking this great question).

Well, I now am monitoring a lot of newsfeeds, but it’s time to clean house. IOW, I can’t keep all of these old messages around. Outlook has the super-cool AutoArchive feature that expunges old messages, moving them into a folder or deleting them altogether. Additionally, Outlook lets me have a global setting but I can also have specific settings for each folder. I prefer this because there are some RSS feeds whose messages I want around longer than others. Peter Torr’s blog (https://blogs.msdn.com/ptorr/) is one I like to have around for reference material. (It’s no secret he is brilliant).

 

There’s the problem: every time I add a new folder, I have to set each folders custom AutoArchive settings in the UI. Not fun when I have a lot of folders.

So, I have written some code to do it for me, and today I will connect to a button.

 

Here’s the deal (big thanks to Sue Mosher, Slipstick.com, and CDO Live with this link for getting me going (https://www.cdolive.com/cdo10.htm)

Let me break it down. First, I get a reference to the Mapi.Folder object for the target folder. The folder has a collection of hidden messages (HiddenMessages). In this messages is one that is of a specific type: IPC.MS.Outlook.AgingProperties (yeah, another barely known class type in the Mapi world!). You can filter the messages collection for that type or just loop through to find it. Filtering is usually more efficient, but I was looping when I wrote this code (blah). The Message in questions has some fields that are specific to the AutoArchive settings. I grab these using some constants defined earlier (just follow the CDOLive link to see what they are and what they mean). Then, I can read/write the props. Make sure you call the Update method of the Message when you are done setting the props.

Here’s the snippet:

'I acquire a reference to the MAPIFolder earlier, get

'its folder id and store id. These match the Mapi.Folder ones,

'so I can pass them in here and get the Mapi.Folder

  Set fld = objSession.GetFolder(sFolderID, sStoreID)

    Dim objMessages As Messages

    Dim objFilter As Object

    'I have a little userform I pop up to display the props

    Dim f As frmProps

    Dim objMessage As MAPI.Message

    Set objMessages = fld.HiddenMessages

    If Not objMessages Is Nothing Then

      For Each objMessage In objMessages

        If objMessage.Type = "IPC.MS.Outlook.AgingProperties" Then

          Set f = New frmProps

          Set objFields = objMessage.Fields

          If Not objFields Is Nothing Then

            Set objField = objFields.Item(CdoPR_AGING_PERIOD)

            'Here is an example of changing the value and updating

            objField.Value = 2

            objMessage.Update

            Set objField = Nothing

            f.txtPeriod.Text = objField.Value

            Set objField = objFields.Item(CdoPR_AGING_GRANULARITY)

            f.cboGranularity.AddItem objField.Value

            Set objField = Nothing

            Set objField = objFields.Item(CdoPR_AGING_FILENAME)

            f.txtPath.Text = objField.Value

            Set objField = Nothing

            Set objField = objFields.Item(CdoPR_PR_AGING_AGE_FOLDER)

            f.chkEnabled.Value = objField.Value

            Set objField = Nothing

            Set objField = objFields.Item(CdoPR_AGING_DELETE_ITEMS)

            If objField.Value Then

              f.optDelete.Value = True

            Else

              f.optMove.Value = True

            End If

          End If

          f.Show vbModal

          Exit For

        End If

      Next objMessage

    End If

 

Now, I will make adjustments so that custom AutoArchive settings just get placed on whatever my selected folder is in my Outlook.Explorer. I will also check for multiple folders selected in the explorer. I will then hook it up to a button. In this way, I can add newsfeeds all day, select the folders I want and with one click, apply autoarchive settings of my choosing.

 

Make sure you check out the MSDN Office Developer Center (https://msdn.microsoft.com/office)

Rock on!