On Jan 7, 2008, at 4:37 AM, Alexandru Stanoi wrote:

Dave Fischetti wrote:
If you don't mind I do have one quick question about something different. The parser has been working great for me. All users who submit images from their phones are parsed and added to their account. This works great for all users accept those sending emails from a specific mobile carrier.

I check if there is an image with:

if ( get_class( $part ) === 'ezcMailFile' ) {

and when I get here, this is where I have the problem

$my_image = array_values(getimagesize($part->fileName));

For this specific carrier, I get this error every time an image is attached: <b>Warning</b>: array_values() [<a href='function.array- values'>function.array-values</a>]: The argument should be an array in <b>/var/www/vhosts/broadtexter.com/httpdocs/_maintenance/ phpcgi/ inboxManager.php5</b> on line <b>671</b><br />

I realize this is probably not a EZ issue. But perhaps there's something I should be doing differently for messages from this source.

Below is an example of the source of a message like this. I'm not sure whats different here when compared to the other users who get parsed no problem.

Thanks again:

Dave

Message Source below
------------------------------

MIME-Version: 1.0
Content-Type: multipart/related; type="text/html";
        boundary="----=_Part_659415_20850935.1199378668689"
Importance: Normal
X-MMS-Message-Type: MM4_forward.REQ
X-Priority: 3

------=_Part_659415_20850935.1199378668689
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable
Content-ID: <0000>
Content-Disposition: inline

<html>

[snip]

</html>

------=_Part_659415_20850935.1199378668689
Content-Type: text/plain; charset=utf-8; name=smiltextpartfilename0.txt
Content-Transfer-Encoding: 7bit
Content-Location: smiltextpartfilename0.txt
Content-ID: <155>
Content-Disposition: inline

msg
------=_Part_659415_20850935.1199378668689
Content-Type: image/jpeg; name=1231071650a.jpg
Content-Transfer-Encoding: base64
Content-Location:1231071650a.jpg
Content-ID: <156>

/9j/4AAQSkZJRgABAQAAAQABAAD/ 2wBDAAEBAQEBAQEBAQECAQEBAgICAQECAgICAgICAgIDAgMD AwMCAwMEBAQEBAMFBQUFBQUHBwcHBwgICAgICAgICAj/ 2wBDAQEBAQICAgUDAwUHBQQFBwgICAgI CAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAj/ xAGiAAAABgIDAQAA
AAAAAAAAAAAHCAYFBAkDCgIBAAsQAAIBAgUCAwQGBgUFAQMGbwECAwQRBQYhEgAHMUETCFEiYRRx
gTKRCaEj8M
Just following up on my message above regarding warnings I'm getting from emails from specific users phones. I solved the Warning problem by changing my code to check if its an array, before using array_values(), but I'm still unsure why the image was missed. All images are missed when they come from this one phone carrier. I parsing the mail as follows. Not sure why its being missed. unless the $type value is not 2 even though its a jpg. I'll look into that more.
foreach ( $parts as $part )
{
if ( get_class( $part ) === 'ezcMailText' && $part->subType === 'plain' && $bodySet != true )
        {
                $bodyFull = trim($part->text);
                $bodySet = true;
        }
        
        //////   MANAGE INCOMING IMAGE FROM FAN   //////
        if ( get_class( $part ) === 'ezcMailFile' && $imageSet != true) {
                
                $getImage = getimagesize($part->fileName);
                if (is_array($getImage) && $getImage !== false) {
                        $my_image = array_values($getImage);
                        list($width, $height, $type, $attr) = $my_image;
                        if ($type == 2 && basename($part->fileName)) {
if (filesize($part->fileName) < 4194304) { // only accept images < 4MB
                                        $imageErr = false;
                                        $imageSet = true;
                                        break;
                                } else {
                                        $imageErr = 1;
                                        break;
                                }
                        }
                } else {
                        $imageErr = 2;
                }
        }
}
Also, in some cases with this carrier, the content-type "name" does not match the Content-Location. In all my successful parsings so far, it did match. I'm wondering if the parser is looking at Content- Location when it should be looking at the "name" field, or at least using the name field when the 2 don't match.
Content-Type: image/jpeg; name=me.jpg
Content-Transfer-Encoding: base64
Content-Location:media1.jpeg
Content-ID: <268>
However
This seems to be the case with this message, but then again, my message below has the same "name" and Content-Location value. So I'm not sure why its being missed there.

Hi Dave,

The parser uses the filename specified in Content-Type (me.jpg) and not the one in Content-Location (media1.jpg). A temporary file is created and you access it with $part->fileName (eg. '/tmp/6520-1/ me.jpg'). So the file in the attachment exists.

You call getimagesize() on the file, which returns false, indicating that the file is not an image (and not that the file does not exist, because in that case it would throw a warning or notice).

The attachment in your previous mail seems to be a jpeg, but when I open it in gimp it says that it is not complete (but maybe you did not put all of it in the mail because it would have been too big). I replaced it with another image and it works. So I think the image from that mail is not supported by getimagesize().

Try copying the temporary file to another directory:

copy( $part->fileName, '/tmp/' . basename( $part->fileName ) );

before you call getimagesize() and open it in an image editor to see if the file is really an image.

Hope this helps.

Cheers,
Alex.

--
Alexandru Stanoi
eZ Components System Developer
eZ Systems | http://ez.no

Hey Alex. thx again.

I have all mail coming in and being parsed also redirected to another email account so I see everything that comes in as I test (since the parsed deletes things immediately). It seems that these files coming in are images. in one case the file was named the same in both cases but it wasn't picked up by the parser. The only other attachement in that email was some text file that was blank. so it should have seen the image. Maybe it was just a hiccup.

But then another one recently wasn't picked up. This one is from a different phone carrier:

Content-Type: image/jpeg; name=m_000c8e00983658a5839ec75edd2031a4.jpg
Content-Transfer-Encoding: base64
Content-Location:media1.jpeg
Content-ID: <136>

/9j/4AAQSkZJRgABAQEAYABgAAD/ 2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/ 2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIy MjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/ wAARCADiAKoDASIA AhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/ 8QAtRAAAgEDAwIEAwUFBAQA
AAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3
ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm
p6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4 +Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA
AwE... ... ... ... <snip>

The attachment in my mirrored mail shows up fine. The filename is "m_000c8e00983658a5839ec75edd2031a4.jpg" There are 5 other attachments in that email. All are gif files and should be skipped by my code I believe.

I actually went back to a few other emails from this carrier and their emails also have jpg images that are missed by the parser.

Do you have any other suggestions as to what might be causing this. DO you want me to send the full source for an email that had a missed image? Would more of my code help?

Thanks again.

Dave



-- 
Components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/components

Reply via email to