Hi,
I made a funstion that checks a mail account, retrieves and stores the
attachments in a folder on my website.
This works great for .doc files but not for .pdf files.
I am almost sure the problem is in: $fileContent =
imap_base64($fi leContent);
Whet is the encoding for PDF attachments ?
Can someone help me with this.
Best Regards,
JAKE, Belgium
This is the script (copied the function in a standalone script, the only
thing this does is open pop account, check messages, store attachments,
close imap connection):
<?php
$login = 'mypoplogin';
$password = 'mypoppassword' ;
$mbox = imap_open("{127 .0.0.1:110/pop3/notls}INBOX", "$login", "$password" )
or die("Could not open Mailbox - try again later!");
//
// make connection with mailbox and check # messages
if ($hdr = imap_check($mbo x)) {
echo "Num Messages " . $hdr->Nmsgs ."\n\n<br><br>" ;
$msgCount = $hdr->Nmsgs;
} else { echo "failed"; }
$overview=imap_ fetch_overview( $mbox,"1:$msgCo unt",0);
$size=sizeof($o verview);
// get message info
for($i=$size-1;$i>=0;$i--)
{
$val=$overview[$i];
$msg=$val->msgno;
$from=$val->from;
$date=$val->date;
$subj=$val->subject;
$seen=$val->seen;
$from = ereg_replace("\ "","",$from );
// Check for attachements and store them
$struct = imap_fetchstruc ture($mbox,$msg );
$contentParts = count($struct->parts);
if ($contentParts >= 2) {
for ($ix=2;$ix<=$co ntentParts;$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(s trrev($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(s trrev($FileName[$k]),0,4));
$fileContent = imap_fetchbody( $mbox,$msg,$fil e+2);
$fileContent = imap_base64($fi leContent);
$localfile = fopen("/var/www/html/storedattachmen ts/$FileName[$k]","w");
fputs($localfil e,$fileContent) ;
fclose($localfi le);
}
}
}
}
imap_close($mbo x);
?>
I made a funstion that checks a mail account, retrieves and stores the
attachments in a folder on my website.
This works great for .doc files but not for .pdf files.
I am almost sure the problem is in: $fileContent =
imap_base64($fi leContent);
Whet is the encoding for PDF attachments ?
Can someone help me with this.
Best Regards,
JAKE, Belgium
This is the script (copied the function in a standalone script, the only
thing this does is open pop account, check messages, store attachments,
close imap connection):
<?php
$login = 'mypoplogin';
$password = 'mypoppassword' ;
$mbox = imap_open("{127 .0.0.1:110/pop3/notls}INBOX", "$login", "$password" )
or die("Could not open Mailbox - try again later!");
//
// make connection with mailbox and check # messages
if ($hdr = imap_check($mbo x)) {
echo "Num Messages " . $hdr->Nmsgs ."\n\n<br><br>" ;
$msgCount = $hdr->Nmsgs;
} else { echo "failed"; }
$overview=imap_ fetch_overview( $mbox,"1:$msgCo unt",0);
$size=sizeof($o verview);
// get message info
for($i=$size-1;$i>=0;$i--)
{
$val=$overview[$i];
$msg=$val->msgno;
$from=$val->from;
$date=$val->date;
$subj=$val->subject;
$seen=$val->seen;
$from = ereg_replace("\ "","",$from );
// Check for attachements and store them
$struct = imap_fetchstruc ture($mbox,$msg );
$contentParts = count($struct->parts);
if ($contentParts >= 2) {
for ($ix=2;$ix<=$co ntentParts;$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(s trrev($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(s trrev($FileName[$k]),0,4));
$fileContent = imap_fetchbody( $mbox,$msg,$fil e+2);
$fileContent = imap_base64($fi leContent);
$localfile = fopen("/var/www/html/storedattachmen ts/$FileName[$k]","w");
fputs($localfil e,$fileContent) ;
fclose($localfi le);
}
}
}
}
imap_close($mbo x);
?>
Comment