jollyshots
MIS
I don't get it, what am I missing here? It sends the meeting no
problem, but not as a canclled meeting, and it does remove the meeting
from the calendar, but the sent e-mail is not cancelled. Any ideas?
const adModeReadWrite = 3
Const adLockOptimistic = 3
Const adFailIfNotExists = -1
Const adOpenSource = &H00800000
Const adOpenUnspecified = &Hffffffff
DIM addrfield, timeZ, xmlstr
DIM sExchangeServer, sDomain,sUserName,sPasswd
sExchangeServer = "exchange2"
sDomain = "MyDomain\"
sUserName = "testUser"
sPasswd = "Passwd12"
inboxURL = "sDestinationURL = "
Set imsg = createObject("CDO.Message")
Set oCn = createobject("ADODB.Connection")
Set oRs = createobject("ADODB.RecordSet")
Set XMLreq = CreateObject("Microsoft.xmlhttp")
oCn.Provider = "exoledb.datasource"
oCn.Open inboxURL, sDomain+sUserName, sPasswd, -1
'###### Generate the SQL statement ######
strSql = ""
strSql = "select"
strSql = strSql & " ""urn:schemas:mailheader:content-class"" "
strSql = strSql & ", ""DAV:href"" "
strSql = strSql & ", ""DAV:displayname"" "
strSql = strSql & ", ""urn:schemas:httpmail:subject"" "
strSql = strSql & ", ""mail:htmldescription"" "
strSql = strSql & ", ""urn:schemas:calendar:dtstart"" "
strSql = strSql & ", ""urn:schemas:calendar:dtend"" "
strSql = strSql & ", ""urn:schemas:calendar:busystatus"" "
strSql = strSql & ", ""urn:schemas:calendar:alldayevent"" "
strSql = strSql & ", ""urn:schemas:calendar:meetingstatus"" "
strSql = strSql & ", ""urn:schemas:calendar:responserequested"" "
strSql = strSql & ", ""urn:schemas:calendar:instancetype"" "
strSql = strSql & ", ""urn:schemas:calendar:uid"" "
strSql = strSql & ", ""urn:schemas:mailheader:bcc"" "
strSql = strSql & ", ""urn:schemas:mailheader:to"" "
strSql = strSql & ", ""urn:schemas:mailheader:cc"" "
strSql = strSql & ", ""urn:schemas:mailheader:from"" "
strSql = strSql & ", ""urn:schemas:calendar:recurrenceid "" "
strSql = strSql & " from scope ('shallow traversal of """& inboxurl & """') "
strSql = strSql & " WHERE ""DAV:ishidden"" = false"
strSql = strSql & " AND ""DAV:isfolder"" = false"
'###### Open the SQL Statement ######
oRs.Open strSql, oCn, adOpenUnspecified, adLockOptimistic, 1
oRs.MoveFirst
while not ORs.EOF
oField = oRs.Fields("DAV:href").value
wscript.echo oField
for i=0 to 15
wscript.echo (oRs.Fields(i).Name &" " & oRs.Fields(i).Value )
next
'###### Open the message ######
imsg.DataSource.Open ofield, oRs.ActiveConnection, admodeReadWrite, adfailIfNotExists,adOpenSource, "",""
'###### make sure the sender is the owner ######
if imsg.From = oRs.Fields("urn:schemas:mailheader:from") then
if (cstr(oRs.Fields("urn:schemas:calendar:alldayevent").value)) = false then
isallday = 0
else
isallday = 1
end if
'###### Re-Wrtie some data for proper formating ######
starttime = setutctime(oRs.Fields("urn:schemas:calendar:dtstart"))
endtime = setutctime(oRs.Fields("urn:schemas:calendar:dtend"))
tofield = formataddress(oRs.Fields("urn:schemas:mailheader:to"))
fromfield = formataddress(oRs.Fields("urn:schemas:mailheader:from"))
ccfield = formataddress(oRs.Fields("urn:schemas:mailheader:cc"))
bccfield = formataddress(oRs.Fields("urn:schemas:mailheader:bcc"))
wscript.echo starttime
wscript.echo endtime
'###### Generate the XML string ######
Set XMLreq = CreateObject("Microsoft.xmlhttp")
XMLreq.open "PROPPATCH", oField, False, sDomain&sUserName, sPasswd
xmlstr = "<?xml version=""1.0""?>" _
& "<gropertyupdate "_
& " xmlns:g=""DAV:"" "_
& " xmlns:e="" "_
& " xmlns:mapi="" "_
& " xmlns:mapit="" "_
& " xmlns:x=""xml:"" xmlns:cal=""urn:schemas:calendar:"" "_
& " xmlns:dt=""urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"" "_
& " xmlns:header=""urn:schemas:mailheader:"" "_
& " xmlns:mail=""urn:schemas:httpmail:""> "_
& " <g:set> "_
& " <grop> "_
& " <g:contentclass>urn:content-classes:calendarmessage</g:contentclass> "_
& " <eutlookmessageclass>Ipm.Schedule.Meeting.Canceled</eutlookmessageclass> "_
& " <e:x-priority-long dt:dt=""int"">2</e:x-priority-long> "_
& " <mail:subject>"&oRs.Fields("urn:schemas:httpmail:subject").value&"</mail:subject> "_
& " <mail:htmldescription>User Termination, Meeting Cancelled: "&oRs.Fields("urn:schemas:httpmail:subject").value&"</mail:htmldescription> "_
& " <header:cc>"&ccfield&"</header:cc> "_
& " <header:bcc>"&bccfield&"</header:bcc> "_
& " <header:to>"&tofield&"</header:to> "_
& " <cal:meetingstatus>CANCELLED</cal:meetingstatus> "_
& " <cal:dtend dt:dt=""dateTime.tz"">"&endtime&"</cal:dtend> "_
& " <cal:dtstart dt:dt=""dateTime.tz"">"&starttime&"</cal:dtstart> "_
& " <cal:alldayevent dt:dt=""boolean"">"&isallday&"</cal:alldayevent> "_
& " <cal:busystatus>"&oRs.Fields("urn:schemas:calendar:busystatus").value&"</cal:busystatus> "_
& " <cal:method>CANCEL</cal:method> "_
& " <cal:instancetype dt:dt=""int"">"&oRs.Fields("urn:schemas:calendar:instancetype").value&"</cal:instancetype> "_
& " <cal:removefromcalendar dt:dt=""boolean"">1</cal:removefromcalendar> "_
& " <cal:uid>"&oRs.Fields("urn:schemas:calendar:uid").value&"</cal:uid> "_
& " <mapi:appstateflags dt:dt=""int"">7</mapi:appstateflags> "_
& " <mapi:finvited dt:dt=""boolean"">1</mapi:finvited> "_
& " <mapi:responsestatus dt:dt=""int"">1</mapi:responsestatus> "_
& " <mapi:responsestate dt:dt=""int"">0</mapi:responsestate> "_
& " <mapi:responserequested dt:dt=""boolean"">0</mapi:responserequested> "_
& " <mapi:busystatus dt:dt=""int"">0</mapi:busystatus> "_
& " <mapi:intendedbusystatus dt:dt=""int"">0</mapi:intendedbusystatus> "_
& " </grop> "_
& " </g:set> "_
& " </gropertyupdate> "
'###### Change the Message Around ######
XMLreq.setRequestHeader "Content-Type", "text/xml;"
XMLreq.setRequestHeader "Translate", "f"
XMLreq.setRequestHeader "Content-Length:", Len(xmlstr)
XMLreq.send xmlstr
If (XMLreq.Status >= 200 And XMLreq.Status < 300) Then
Wscript.echo "Success! " & "Results = " & XMLreq.Status & ": " & XMLreq.statusText
ElseIf XMLreq.Status = 401 then
Wscript.echo "You don't have permission to do the job! Please check your permissions on this item."
Else
Wscript.echo "Request Failed. Results = " & XMLreq.Status & ": " & XMLreq.statusText
End If
'###### Send the Changed Message ######
XMLreq.open "MOVE", ofield, false, sDomain&sUserName, sPasswd
xmlReq.setRequestHeader "Destination", sDestinationURL
XMLreq.setRequestHeader "Content-Type", "message/rfc822;"
XMLreq.setRequestHeader "Translate", "f"
XMLreq.setRequestHeader "Content-Length:", Len(xmlstr)
XMLreq.send xmlstr
If (XMLreq.Status >= 200 And XMLreq.Status < 300) Then
Wscript.echo "Success! " & "Results = " & XMLreq.Status & ": " & XMLreq.statusText
ElseIf XMLreq.Status = 401 then
Wscript.echo "You don't have permission to do the job! Please check your permissions on this item."
Else
Wscript.echo "Request Failed. Results = " & XMLreq.Status & ": " & XMLreq.statusText
End If
'###### END CANCEL PART ######
end if
oRs.MoveNext
Wend
'#############################
'
' FUNCTIONS
'
'#############################
'## SETUTCTIME
Function setutctime (returntime)
syear = null
smonth = null
sday = null
stime = null
timeT = null
syear = year(returntime)
smonth = month(returntime)
sday = day(returntime)
if smonth < 10 then
smonth = 0 & smonth
end if
if sday < 10 then
sday = 0 & sday
end if
stime = formatdatetime(returntime,4)
timeT = syear & "-" & smonth & "-" & sday & "T"
setutctime = timeT & stime & ":" & "00Z"
end function
'## FORMATADDRESS
function formataddress (fieldtoparse)
addrfield = null
array1= null
array2= null
if not fieldtoparse = "" then
array1 = split (fieldtoparse,",")
for each item in array1
array2 = split(item,"<")
for i = 1 to ubound(array2)
addrfield = addrfield & replace(array2(i),">","")&","
i=i+2
next
next
fieldlen = len(addrfield)
addrfield = left(addrfield,fieldlen-1)
formataddress = addrfield
else
formataddress = ""
end if
end function
problem, but not as a canclled meeting, and it does remove the meeting
from the calendar, but the sent e-mail is not cancelled. Any ideas?
const adModeReadWrite = 3
Const adLockOptimistic = 3
Const adFailIfNotExists = -1
Const adOpenSource = &H00800000
Const adOpenUnspecified = &Hffffffff
DIM addrfield, timeZ, xmlstr
DIM sExchangeServer, sDomain,sUserName,sPasswd
sExchangeServer = "exchange2"
sDomain = "MyDomain\"
sUserName = "testUser"
sPasswd = "Passwd12"
inboxURL = "sDestinationURL = "
Set imsg = createObject("CDO.Message")
Set oCn = createobject("ADODB.Connection")
Set oRs = createobject("ADODB.RecordSet")
Set XMLreq = CreateObject("Microsoft.xmlhttp")
oCn.Provider = "exoledb.datasource"
oCn.Open inboxURL, sDomain+sUserName, sPasswd, -1
'###### Generate the SQL statement ######
strSql = ""
strSql = "select"
strSql = strSql & " ""urn:schemas:mailheader:content-class"" "
strSql = strSql & ", ""DAV:href"" "
strSql = strSql & ", ""DAV:displayname"" "
strSql = strSql & ", ""urn:schemas:httpmail:subject"" "
strSql = strSql & ", ""mail:htmldescription"" "
strSql = strSql & ", ""urn:schemas:calendar:dtstart"" "
strSql = strSql & ", ""urn:schemas:calendar:dtend"" "
strSql = strSql & ", ""urn:schemas:calendar:busystatus"" "
strSql = strSql & ", ""urn:schemas:calendar:alldayevent"" "
strSql = strSql & ", ""urn:schemas:calendar:meetingstatus"" "
strSql = strSql & ", ""urn:schemas:calendar:responserequested"" "
strSql = strSql & ", ""urn:schemas:calendar:instancetype"" "
strSql = strSql & ", ""urn:schemas:calendar:uid"" "
strSql = strSql & ", ""urn:schemas:mailheader:bcc"" "
strSql = strSql & ", ""urn:schemas:mailheader:to"" "
strSql = strSql & ", ""urn:schemas:mailheader:cc"" "
strSql = strSql & ", ""urn:schemas:mailheader:from"" "
strSql = strSql & ", ""urn:schemas:calendar:recurrenceid "" "
strSql = strSql & " from scope ('shallow traversal of """& inboxurl & """') "
strSql = strSql & " WHERE ""DAV:ishidden"" = false"
strSql = strSql & " AND ""DAV:isfolder"" = false"
'###### Open the SQL Statement ######
oRs.Open strSql, oCn, adOpenUnspecified, adLockOptimistic, 1
oRs.MoveFirst
while not ORs.EOF
oField = oRs.Fields("DAV:href").value
wscript.echo oField
for i=0 to 15
wscript.echo (oRs.Fields(i).Name &" " & oRs.Fields(i).Value )
next
'###### Open the message ######
imsg.DataSource.Open ofield, oRs.ActiveConnection, admodeReadWrite, adfailIfNotExists,adOpenSource, "",""
'###### make sure the sender is the owner ######
if imsg.From = oRs.Fields("urn:schemas:mailheader:from") then
if (cstr(oRs.Fields("urn:schemas:calendar:alldayevent").value)) = false then
isallday = 0
else
isallday = 1
end if
'###### Re-Wrtie some data for proper formating ######
starttime = setutctime(oRs.Fields("urn:schemas:calendar:dtstart"))
endtime = setutctime(oRs.Fields("urn:schemas:calendar:dtend"))
tofield = formataddress(oRs.Fields("urn:schemas:mailheader:to"))
fromfield = formataddress(oRs.Fields("urn:schemas:mailheader:from"))
ccfield = formataddress(oRs.Fields("urn:schemas:mailheader:cc"))
bccfield = formataddress(oRs.Fields("urn:schemas:mailheader:bcc"))
wscript.echo starttime
wscript.echo endtime
'###### Generate the XML string ######
Set XMLreq = CreateObject("Microsoft.xmlhttp")
XMLreq.open "PROPPATCH", oField, False, sDomain&sUserName, sPasswd
xmlstr = "<?xml version=""1.0""?>" _
& "<gropertyupdate "_
& " xmlns:g=""DAV:"" "_
& " xmlns:e="" "_
& " xmlns:mapi="" "_
& " xmlns:mapit="" "_
& " xmlns:x=""xml:"" xmlns:cal=""urn:schemas:calendar:"" "_
& " xmlns:dt=""urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"" "_
& " xmlns:header=""urn:schemas:mailheader:"" "_
& " xmlns:mail=""urn:schemas:httpmail:""> "_
& " <g:set> "_
& " <grop> "_
& " <g:contentclass>urn:content-classes:calendarmessage</g:contentclass> "_
& " <eutlookmessageclass>Ipm.Schedule.Meeting.Canceled</eutlookmessageclass> "_
& " <e:x-priority-long dt:dt=""int"">2</e:x-priority-long> "_
& " <mail:subject>"&oRs.Fields("urn:schemas:httpmail:subject").value&"</mail:subject> "_
& " <mail:htmldescription>User Termination, Meeting Cancelled: "&oRs.Fields("urn:schemas:httpmail:subject").value&"</mail:htmldescription> "_
& " <header:cc>"&ccfield&"</header:cc> "_
& " <header:bcc>"&bccfield&"</header:bcc> "_
& " <header:to>"&tofield&"</header:to> "_
& " <cal:meetingstatus>CANCELLED</cal:meetingstatus> "_
& " <cal:dtend dt:dt=""dateTime.tz"">"&endtime&"</cal:dtend> "_
& " <cal:dtstart dt:dt=""dateTime.tz"">"&starttime&"</cal:dtstart> "_
& " <cal:alldayevent dt:dt=""boolean"">"&isallday&"</cal:alldayevent> "_
& " <cal:busystatus>"&oRs.Fields("urn:schemas:calendar:busystatus").value&"</cal:busystatus> "_
& " <cal:method>CANCEL</cal:method> "_
& " <cal:instancetype dt:dt=""int"">"&oRs.Fields("urn:schemas:calendar:instancetype").value&"</cal:instancetype> "_
& " <cal:removefromcalendar dt:dt=""boolean"">1</cal:removefromcalendar> "_
& " <cal:uid>"&oRs.Fields("urn:schemas:calendar:uid").value&"</cal:uid> "_
& " <mapi:appstateflags dt:dt=""int"">7</mapi:appstateflags> "_
& " <mapi:finvited dt:dt=""boolean"">1</mapi:finvited> "_
& " <mapi:responsestatus dt:dt=""int"">1</mapi:responsestatus> "_
& " <mapi:responsestate dt:dt=""int"">0</mapi:responsestate> "_
& " <mapi:responserequested dt:dt=""boolean"">0</mapi:responserequested> "_
& " <mapi:busystatus dt:dt=""int"">0</mapi:busystatus> "_
& " <mapi:intendedbusystatus dt:dt=""int"">0</mapi:intendedbusystatus> "_
& " </grop> "_
& " </g:set> "_
& " </gropertyupdate> "
'###### Change the Message Around ######
XMLreq.setRequestHeader "Content-Type", "text/xml;"
XMLreq.setRequestHeader "Translate", "f"
XMLreq.setRequestHeader "Content-Length:", Len(xmlstr)
XMLreq.send xmlstr
If (XMLreq.Status >= 200 And XMLreq.Status < 300) Then
Wscript.echo "Success! " & "Results = " & XMLreq.Status & ": " & XMLreq.statusText
ElseIf XMLreq.Status = 401 then
Wscript.echo "You don't have permission to do the job! Please check your permissions on this item."
Else
Wscript.echo "Request Failed. Results = " & XMLreq.Status & ": " & XMLreq.statusText
End If
'###### Send the Changed Message ######
XMLreq.open "MOVE", ofield, false, sDomain&sUserName, sPasswd
xmlReq.setRequestHeader "Destination", sDestinationURL
XMLreq.setRequestHeader "Content-Type", "message/rfc822;"
XMLreq.setRequestHeader "Translate", "f"
XMLreq.setRequestHeader "Content-Length:", Len(xmlstr)
XMLreq.send xmlstr
If (XMLreq.Status >= 200 And XMLreq.Status < 300) Then
Wscript.echo "Success! " & "Results = " & XMLreq.Status & ": " & XMLreq.statusText
ElseIf XMLreq.Status = 401 then
Wscript.echo "You don't have permission to do the job! Please check your permissions on this item."
Else
Wscript.echo "Request Failed. Results = " & XMLreq.Status & ": " & XMLreq.statusText
End If
'###### END CANCEL PART ######
end if
oRs.MoveNext
Wend
'#############################
'
' FUNCTIONS
'
'#############################
'## SETUTCTIME
Function setutctime (returntime)
syear = null
smonth = null
sday = null
stime = null
timeT = null
syear = year(returntime)
smonth = month(returntime)
sday = day(returntime)
if smonth < 10 then
smonth = 0 & smonth
end if
if sday < 10 then
sday = 0 & sday
end if
stime = formatdatetime(returntime,4)
timeT = syear & "-" & smonth & "-" & sday & "T"
setutctime = timeT & stime & ":" & "00Z"
end function
'## FORMATADDRESS
function formataddress (fieldtoparse)
addrfield = null
array1= null
array2= null
if not fieldtoparse = "" then
array1 = split (fieldtoparse,",")
for each item in array1
array2 = split(item,"<")
for i = 1 to ubound(array2)
addrfield = addrfield & replace(array2(i),">","")&","
i=i+2
next
next
fieldlen = len(addrfield)
addrfield = left(addrfield,fieldlen-1)
formataddress = addrfield
else
formataddress = ""
end if
end function