Re: [PHP] Re: Imap and attachments

2005-03-11 Thread Evert | Rooftop Solutions
Jim Plush wrote:
here is a script I use to get jpg attachments with IMAP.. good luck
?php
[snip]
 

Thanx Jim,
Unfortunaly some e-mail clients send the headers in ways the 
imap-functions can't read. So I figured something out using regular 
expressions. If anyone needs this, mail me (in total it's a big script, 
so I won't post it here)

grt,
Evert
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Imap and attachments

2005-03-10 Thread Jim Plush
here is a script I use to get jpg attachments with IMAP.. good luck

?php
//--+-- ---+-- --  -
# view the contents of an array in html format
#---  -+-

// return the email account of the user so we can assign it to a user
account
function get_phone_address($i)
{
 global $mbox;
 $header=imap_header($mbox,$i);
 echo 'FROM: '.$header-from[0]-mailbox.@.$header-from[0]-host.'BR';
 return $header-from[0]-mailbox.@.$header-from[0]-host;

}

function get_structure($mbox,$i)
{
$structure = imap_fetchstructure($mbox, $i);
return $structure;
}

function no_attachments($structure)
{
global $mbox;
$attach = sizeof($structure-parts); //# OF ATTACHMENTS
echo 'BRBR'.$attach.' attachments BR';
return $attach;
}

function get_attached_file($structure, $username, $k,$i)
{
global $mbox;
$encoding = $structure-parts[$k]-encoding;
$Name = strtolower($structure-parts[$k]-dparameters[0]-value);
//$NewFile[$k-1] = $Name;
echo $Name.'BR';
if(strstr($Name, '.jpg')  !strstr($Name, 'masthead.jpg'))
{
 echo 'In File LoopBR';
 $File = base64_decode(imap_fetchbody($mbox, $i, $k+1));

 $fp = fopen(C:/TEMP/.$username.$Name ,w+);
 fwrite ($fp, $File, 1);
 fclose($fp);
}
 return $Name;
}
/*

**

**
*/
// CONNECT TO IMAP SERVER
$mbox = imap_open({mail.myserver.net:143}INBOX, USERNAME, PASSWORD);

if($mbox)
{
 echo 'CONNECTED TO INBOX...BR';
}

$error = imap_errors();
$alerts = imap_alerts();
/*

**

**
*/

$msg_cnt = imap_num_msg($mbox);
htm($msg_cnt);

for($msg_num=1; $msg_num=$msg_cnt; $msg_num++)
{
 $structure = get_structure($mbox, $msg_num);

 $num_attach = no_attachments($structure);

 $phone_address = get_phone_address($msg_num);
 //get_attached_file($structure,1,1);

 for($i=0; $i$num_attach; $i++)
 {
  get_attached_file($structure, 'jim_', $i, $msg_num);
 }


}





imap_close($mbox);

print_r($error);
print_r($alerts);

?









Evert | Rooftop Solutions [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Hi,

 I started using the IMAP functions and ran into a problem with some
 headers for attachments.

 The first one is:

 Content-type: image/psd; x-unix-mode=0644; name=FinalVersion6.psd
 Content-transfer-encoding: base64
 Content-disposition: inline; filename=FinalVersion6.psd

 Generated by Mac Mail. The filename wont show up in the result of for
example imap_fetchstructure.

 The second is:

 Content-Type: text/plain
 Content-Disposition: attachment;
 filename=Video(019).3gp
 Content-Transfer-Encoding: base64

 I suspect this one has something to do with the linebreak. It's generated
by a modern nokia (7650 I think)


 I additionaly found a problem calling imap_fetchbody with a non-existent
msg number. This will result in a segfault.

 grt,
 Evert


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php