Skip to main content

Calendar RSS feed Event sink

Somebody emailed me about using the public folder RSS event sink from one of my previous posts on a mailbox calendar. This sounded like a pretty cool idea and I could see some good applications so I decided to blog what I came up with in response to this.

A few things need to be changed from the original script the main one would be instead of the sink generating a feed of the last 7 days worth of posts in a public folder you would want it to generate a feed of the next 7 days worth of appointments in the calendar. Also some of the email fields needed to be dumped in favor of appointment start and end times. The third thing that needs to be done was to add some code to do a timezone adjustment because Exchange stores all appointment start and end times in UTC format. And last but not least a function was added to convert the adjusted query date values into ISO date format which is required for the Exoledb SQL query string. The Query string itself was completely rewritten to grab appointments that had a start date within the next 7 days. (Note you could have gone for end date as well if you wanted to catch appointments that where already in process or appointments that where multi-day events).

I fixed a few issues with the old code (most relating to reading this feed in RSS Bandit) I've fixed the pubdate xml field so It generates a reliable RFC822 date format field. I've also fixed the empty URI value of the feed link.

The code is written to create links based on a mailbox but you could also change the code so it could be used in a shared calendar in a public folder by changing the following line of code (note you need to at least change the servername)

objfield9.text = "http://servname/exchange" & right(Rs.fields("Dav:href"),(len(Rs.fields("Dav:href"))-instr(Rs.fields("Dav:href"),"/MBX/"))-3)

Change "/MBX/" to "/Public Folders/"

Anyway here's the script (ps watch the cut and paste its still pretty terrible)

Sub ExStoreEvents_OnSave(pEventInfo, bstrURLItem, lFlags)

on error resume next
set DispEvtInfo = pEventInfo
set ADODBRec = DispEvtInfo.EventRecord
set objdom = CreateObject("MICROSOFT.XMLDOM")
Set objField = objDom.createElement("rss")
Set objattID = objDom.createAttribute("version")
objattID.Text = "2.0"
objField.setAttributeNode objattID
objDom.appendChild objField
Set objField1 = objDom.createElement("channel")
objfield.appendChild objField1
Set objField3 = objDom.createElement("title")
objfield3.text = "Calendar Folder Feed"
objfield1.appendChild objField3
Set objField4 = objDom.createElement("link")
objfield4.text = "http://servername/exchange" & right(ADODBRec.fields("Dav:parentname"),(len(ADODBRec.fields("Dav:parentname"))-instr(ADODBRec.fields("Dav:parentname"),"/MBX/"))-3)
objfield1.appendChild objField4
Set objField5 = objDom.createElement("description")
objfield5.text = "Calendar Feed For Path"
objfield1.appendChild objField5
Set objField6 = objDom.createElement("language")
objfield6.text = "en-us"
objfield1.appendChild objField6
Set objField7 = objDom.createElement("lastBuildDate")
objfield7.text = WeekdayName(weekday(now),3) & ", " & day(now()) & " " & Monthname(month(now()),3) & " " & year(now()) & " " & formatdatetime(now(),4) & ":00 GMT"
objfield1.appendChild objField7
Set Rs = CreateObject("ADODB.Recordset")
Set fso = CreateObject("Scripting.FileSystemObject")
set shell = CreateObject("WScript.Shell")
strValueName = "HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias"
minTimeOffset = shell.regread(strValueName)
toffset = datediff("h",DateAdd("n", minTimeOffset, now()),now())
dtListFrom = DateAdd("n", minTimeOffset, now())
dtListTo = isodateit(DateAdd("d",7,dtListFrom))
dtListFrom = isodateit(dtListFrom)
set Rec = CreateObject("ADODB.Record")
set Rec1 = CreateObject("ADODB.Record")
Set Conn = CreateObject("ADODB.Connection")
mailboxurl = ADODBRec.fields("Dav:parentname")
Conn.Provider = "ExOLEDB.DataSource"
Rec.Open mailboxurl, ,3
SSql = "Select ""DAV:href"", ""urn:schemas:httpmail:subject"", ""urn:schemas:calendar:dtstart"", ""urn:schemas:calendar:dtend"", "
SSql = SSql & " ""urn:schemas:calendar:organizer"", ""urn:schemas:calendar:location"", ""DAV:contentclass"", "
SSql = SSql & " ""urn:schemas:httpmail:textdescription"", ""urn:schemas:httpmail:fromemail"", ""DAV:ishidden"" "
SSql = SSql & " FROM scope('shallow traversal of """ & mailboxurl & """') "
SSql = SSql & "WHERE (""urn:schemas:calendar:dtstart"" >= CAST(""" & dtListFrom & """ as 'dateTime')) "
SSql = SSql & "AND (""urn:schemas:calendar:dtstart"" < ssql =" SSql" cursorlocation =" 3" aduseserver =" 2," aduseclient =" 3" cursortype =" 3"> 0 then
Rs.movefirst
while not rs.eof
if rs.fields("DAV:ishidden") = 0 then
Set objField2 = objDom.createElement("item")
objfield1.appendChild objField2
Set objField8 = objDom.createElement("title")
objfield8.text = rs.fields("urn:schemas:httpmail:subject")
objfield2.appendChild objField8
Set objField9 = objDom.createElement("link")
objfield9.text = "http://servername/exchange" & right(Rs.fields("Dav:href"),(len(Rs.fields("Dav:href"))-instr(Rs.fields("Dav:href"),"/MBX/"))-3)
objfield2.appendChild objField9
Set objField10 = objDom.createElement("description")
if isnull(Rs.fields("urn:schemas:httpmail:textdescription")) then
Etext = "Starts : " & dateadd("h",toffset,rs.fields("urn:schemas:calendar:dtstart")) & "<br>" Etext = Etext & "Ends : " & dateadd("h",toffset,rs.fields("urn:schemas:calendar:dtend")) & "<br>"

Etext = Etext & "Location : " & rs.fields("urn:schemas:calendar:location")
objfield10.text = Etext
else
Etext = "Starts : " & dateadd("h",toffset,rs.fields("urn:schemas:calendar:dtstart")) & "<br>"
Etext = Etext & "Ends : " & dateadd("h",toffset,rs.fields("urn:schemas:calendar:dtend")) & "<br>"
Etext = Etext & "Location : " & rs.fields("urn:schemas:calendar:location") & "<br><br>"
Etext = Etext & Rs.fields("urn:schemas:httpmail:textdescription")
objfield10.text = Etext
end if
objfield2.appendChild objField10
Set objField11 = objDom.createElement("author")
objfield11.text = rs.fields("urn:schemas:httpmail:fromemail")
objfield2.appendChild objField11
Set objField12 = objDom.createElement("pubDate")
dtstartd = rs.fields("urn:schemas:calendar:dtstart")
objfield12.text = WeekdayName(weekday(dtstartd),3) & ", " & day(dtstartd) & " " & Monthname(month(dtstartd),3) & " " & year(dtstartd) & " " & formatdatetime(rs.fields("urn:schemas:calendar:dtstart"),4) & ":00 GMT"
objfield2.appendChild objField12
set objfield2 = nothing
set objfield8 = nothing
set objfield9 = nothing
set objfield10 = nothing
set objfield11 = nothing
end if
rs.movenext
wend
end if
rs.close
Set objPI = objDom.createProcessingInstruction("xml", "version='1.0'")
objDom.insertBefore objPI, objDom.childNodes(0)
objdom.save("\\servername\inetpub\calpub.xml")

End Sub

function isodateit(datetocon)
strDateTime = year(datetocon) & "-"
if (Month(datetocon) < 10) then strDateTime = strDateTime & "0"
strDateTime = strDateTime &amp;amp;amp; Month(datetocon) & "-"
if (Day(datetocon) < 10) then strDateTime = strDateTime & "0"
strDateTime = strDateTime &amp;amp; Day(datetocon) & "T" & formatdatetime(datetocon,4) & ":00Z"
isodateit = strDateTime
end function

[Sorry about the edits blogger keep eating the function ]

Popular posts from this blog

Testing and Sending email via SMTP using Opportunistic TLS and oAuth in Office365 with PowerShell

As well as EWS and Remote PowerShell (RPS) other mail protocols POP3, IMAP and SMTP have had OAuth authentication enabled in Exchange Online (Official announcement here ). A while ago I created  this script that used Opportunistic TLS to perform a Telnet style test against a SMTP server using SMTP AUTH. Now that oAuth authentication has been enabled in office365 I've updated this script to be able to use oAuth instead of SMTP Auth to test against Office365. I've also included a function to actually send a Message. Token Acquisition  To Send a Mail using oAuth you first need to get an Access token from Azure AD there are plenty of ways of doing this in PowerShell. You could use a library like MSAL or ADAL (just google your favoured method) or use a library less approach which I've included with this script . Whatever way you do this you need to make sure that your application registration  https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-

How to access and restore deleted Items (Recoverable Items) in the Exchange Online Mailbox dumpster with the Microsoft Graph API and PowerShell

As the information on how to do this would cover multiple posts, I've bound this into a series of mini post docs in my GitHub Repo to try and make this subject a little easier to understand and hopefully navigate for most people.   The Binder index is  https://gscales.github.io/Graph-Powershell-101-Binder/   The topics covered are How you can access the Recoverable Items Folders (and get the size of these folders)  How you can access and search for items in the Deletions and Purges Folders and also how you can Export an item to an Eml from that folder How you can Restore a Deleted Item back to the folder it was deleted from (using the Last Active Parent FolderId) and the sample script is located  https://github.com/gscales/Powershell-Scripts/blob/master/Graph101/Dumpster.ps1

Using the MSAL (Microsoft Authentication Library) in EWS with Office365

Last July Microsoft announced here they would be disabling basic authentication in EWS on October 13 2020 which is now a little over a year away. Given the amount of time that has passed since the announcement any line of business applications or third party applications that you use that had been using Basic authentication should have been modified or upgraded to support using oAuth. If this isn't the case the time to take action is now. When you need to migrate a .NET app or script you have using EWS and basic Authentication you have two Authentication libraries you can choose from ADAL - Azure AD Authentication Library (uses the v1 Azure AD Endpoint) MSAL - Microsoft Authentication Library (uses the v2 Microsoft Identity Platform Endpoint) the most common library you will come across in use is the ADAL libraries because its been around the longest, has good support across a number of languages and allows complex authentications scenarios with support for SAML etc. The
All sample scripts and source code is provided by for illustrative purposes only. All examples are untested in different environments and therefore, I cannot guarantee or imply reliability, serviceability, or function of these programs.

All code contained herein is provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.