Implemented OpenSSL::PKCS7::write_smime

The implementation follows the C openssl source as much as possible. 

Have also made some minor changes to keep compatibility with the MRI implementation.