What about using a CSS3 attribute selector, like so:
Code:
div[id^=post_message_] img { max-width: 100%; height: auto; }
(If you're not familiar with the syntax, this only targets divs with an ID of the form post_message_XXXX, regardless of what the numeric string is on the end of the ID).
Should work in all modern browsers, and even in IE7+. IE6 would be left in the cold, but it would be no worse for those users than it is at present.