Scans unattached media to see if it is included in the post content. If ...

...the media is referenced in the post content then the media is attached to the post. Function is taken from the XML-RPC implementation.

This brings the behavior of associating media with posts in-line with the XML-RPC implementation which I believe is the correct behavior.