Hallo,
Ik wil met een PHP script een mailbox controleren en de attachments
automatisch laten opslaan in een directory zodat deze beschikbaar zijn
voor de gebruikers (een soort archief).
Het lukt goed met .doc bestanden (met imap_base64) doch de .pdf files
geven een encoded error. Iemand die raad weet ?
Dit is mijn php code:
--------------------
$login = 'mailboxlogin';
$password = 'mailboxpass';
$mbox = imap_open("{127.0.0.1:110/pop3/notls}INBOX", "$login", "$password")
or die("Could not open Mailbox - try again later!");
$hdr = imap_check($mbox);
$msgCount = $hdr->Nmsgs;
$overview=imap_fetch_overview($mbox,"1:$msgCount", 0);
$size=sizeof($overview);
for($i=$size-1;$i>=0;$i--)
{
$val=$overview[$i];
$msg=$val->msgno;
$date=$val->date;
$subj=$val->subject;
$struct = imap_fetchstructure($mbox,$msg);
$contentParts = count($struct->parts);
if ($contentParts >= 2) {
for ($ix=2;$ix<=$contentParts;$ix++) {
$att[$ix-2] = imap_bodystruct($mbox,$msg,$ix);
}
for ($k=0;$k<sizeof($att);$k++) {
if ($att[$k]->parameters[0]->value == "us-ascii" ||
$att[$k]->parameters[0]->value == "US-ASCII") {
if ($att[$k]->parameters[1]->value != "") {
$FileName[$k] = $att[$k]->parameters[1]->value;
$FileType[$k] = strrev(substr(strrev($FileName[$k]),0,4));
}
} elseif ($att[$k]->parameters[0]->value != "iso-8859-1" &&
$att[$k]->parameters[0]->value != "ISO-8859-1") {
$FileName[$k] = $att[$k]->parameters[0]->value;
$FileType[$k] = strrev(substr(strrev($FileName[$k]),0,4));
$fileContent = imap_fetchbody($mbox,$msg,$file+2);
$fileContent = imap_base64($fileContent);
$localfile = fopen("/var/www/bestanden/$FileName[$k]","w");
fputs($localfile,$fileContent);
fclose($localfile);
}
}
}
}
imap_close($mbox);

Likes:

Quote