Page 1 of 1

imap attachments

Posted: Wed Jul 12, 2006 6:46 am
by rhosk
Can someone look at this and let me know why - if there's more than one attachment in the email, it duplicates the saved file ?? Single attachments work perfect.

Code: Select all

$mbox = imap_open("{localhost:110/pop3}INBOX", "$login", "$password")
or die("Could not open Mailbox - try again later!");
//
// make connection with mailbox and check # messages
if ($hdr = imap_check($mbox)) {
echo "Num Messages " . $hdr->Nmsgs ."\n\n<br><br>";
$msgCount = $hdr->Nmsgs;
} else { echo "failed"; }
$overview=imap_fetch_overview($mbox,"1:$msgCount",0);
$size=sizeof($overview);

// 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_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("images/$FileName[$k]","w");
fputs($localfile,$fileContent);
fclose($localfile);
}
}
}
}
imap_close($mbox);
Thanks.

Posted: Wed Jul 12, 2006 9:35 am
by rhosk
Anyone?

Posted: Wed Jul 12, 2006 9:37 am
by JayBird
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:4. All users of any level are restricted to bumping (as defined here) any given thread within twenty-four (24) hours of its last post. Non-trivial posts are not considered bumping. A bump post found in violation will be deleted, and you may or may not recieve a warning. Persons bumping excessively be considered as spammers and dealt with accordingly.
Consider this a warning

Posted: Wed Jul 12, 2006 3:29 pm
by rhosk
Pimp wrote:Persons bumping excessively be considered as spammers and dealt with accordingly.
You may want to consider fixing your "Forum Rules" as it contains poor english. Thanks for all the help.