Image Attachments not recognized
GoogleCodeExporter opened this issue · comments
Google Code Exporter commented
What steps will reproduce the problem?
1.Enter email with only image/jpeg attachment(s)
2.Call $Parser->getAttachments()
3.return is empty array
What is the expected output? What do you see instead?
Expect to see an image attachment, see an empty array instead
// the following snippet finds the image attachments
/**
* Returns the image attachments
* @return Array
*/
public function getImages() {
$images = array();
$types = array("image/jpeg");
foreach($this->parts as $part) {
$type = $this->getPartContentType($part);
if(in_array($type, $types)) {
$images[] = new MimeMailParser_attachment("image", $type, $this->getAttachmentStream($part));
}
}
return $images;
}
Original issue reported on code.google.com by andrewp...@gmail.com
on 26 Feb 2011 at 6:47
Google Code Exporter commented
Confirmed that this is a problem and that the mentioned fix works. An
improvement on the above code, placed underneath the getAttachments method
definition:
/**
* Returns the image attachments
* @return Array
*/
public function getImages() {
$images = array();
$types = array("image/jpeg", "image/png");
foreach($this->parts as $part) {
$type = $this->getPartContentType($part);
if(in_array($type, $types)) {
$images[] = new MimeMailParser_attachment(
$part['content-name'],
$type,
$this->getAttachmentStream($part),
null,
$this->getPartHeaders($part)
);
}
}
return $images;
}
This version gives the MimeMailParser_attachment more information. In
particular, $attachment->filename should work properly this way.
Original comment by Daniel.S...@gmail.com
on 29 Dec 2011 at 4:45
Google Code Exporter commented
Further information: This seems to be an issue with certain email clients not
adding a Content-Disposition header to some image attachments.
Original comment by Daniel.S...@gmail.com
on 29 Dec 2011 at 5:05
Google Code Exporter commented
I've added you guys to the project contributors so you can commit to SVN. Feel
free to add the patch.
Maybe it should do a regular expression match for image types instead?
/**
* Returns the image attachments
* @return Array
*/
public function getImages() {
$images = array();
$types = "/^image\/(.*)$/";
foreach($this->parts as $part) {
$type = $this->getPartContentType($part);
if(preg_match($types, $type)) {
$images[] = new MimeMailParser_attachment(
$part['content-name'],
$type,
$this->getAttachmentStream($part),
null,
$this->getPartHeaders($part)
);
}
}
return $images;
}
Original comment by buca...@gmail.com
on 30 Dec 2011 at 3:36