【问题标题】:How to fix DOMException Decoding Email Message如何修复 DOMException 解码电子邮件消息
【发布时间】:2019-04-23 07:28:00
【问题描述】:

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

虽然大多数消息都很好,但我得到了一个 DOMException,使用 atob 来解码消息子集的消息体。

我认为我已将其范围缩小到其中包含如下部分的消息:

     --------------------- 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);
    }

【问题讨论】:

    标签: gmail-api


    【解决方案1】:

    这个帖子帮助了我Decode URL Safe Base64 in JavaScript (browser side)

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

    修好了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-06
      • 1970-01-01
      • 2011-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多