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

From: Date: Thu, 01 Apr 2010 11:20:48 +0000
Subject: Re: 'Mail/mimeDecode': how can i identify attachments?
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-30431@lists.php.net to get a copy of this message
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 ========================================================================

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