Fix data writing to stream
bug #427 Fix data writing to stream (videv)

This PR was squashed before being merged into the 5.1-dev branch (closes #427).

Discussion
----------

Fix data writing to stream

There were problem with streaming data, when using embed images or while sending big message. Connection to SMTP server and email sending was an interrupted.
It was due to the fact that fwrite operations on non-blocking socket streams can be interrupted by the arrival of new packets.
After this fix writing continues  until all data is sent.

Commits
-------

214c5dc Fix data writing to stream