doubi9531 2013-03-10 19:10
浏览 130
已采纳

imap_fetchstructure:如何区分嵌入图像和附件?

I'm working on a script that parses email-inbox. How can tell if a message-part is an attachment or an embedded images? This sample mail was sent from a user who tells me his clients embedded the images, but disposition="Attachment" looks like an attached image, I saw AppleMail using "inline" which seems more plausible...

I also have done checks of the msg-text to see if it references the attached file, but in this sample there are also no refs to the files-and yet the user insists they were embedded,not attached.

Structure of the message:

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"
        }
      }
    }
  }
}
  • 写回答

3条回答 默认 最新

  • dongtongjian3127 2015-11-05 17:48
    关注

    The best way to check if the image is inline by [ifid]. I have checked various mail application. They handle the inline attachments differently. Zoho mail marks the

    [disposition] => inline

    Live mail marks

    [disposition] => attachment

    Both of them set

    [ifid] => 1 [id] => <0.28876465441.6812139177583476518.150d8a30c19__inline__img__src>

    if [ifid] => 1 then it is an inline image and [id] will be the image cid. download the inline attachment and replace

    src="cid:0.28876465441.6812139177583476518.150d8a30c19__inline__img__src"

    with the downloaded path

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用