I am using ItemAttachmentGetName to determine the filename that an
attachment will have when opened. I give it the message id and the what I
get back matches the temporary filename, unfortunately this doesn't work
when the attachment has certain characters in it e.g. []''

In this case using X00 as the message ID gets the correct filename but now
the problem is that the temporary file is never deleted.

What is the best way to determine the filename where the attachment that
is opened is put?

Failing that what special characters will get stripped?