解码html电子邮件正文Gmail api

时间:2018-02-18 15:52:23

标签: php laravel decode gmail-api

使用Gmail API时解码html电子邮件正文的正确方法是什么。

// Expected: "<p><strong>Test test</strong></p>"
$message = $gmail->users_messages->get('me', $messageId);
$payload = $message->getPayload();
$body = $payload->getBody()->data;
Log::info('Raw body:', [$body]); // "PHA-PHN0cm9uZz5UZXN0IHRlc3Q8L3N0cm9uZz48L3A-"
Log::info('Base64 decoded body:', [base64_decode($body)]); // NO OUTPUT
Log::info('UTF8 encoded body:', [utf8_encode($body)]); // "PHA-PHN0cm9uZz5UZXN0IHRlc3Q8L3N0cm9uZz48L3A-"
Log::info('Quote print decoded:', [quoted_printable_decode($body)]); // "PHA-PHN0cm9uZz5UZXN0IHRlc3Q8L3N0cm9uZz48L3A-"
Log::info('Quote print decoded:', [quoted_printable_decode(base64_decode($body)))]); // NO OUTPUT

1 个答案:

答案 0 :(得分:4)

想出来。它需要一些额外的hackery,特别是base64url_decode函数found here

eax
相关问题