Get sender email from gmail-api
Loop through the headers[] array and look for the one with the 'name' = "From" (or whatever the header name is you're interested in). Note there may be multiple headers with that name. There are some standard headers that will usually exist (To, From, Subject) but I don't believe that's mandated by the RFC.
Know this question is from a while back, but I ran into this problem recently and couldn't really find any solutions online - so thought I'd share my findings.
Basically wrapping it in the htmlentities() would do the trick - but you'd have to access the part directly; as such:-
$part = $message->payload['modelData']['headers'][0]['value'];
echo htmlentities($part);
It seems that the API is removing the values because when you do a var_dump on the payload, the string value is actually visible.
["name"]=> string(11) "Return-Path" ["value"]=> string(21) ""
This works on the FROM part too. Just thought this would a much easier way to demonstrate it. :)