Fix bug where begining of a message was removed.
Simplify header parsing functions by using RegExp