如何修复DOMException解码电子邮件

时间:2019-03-22 18:50:58

标签: gmail-api

我正在使用GMail API检索消息。这些消息是机器生成的,因此遵循类似的格式。

尽管大多数消息都很好,但是我得到了一个使用atob解码消息主体的消息主体的DOMException。

我认为我已将其范围缩小到其中包含以下部分的邮件:

     --------------------- Sudo (secure-log) Begin ------------------------ 


     jeremy => root
     --------------
     /usr/bin/docker                -   5 Time(s).

     ---------------------- Sudo (secure-log) End ------------------------- 

具体地说,我认为问题是由于=>引起的。

错误是: Error parsing DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.

代码片段:

    gapi.client.gmail.users.threads.get({
       userId: 'me',
       id:     thread.id
    })
    .then(function(response){
       var
          content,
          message = response.result.messages[0],
          rawContent = message.payload.body.data;

    try{
       content = atob(rawContent);
    }

1 个答案:

答案 0 :(得分:0)

该主题帮助我Decode URL Safe Base64 in JavaScript (browser side)

    rawContent = rawContent.replace(/_/g, '/').replace(/-/g, '+');

修复它。

相关问题