Re: 'Mail/mimeDecode': how can i identify attachments?

From: Date: Thu, 01 Apr 2010 11:48:15 +0000
Subject: Re: 'Mail/mimeDecode': how can i identify attachments?
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-30432@lists.php.net to get a copy of this message
On 1 April 2010 12:20, Robert P. J. Day <rpjday@crashcourse.ca> wrote: > On Thu, 1 Apr 2010, Richard Quadling wrote: > >> On 1 April 2010 11:30, Robert P. J. Day <rpjday@crashcourse.ca> wrote: >> > >> >  what sounds like an easy question but if i run incoming email >> > messages thru mimeDecode, how can i reliably distinguish between >> > messages that have non-text attachments (pic, audio, video) and those >> > that don't? >> > >> >  more specifically, i have a PHP script that's being fed incoming >> > text messages, some of which (SMS) have a simple, short text body, >> > while the others (MMS) will have some sort of attachment, and i want >> > to quickly distinguish between the two. >> > >> >  after mime decoding the incoming message, i figured i could just >> > look for the existence of a 'parts' key in the message array, assuming >> > that attachments would be represented by a multi-part message.  but >> > apparently, there are carrier gateways out there that will construct >> > multi-part messages even for simple text messages. >> > >> >  so i'm sure there are numerous ways to do this but is there a >> > canonical way to check if a mime-decoded email has a non-text >> > attachment?  thanks. > >> This should be what you need. >> >> >> http://pear.php.net/manual/en/package.mail.mail-mimedecode.decode.php >> >> Return value >> object - >> >> array $return->headers - an associative array of the headers. The keys >> of the array are the header names (lowercased) whilst the values are >> the header values (original case). If there are multiple headers with >> the same name (eg. Received: ) then the value is a numerically indexed >> array of each of the header values. If the parameter decode_headers is >> specified as TRUE, the headers will be decoded according to RFC 2047. >> >> string $return->ctype_primary - the first part of the content type >> (ie. before the forward slash). Eg. if the content type is >> multipart/mixed , ctype_primary would be "multipart" . >> >> string $return->ctype_secondary - the second part of the content type. >> Eg. If the content type is multipart/mixed , ctype_secondary would be >> "mixed" . > >  i'm actually using that very package -- i was just wondering if > there was a fundamental query about whether there was a non-text > attachment, but i can see that it's my job to query the various > content types and figure that out.  should be easy, thanks. > > rday > -- > > ======================================================================== > Robert P. J. Day                               Waterloo, Ontario, CANADA > >            Linux Consulting, Training and Kernel Pedantry. > > Web page:                                         >  http://crashcourse.ca > Twitter:                                       > http://twitter.com/rpjday > ======================================================================== Considering that in most cases the attachments will arrive as base64 encoded data, at first glance, they are all text. Also, it is entirely possible that a binary attachment could be comprised entirely of 7bit ASCII characters. The EICAR test virus is a contrived/perfect example. A text file which can run as a binary (when renamed accordingly). So, the mime type is probably all you have to work off that is in any way accurate. BTW. X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H* is the text. Save this as test.com on a windows machine and it will run. Or trigger an alert in your AV software. http://www.eicar.org/anti_virus_test_file.htm Richard. -- ----- Richard Quadling "Standing on the shoulders of some very clever giants!" EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling

« previous php.pear.general (#30432) next »