Compartilhar via


Processing a Calendar Message

Topic Last Modified: 2006-11-29

When a meeting organizer sends a meeting request, Microsoft® Exchange Server 2007 stores the calendar message in the recipient's inbox. Responses to meeting requests, meeting updates, and cancellations are all received as calendar messages in the inbox. You can use Microsoft ActiveX® Data Objects (ADO) and Collaboration Data Objects (CDO) to retrieve calendar messages from the inbox and process them.

You can identify an item in an Exchange 2007 folder by the item's content class. The content class is a property of items in the Exchange store. The content class of calendar messages is contained in the contentclass Field of the message. All calendar messages have the content class urn:content-classes:calendarmessage.

Note

CDOEX and ExOLEDB versions included in Exchange Server 2007 and Exchange Server 2003 Service Pack 2 handle meetings differently than previous versions of Exchange Server. A new Entry ID value is assigned to an item when it is accepted, tentatively accepted, or declined. The new Entry ID value is assigned regardless of where the item is stored when the action is taken.

You typically open calendar messages by using the ICalendarPart.GetUpdatedItem method. This method checks the Exchange store to verify if the meeting in the calendar message already exists. If the meeting already exists, the calendar message is probably an update to that meeting. The GetUpdatedItem method returns an Appointment object in memory that contains the most current meeting information, either from the Exchange store or the calendar message. When you save the meeting, it overwrites the existing meeting in the Exchange store.

Note

If the calendar part contains an exception to an existingrecurring meeting, the GetUpdatedItem method returns the exception in memory. If you accept or decline the exception, the meeting response is based on the exception. However, when you call the IDataSource.Save method on the exception, it merges the exception into the master recurring meeting and saves the updated master to the Exchange store.

This topic explains how to identify and open calendar messages. Other topics in this section explain how to process the calendar message after it has been opened.

To open a calendar message in the inbox

  1. Open the inbox folder by using an ActiveX Data Objects database (ADODB) record.
  2. Open an ADO Recordset containing the items in the inbox. Use a SELECT statement to include the item URL and content class in the recordset. Specify a WHERE clause to select only calendar messages.
  3. Get the URL of the message from the recordset, and then open the URL by using a CDO CalendarMessage object.
  4. Open each calendar part in the calendar parts collection by using a CDO Appointment object, and process the Appointment object as needed.
  5. Delete the calendar message from the inbox (optional).

The following example gets all calendar messages from the inbox of a specific user. It prints the subject of each calendar part and deletes the message. The examples under other topics in this section explain how to process the calendar parts.

Example

' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Exchange 2000 Library

' Note: It is recommended that all input parameters be validated when they are
' first obtained from the user or user interface.
Sub ProcessCalMsgs(iMbx As IMailbox)

    Dim Rs As ADODB.Recordset
    Set Rs = QueryInboxFolderForCalMsgs(iMbx)
    Debug.Print Rs.RecordCount
    While Not Rs.EOF
        Debug.Print Rs(0)
        Debug.Print Rs(1)
        ProcessCalMsg Rs(0), Conn, iMbx, False
        Rs.MoveNext
    Wend

End Sub

Function QueryInboxFolderForCalMsgs(iMbx As IMailbox) As ADODB.Recordset

    Dim Rs          As New ADODB.Recordset
    Dim Rec         As New ADODB.Record
    Dim Conn        As New ADODB.Connection

    'Open the recordset for the items in the calendar folder
    Conn.Provider = "ExOLEDB.DataSource"
    Conn.Open iMbx.BaseFolder
    Rec.Open iMbx.Inbox, Conn
    Set Rs.ActiveConnection = Rec.ActiveConnection


    Rs.Source = "SELECT ""DAV:href"", " & _
                " ""DAV:contentclass"", " & _
                " ""urn:schemas:httpmail:subject"" " & _
                " FROM scope('shallow traversal of """ & iMbx.Inbox & """')" & _
                " WHERE ""DAV:ishidden"" = False AND ""DAV:isfolder"" = False AND ""DAV:contentclass"" = 'urn:content-classes:calendarmessage'"
    Rs.Open

    Set QueryInboxFolderForCalMsgs = Rs
End Function


Sub ProcessCalMsg(itemURL As String, Conn As ADODB.Connection, iMbx As CDO.IMailbox, fDelete As Boolean)

    Dim iCalMsg      As New CalendarMessage
    Dim iAddre       As New Addressee
    Dim iCalPart     As ICalendarPart
    Dim iAppt        As Appointment
    Dim iDsrc        As CDO.IDataSource
    Dim Index        As Integer
    Dim Rec As New ADODB.Record


    Dim Config As New CDO.Configuration
    Config("CalendarLocation") = iMbx.Calendar
    Config.Fields.Update

    Set iCalMsg.Configuration = Config
    iCalMsg.DataSource.Open itemURL, Conn, adModeReadWrite

    'Get each calendar part
    For Each iCalPart In iCalMsg.CalendarParts
      Set iAppt = iCalPart.GetUpdatedItem
      Debug.Print "Subject: " & iAppt.Subject

      'Process the appointment as necessary
      Select Case iCalPart.CalendarMethod
        Case "REQUEST"
            ' Handle a meeting request
        Case "REPLY"
            ' Handle meeting request reply
        Case "CANCEL"
            ' Handle cancelled meeting.
      End Select
    Next iCalPart

    'If flagged, delete the calendar message from the inbox
    If fDelete Then
        Rec.Open itemURL, Conn, adModeReadWrite
        Debug.Print iMbx.DeletedItems
        Rec.DeleteRecord
        ' Or move the Record:
        ' Rec.MoveRecord , iMbx.DeletedItems, , , adMoveOverWrite
    End If
End Sub