My first instinct would be to grab the md5 sum of the message (including headers). You should be pretty safe there. As mentioned above, no matter what method you should always try and detect filename collision and perhaps alter based on that. Most programs tend to change filename to filename-2 in the case of a collision.