imap attachments

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rhosk
Forum Commoner
Posts: 30
Joined: Sun Oct 31, 2004 12:00 pm
Location: Maine, USA

imap attachments

Post 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.
rhosk
Forum Commoner
Posts: 30
Joined: Sun Oct 31, 2004 12:00 pm
Location: Maine, USA

Post by rhosk »

Anyone?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
rhosk
Forum Commoner
Posts: 30
Joined: Sun Oct 31, 2004 12:00 pm
Location: Maine, USA

Post 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.
Post Reply