Reputation: 7530
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"
}
}
}
}
}
Upvotes: 3
Views: 2638
Reputation: 441
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
Upvotes: 3
Reputation: 22261
Embedded images will be the second and subsequent children of a MIME body part of type "multipart/related". Attached images will be children of a MIME body part of type "multipart/mixed".
Upvotes: 1