如何使用 PHP 的 imap_fetchstruct() 消除错误消息?

发布于 2024-09-12 19:10:35 字数 567 浏览 6 评论 0原文

PHP 提供了非常有用的函数来从 POP3 帐户获取电子邮件,在我的例子中是处理退回邮件。然而,函数 imap_fetchstruct() 让我头疼。当在一个脚本中使用它时,我(对于某些邮件)收到以下消息:

注意:未知:警告:MIME 标头 在非 MIME 消息中遇到 (errflg=3) 位于第 0 行未知

向 PHP 报告的错误已设置为状态 Bugus (http://bugs.php.net/bug.php?id=43471),但我无法在文档中找到有关此问题的线索。

在函数之前放置 @ 或在函数之前更改错误处理程序(并在之后重置它)都没有帮助。关闭错误报告或永久更改错误处理程序或错误报告级别帮助(似乎错误是在脚本的 和 处触发的) - 但是,我需要注册使用此函数后可能发生的其他错误。

因此,我在 Stackoverflow 上寻找提示:该函数究竟哀悼什么(我猜是格式错误的 MIME 标头或内容)以及如何摆脱此错误通知?

PHP provides very useful functions to fetch emails from a POP3 account, in my case to handle bounce-mails. The function imap_fetchstructure(), however, gives me headache. When using it in one script, I (for some mails) get the message:

Notice: Unknown: Warning: MIME header
encountered in non-MIME message
(errflg=3) in Unknown on line 0

A Bug reported to PHP was set to status Bugus (http://bugs.php.net/bug.php?id=43471), but I fail to find a clue on this problem in the documentation.

Neither placing a @ before the function nor changing the error handler before the function (and resetting it after that) helps. Turning error reporting off or permanently changing the error handler or the error reporting level help (it seems that the error is triggered at the and of the script) - however, I need to register other errors that may occur after using this function.

Therefore I search for a hint at Stackoverflow: What exactly does the function mourn about (I guess a malformned MIME header or content) and how do I get rid of this error notice?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

明月夜 2024-09-19 19:10:35

我相信当您调用 imap_close() 时,或者在缺少该函数的情况下,当脚本结束时,会发出错误消息。尝试在此之前调用 imap_errors() (以清除错误堆栈)。

$struct = imap_fetchstructure($imap, $num);
$errs = imap_errors();
imap_close($imap);

I believe the error message is emitted when you call imap_close(), or, in that function's absence, when the script ends. Try calling imap_errors() before that (to clear the error stack).

$struct = imap_fetchstructure($imap, $num);
$errs = imap_errors();
imap_close($imap);
浪推晚风 2024-09-19 19:10:35

错误不是由 php 发出的,这可能就是 @ 不起作用的原因。 见下文!

在 php 源代码中,您将在 ext/imap/php_imap.c 中找到函数 imap_fetchstruct(),它是 mail_fetchstructure_full() 的包装器,而后者是c 客户端库。

在该库中的 c-client/rfc822.c 中有一个有趣的段落:

  case 'C':                 /* possible cc: or Content-<mumble>*/
    if (!strcmp (tmp+1,"C")) rfc822_parse_adrlist (&env->cc,d,host);
    else if ((tmp[1] == 'O') && (tmp[2] == 'N') && (tmp[3] == 'T') &&
             (tmp[4] == 'E') && (tmp[5] == 'N') && (tmp[6] == 'T') &&
             (tmp[7] == '-') && body)
      switch (MIMEp) {
      case -1:              /* unknown if MIME or not */
        if (!(MIMEp =       /* see if MIME-Version header exists */
              search ((unsigned char *) s-1,i,
                      (unsigned char *)"\012MIME-Version",(long) 13))) {
#if 1
         /* This is a disgusting kludge, and most of the messages which
           * benefit from it are spam.
           */
          if (!strcmp (tmp+8,"TRANSFER-ENCODING") ||
              (!strcmp (tmp+8,"TYPE") && strchr (d,'/'))) {
            MM_LOG ("Warning: MIME header encountered in non-MIME message",
                    PARSE);
            MIMEp = 1;      /* declare MIME now */
          }
          else
#endif

根据 grep,这是唯一生成错误的地方。所以这解释了我认为的大多数谜团。

因此,您有一条带有 CONTENT-TRANSFER-ENCODING 或 CONTENT-TYPE 行的消息,但没有 MIME-Version 标头。

edit MM_LOG 被定义为 mm_log,而 mm_log 又是 php/ext/imap/php_imap.c 提供的函数。来自 imap_fetchstruction() 的错误被放入错误列表中(它们不会直接输出!),您可以使用 imap_errors() 查询该错误列表并清空该列表。然后,在关闭资源时,不会显示错误,因为错误列表为空。

The error is not emitted by php, that's probably why @ doesn't work. see below!

in the php source you'll find the function imap_fetchstructure() in ext/imap/php_imap.c, which is a wrapper for mail_fetchstructure_full(), which is a part of the c-client library.

In that library, in c-client/rfc822.c there's an interesting passage:

  case 'C':                 /* possible cc: or Content-<mumble>*/
    if (!strcmp (tmp+1,"C")) rfc822_parse_adrlist (&env->cc,d,host);
    else if ((tmp[1] == 'O') && (tmp[2] == 'N') && (tmp[3] == 'T') &&
             (tmp[4] == 'E') && (tmp[5] == 'N') && (tmp[6] == 'T') &&
             (tmp[7] == '-') && body)
      switch (MIMEp) {
      case -1:              /* unknown if MIME or not */
        if (!(MIMEp =       /* see if MIME-Version header exists */
              search ((unsigned char *) s-1,i,
                      (unsigned char *)"\012MIME-Version",(long) 13))) {
#if 1
         /* This is a disgusting kludge, and most of the messages which
           * benefit from it are spam.
           */
          if (!strcmp (tmp+8,"TRANSFER-ENCODING") ||
              (!strcmp (tmp+8,"TYPE") && strchr (d,'/'))) {
            MM_LOG ("Warning: MIME header encountered in non-MIME message",
                    PARSE);
            MIMEp = 1;      /* declare MIME now */
          }
          else
#endif

This is the only place generating your error, according to grep. So that explains most mysteries I think.

So you have a message with a CONTENT-TRANSFER-ENCODING or CONTENT-TYPE line, without a MIME-Version header.

edit MM_LOG is defined to mm_log, which is in turn a function that php/ext/imap/php_imap.c provides. The errors from imap_fetchstructure() are put in a list of errors (they are not output directly!) which you may query and empty using imap_errors(). Then, on shutdown of the resource, the errors are not displayed since the error list is empty.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文