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; Month(datetocon) & "-"
if (Day(datetocon) < 10) then strDateTime = strDateTime & "0"
strDateTime = strDateTime &amp; Day(datetocon) & "T" & formatdatetime(datetocon,4) & ":00Z"
isodateit = strDateTime
end function
[Sorry about the edits blogger keep eating the function ]
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; Month(datetocon) & "-"
if (Day(datetocon) < 10) then strDateTime = strDateTime & "0"
strDateTime = strDateTime &amp; Day(datetocon) & "T" & formatdatetime(datetocon,4) & ":00Z"
isodateit = strDateTime
end function
[Sorry about the edits blogger keep eating the function ]