Email was sent with empty subject. Fixed that: apparently subject was sent to function send_message with a trailing '\n', and then split("\n") was returning an empty string.