Skip to main content

Setting the Appointment Label Text Programmatically

Last week I blogged this Appointment label Colour Changing Event Sink and I mentioned that the appointment label text is located in the http://schemas.microsoft.com/mapi/proptag/0x36DC0102 property in an undocumented binary form. Well I had a crack at working out what that format is this week and I've come up with the following sample.

Before I start though I must give the following warning, the following piece of code and method is completely unsupported and completely untested. Playing around with binary properties is very unwise unless you really have a good enough grasp to be able to undo any damage you may do trying to set them. The third and last bit is that this will only work if your using the ASCII character set. If you're using other types of character sets (eg a lot of Asian character sets) this wont work.

Because this property is stored in a binary format to work with this in VBS we need something that can read binary and convert it to a hex string which makes it usable. For this I've used Arrayconvert out of this KB article. This library works well and it free and easy to use, the only thing it doesn't do is convert directly a string to hex but you can do this indirectly by first converting the sting to binary and then to hex.

So when no customizations have been made to the labels this property is set to a hex value of 44 Zero's (I know this is not a proper explanation of binary). Or as I'm going to deal with it in the script its 11 groups of "0000". As we have 10 labels then 10 of these groups represent a spacer for each label and the lasts group represents the padding to begin. These groups of 0's are constants in this property they only change in location in relation to the text that's being inserted into the labels.

So the major task that this script does is builds the hex string to be inserted into the property. The first thing it does is sets up a 10 element array to hold all the spacer values for each label. (We already know that this property is going to start with "0000"). The next thing it does is setups up a 10 element array to hold the values for all the customized label texts.

The next part of code then loops through the spacer array and checks to see if any text is going to be inserted from the corresponding label array. If text has been set in that label array element it then first converts the text to a hex string (by way of converting it to binary then back to hex). Then because each character is given 4 digits for storage and USASCII only uses the first 2 digits the hex string is split apart and each hex character representation is padded with "00".

So what we end up with is a hex string representing all the values and spacers that need to be set. Some Exoledb/ADO code is then used to set the x36DC0102 property using the arrayconvert library to convert this hex string into the octent Variant Array of bytes needed for this property.

Thats it as I said you should view this code as experimental and highly suspect. I've posted a downloadable copy of the code here. In my example I'm only setting the two values for blue and green to Internal and External. Eg.

dim objspcarray(9)
dim objlabelarray(9)
set rec = createobject("ADODB.Record")
Set cnvt = CreateObject("ADs.ArrayConvert")
objspcarray(0) = "0000"
objspcarray(1) = "0000"
objspcarray(2) = "0000"
objspcarray(3) = "0000"
objspcarray(4) = "0000"
objspcarray(5) = "0000"
objspcarray(6) = "0000"
objspcarray(7) = "0000"
objspcarray(8) = "0000"
objspcarray(9) = "0000"
objlabelarray(0) = ""
objlabelarray(1) = "External"
objlabelarray(2) = "Internal"
objlabelarray(3) = ""
objlabelarray(4) = ""
objlabelarray(5) = ""
objlabelarray(6) = ""
objlabelarray(7) = ""
objlabelarray(8) = ""
objlabelarray(9) = ""
dstring = "0000"
for i = lbound(objspcarray) to ubound(objspcarray)
if objlabelarray(i) <> "" then
objtooct = cnvt.CvStr2vOctetStr(objlabelarray(i))
objtohex = cnvt.CvOctetStr2vHexStr(objtooct)
for h = 1 to len(objtohex)/2
dstring = dstring & mid(objtohex,((h*2)-1),2) & "00"
next
end if
dstring = dstring & objspcarray(i)
next
wscript.echo dstring
rec.open "file://./backofficestorage/domain/mbx/mailbox/calendar",,3
rec.fields("http://schemas.microsoft.com/mapi/proptag/x36DC0102").Value = cnvt.CvHexStr2vOctetStr(dstring)
rec.fields.update
rec.close

Popular posts from this blog

The MailboxConcurrency limit and using Batching in the Microsoft Graph API

If your getting an error such as Application is over its MailboxConcurrency limit while using the Microsoft Graph API this post may help you understand why. Background   The Mailbox  concurrency limit when your using the Graph API is 4 as per https://docs.microsoft.com/en-us/graph/throttling#outlook-service-limits . This is evaluated for each app ID and mailbox combination so this means you can have different apps running under the same credentials and the poor behavior of one won't cause the other to be throttled. If you compared that to EWS you could have up to 27 concurrent connections but they are shared across all apps on a first come first served basis. Batching Batching in the Graph API is a way of combining multiple requests into a single HTTP request. Batching in the Exchange Mail API's EWS and MAPI has been around for a long time and its common, for email Apps to process large numbers of smaller items for a variety of reasons.  Batching in the Gr...

Sending a MimeMessage via the Microsoft Graph using the Graph SDK, MimeKit and MSAL

One of the new features added to the Microsoft Graph recently was the ability to create and send Mime Messages (you have been able to get Message as Mime for a while). This is useful in a number of different scenarios especially when trying to create a Message with inline Images which has historically been hard to do with both the Graph and EWS (if you don't use MIME). It also opens up using SMIME for encryption and a more easy migration path for sending using SMTP in some apps. MimeKit is a great open source library for parsing and creating MIME messages so it offers a really easy solution for tackling this issue. The current documentation on Send message via MIME lacks any real sample so I've put together a quick console app that use MSAL, MIME kit and the Graph SDK to send a Message via MIME. As the current Graph SDK also doesn't support sending via MIME either there is a workaround for this in the future my guess is this will be supported.

Export calendar Items to a CSV file using Microsoft Graph and Powershell

For the last couple of years the most constantly popular post by number of views on this blog has been  Export calendar Items to a CSV file using EWS and Powershell closely followed by the contact exports scripts. It goes to show this is just a perennial issue that exists around Mail servers, I think the first VBS script I wrote to do this type of thing was late 90's against Exchange 5.5 using cdo 1.2. Now it's 2020 and if your running Office365 you should really be using the Microsoft Graph API to do this. So what I've done is create a PowerShell Module (and I made it a one file script for those that are more comfortable with that format) that's a port of the EWS script above that is so popular. This script uses the ADAL library for Modern Authentication (which if you grab the library from the PowerShell gallery will come down with the module). Most EWS properties map one to one with the Graph and the Graph actually provides better information on recurrences then...
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.