【问题标题】:imap_fetchstructure: how to distinguish embedded images from attachments?imap_fetchstructure:如何区分嵌入图像和附件?
【发布时间】:2013-03-10 19:10:47
【问题描述】:

我正在编写一个解析电子邮件收件箱的脚本。如何判断消息部分是附件还是嵌入图像?此示例邮件是由一位用户发送的,他告诉我他的客户嵌入了图像,但 disposition="Attachment" 看起来像附加图像,我看到 AppleMail 使用“内联”,这似乎更合理......

我还检查了 msg-text 以查看它是否引用了附加文件,但在此示例中也没有对文件的引用 - 但用户坚持认为它们是嵌入的,而不是附加的。

消息结构:

object(stdClass)#218 (12) {
  ["type"]=>
  int(1)
  ["encoding"]=>
  int(0)
  ["ifsubtype"]=>
  int(1)
  ["subtype"]=>
  string(5) "MIXED"
  ["ifdescription"]=>
  int(0)
  ["ifid"]=>
  int(0)
  ["bytes"]=>
  int(262312)
  ["ifdisposition"]=>
  int(0)
  ["ifdparameters"]=>
  int(0)
  ["ifparameters"]=>
  int(1)
  ["parameters"]=>
  array(1) {
    [0]=>
    object(stdClass)#219 (2) {
      ["attribute"]=>
      string(8) "BOUNDARY"
      ["value"]=>
      string(37) "----_=_NextPart_001_01CE168A.AE40BD2E"
    }
  }
  ["parts"]=>
  array(5) {
    [0]=>
    object(stdClass)#220 (12) {
      ["type"]=>
      int(1)
      ["encoding"]=>
      int(0)
      ["ifsubtype"]=>
      int(1)
      ["subtype"]=>
      string(11) "ALTERNATIVE"
      ["ifdescription"]=>
      int(0)
      ["ifid"]=>
      int(0)
      ["bytes"]=>
      int(4237)
      ["ifdisposition"]=>
      int(0)
      ["ifdparameters"]=>
      int(0)
      ["ifparameters"]=>
      int(1)
      ["parameters"]=>
      array(1) {
        [0]=>
        object(stdClass)#221 (2) {
          ["attribute"]=>
          string(8) "BOUNDARY"
          ["value"]=>
          string(37) "----_=_NextPart_002_01CE168A.AE40BD2E"
        }
      }
      ["parts"]=>
      array(2) {
        [0]=>
        object(stdClass)#222 (12) {
          ["type"]=>
          int(0)
          ["encoding"]=>
          int(4)
          ["ifsubtype"]=>
          int(1)
          ["subtype"]=>
          string(5) "PLAIN"
          ["ifdescription"]=>
          int(0)
          ["ifid"]=>
          int(0)
          ["lines"]=>
          int(21)
          ["bytes"]=>
          int(204)
          ["ifdisposition"]=>
          int(0)
          ["ifdparameters"]=>
          int(0)
          ["ifparameters"]=>
          int(1)
          ["parameters"]=>
          array(1) {
            [0]=>
            object(stdClass)#223 (2) {
              ["attribute"]=>
              string(7) "CHARSET"
              ["value"]=>
              string(10) "iso-8859-1"
            }
          }
        }
        [1]=>
        object(stdClass)#224 (12) {
          ["type"]=>
          int(0)
          ["encoding"]=>
          int(4)
          ["ifsubtype"]=>
          int(1)
          ["subtype"]=>
          string(4) "HTML"
          ["ifdescription"]=>
          int(0)
          ["ifid"]=>
          int(0)
          ["lines"]=>
          int(97)
          ["bytes"]=>
          int(3709)
          ["ifdisposition"]=>
          int(0)
          ["ifdparameters"]=>
          int(0)
          ["ifparameters"]=>
          int(1)
          ["parameters"]=>
          array(1) {
            [0]=>
            object(stdClass)#225 (2) {
              ["attribute"]=>
              string(7) "CHARSET"
              ["value"]=>
              string(10) "iso-8859-1"
            }
          }
        }
      }
    }
    [1]=>
    object(stdClass)#226 (14) {
      ["type"]=>
      int(5)
      ["encoding"]=>
      int(3)
      ["ifsubtype"]=>
      int(1)
      ["subtype"]=>
      string(3) "BMP"
      ["ifdescription"]=>
      int(1)
      ["description"]=>
      string(7) "bmp.bmp"
      ["ifid"]=>
      int(0)
      ["bytes"]=>
      int(191348)
      ["ifdisposition"]=>
      int(1)
      ["disposition"]=>
      string(10) "ATTACHMENT"
      ["ifdparameters"]=>
      int(1)
      ["dparameters"]=>
      array(1) {
        [0]=>
        object(stdClass)#227 (2) {
          ["attribute"]=>
          string(8) "FILENAME"
          ["value"]=>
          string(7) "bmp.bmp"
        }
      }
      ["ifparameters"]=>
      int(1)
      ["parameters"]=>
      array(1) {
        [0]=>
        object(stdClass)#228 (2) {
          ["attribute"]=>
          string(4) "NAME"
          ["value"]=>
          string(7) "bmp.bmp"
        }
      }
    }
    [2]=>
    object(stdClass)#229 (14) {
      ["type"]=>
      int(5)
      ["encoding"]=>
      int(3)
      ["ifsubtype"]=>
      int(1)
      ["subtype"]=>
      string(3) "GIF"
      ["ifdescription"]=>
      int(1)
      ["description"]=>
      string(7) "gif.gif"
      ["ifid"]=>
      int(0)
      ["bytes"]=>
      int(12178)
      ["ifdisposition"]=>
      int(1)
      ["disposition"]=>
      string(10) "ATTACHMENT"
      ["ifdparameters"]=>
      int(1)
      ["dparameters"]=>
      array(1) {
        [0]=>
        object(stdClass)#230 (2) {
          ["attribute"]=>
          string(8) "FILENAME"
          ["value"]=>
          string(7) "gif.gif"
        }
      }
      ["ifparameters"]=>
      int(1)
      ["parameters"]=>
      array(1) {
        [0]=>
        object(stdClass)#231 (2) {
          ["attribute"]=>
          string(4) "NAME"
          ["value"]=>
          string(7) "gif.gif"
        }
      }
    }
    [3]=>
    object(stdClass)#232 (14) {
      ["type"]=>
      int(5)
      ["encoding"]=>
      int(3)
      ["ifsubtype"]=>
      int(1)
      ["subtype"]=>
      string(4) "JPEG"
      ["ifdescription"]=>
      int(1)
      ["description"]=>
      string(7) "jpg.jpg"
      ["ifid"]=>
      int(0)
      ["bytes"]=>
      int(25642)
      ["ifdisposition"]=>
      int(1)
      ["disposition"]=>
      string(10) "ATTACHMENT"
      ["ifdparameters"]=>
      int(1)
      ["dparameters"]=>
      array(1) {
        [0]=>
        object(stdClass)#233 (2) {
          ["attribute"]=>
          string(8) "FILENAME"
          ["value"]=>
          string(7) "jpg.jpg"
        }
      }
      ["ifparameters"]=>
      int(1)
      ["parameters"]=>
      array(1) {
        [0]=>
        object(stdClass)#234 (2) {
          ["attribute"]=>
          string(4) "NAME"
          ["value"]=>
          string(7) "jpg.jpg"
        }
      }
    }
    [4]=>
    object(stdClass)#235 (14) {
      ["type"]=>
      int(3)
      ["encoding"]=>
      int(3)
      ["ifsubtype"]=>
      int(1)
      ["subtype"]=>
      string(12) "OCTET-STREAM"
      ["ifdescription"]=>
      int(1)
      ["description"]=>
      string(7) "pdf.pdf"
      ["ifid"]=>
      int(0)
      ["bytes"]=>
      int(27834)
      ["ifdisposition"]=>
      int(1)
      ["disposition"]=>
      string(10) "ATTACHMENT"
      ["ifdparameters"]=>
      int(1)
      ["dparameters"]=>
      array(1) {
        [0]=>
        object(stdClass)#236 (2) {
          ["attribute"]=>
          string(8) "FILENAME"
          ["value"]=>
          string(7) "pdf.pdf"
        }
      }
      ["ifparameters"]=>
      int(1)
      ["parameters"]=>
      array(1) {
        [0]=>
        object(stdClass)#237 (2) {
          ["attribute"]=>
          string(4) "NAME"
          ["value"]=>
          string(7) "pdf.pdf"
        }
      }
    }
  }
}

【问题讨论】:

标签: php imap


【解决方案1】:

通过 [ifid] 检查图像是否内联的最佳方法。我检查了各种邮件应用程序。他们以不同的方式处理内联附件。 Zoho mail 标记了

[处置] => 内联

实时邮件标记

[处置] => 附件

两个都设置

[ifid] => 1 [id] =>

如果[ifid] => 1 则它是一个内联图像,[id] 将是图像 cid。下载内联附件并替换

src="cid:0.28876465441.6812139177583476518.150d8a30c19__inline__img__src"

带有下载路径

【讨论】:

    【解决方案2】:

    嵌入图像将是“multipart/related”类型的 MIME 正文部分的第二个和后续子代。附加图像将是“multipart/mixed”类型的 MIME 正文部分的子级。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-13
      • 2019-06-01
      • 2017-10-21
      • 2015-10-09
      • 2017-03-14
      • 2021-09-06
      • 2014-01-07
      相关资源
      最近更新 更多