【问题标题】:Gmail IMAP E-mail Content GarbledGmail IMAP 电子邮件内容乱码
【发布时间】:2009-04-30 19:23:46
【问题描述】:

我有一个基于 Web 的自定义联系人管理系统,我们在 PHP 中构建了该系统来跟踪联系人,并且最近开始使用 IMAP 检查我们的 Google 电子邮箱,然后,如果该联系人在我们的联系人管理系统中:

  1. 将消息复制到与该联系人关联的 MySQL 数据库表中
  2. 标记该联系人以在当天跟进
  3. 在 Gmail 中存档邮件

一切似乎都运行良好,除了...每收到这么多电子邮件,我们都会收到一条看起来像这样的非常乱码:

FABRRRQAUUUUAJXDjxZrUtzNFa2UMwjYj5YnYgZ74Ndwa4bwfzqmpH3/wDZjTcl CnKdr2Fa7SJP+Ek8S/8AQJX/AMB5P8aZN4s162j33GmxxrnG54XUfqa6ysHxp/yA/wDtqv8AWuej jFUqKDgtSpQsr3L13r4tPDcOoShBcTxgog6FiP5CsrwtpjuzavekvcTZKFuwPf8AH+VZOlwS+Iby 1jlBFnZRKhGeDjt9Sf0Fd0qhVCqAABgA

我回去查看消息,它似乎只是文本,所以我认为它不是图像。知道如何防止这种情况发生吗?

提前致谢。

此致,

詹姆斯

【问题讨论】:

  • 我认为您需要让我们查看原始消息、标题和所有内容

标签: php gmail imap


【解决方案1】:

您提供的示例看起来像是 base64 编码的。邮件的标题会告诉你如何处理邮件的内容。

例如,以下定义了正文为纯文本的电子邮件消息,但其存储为 base64 编码。我已经“删除”了隐私敏感信息。

Received: from xxxxxxxxx ([xxx.xx.xx.xxx]) by xxxxxxxxxx.xxx.xxxxxxxxxxxxxxx.xxx with Microsoft SMTPSVC(6.0.3790.3959);
     Wed, 29 Apr 2009 21:29:16 +0000
Received: from xxxx-xxx-xxxxxx ([xxx.xx.xxx.xxxx]) by xxxxxxxx ; Wed, 29 Apr 2009 15:29:16
 -0600
Message-ID: <AADB29A7-AAED-4068-B4A8-300E3B0D93AB@localhost>
MIME-Version: 1.0
From: xxxxxxxxxx@xxxxxxxxxxxxxxx.com
To: xxxxxxxxxx@xxxxxxxxxxxxxxx.com
Date: 29 Apr 2009 15:29:16 -0600
Subject: xxxx Account Update
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: base64
Return-Path: xxxxxx@xxxxxxxx.com
X-OriginalArrivalTime: 29 Apr 2009 21:29:16.0374 (UTC) FILETIME=[8C63AF60:01C9C911]

密切注意 Content-Type 和 Content-Transfer-Encoding 标头。

【讨论】:

    【解决方案2】:

    我相信 IMAP 是通过 SSL 实现的,因此可能是与 IMAP 的连接不同步。我对此的最佳解决方案就是检查正文是否包含一个很长的单词。因为那个乱码没有空格:

    <?php
    function wordlength($txt, $limit)
    {
       $words = explode(' ', $txt);
    
       foreach($words as $v)
       {
           if(strlen($v) > $limit)
           {
                return false;
           }
       }
    
       return true;
    }
    ?>
    

    用法:

    <?php
    
    $txt = "Message Body would be here";
    
    if(!wordlength($txt, 45))
    {
        //maybe try to pull the message again or
        //send an email to you telling you there is a problem
    }
    
    ?>
    

    我选择了 45 个,以防有人在电子邮件中使用 Pneumonoultramicroscopicsilicovolcanoconiosis 这个词。 :D

    不过,乔丹可能是对的。它可能只是 base64 编码。然后我会explode()标题并搜索它,如果它在那里,一个简单的base64_decode()就可以了。

    【讨论】:

      【解决方案3】:

      这帮助我处理了一个乱码的电子邮件主题。 http://php.net/manual/en/function.imap-header.php

      【讨论】:

      • 虽然理论上这可以回答这个问题,it would be preferable 在这里包含答案的基本部分,并提供链接以供参考。
      猜你喜欢
      • 2016-01-15
      • 1970-01-01
      • 2012-10-10
      • 1970-01-01
      • 1970-01-01
      • 2022-12-28
      • 2015-02-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多