Login   Register  
PHP Classes
elePHPant
Icontem

Possible to unlink SaveBody messages from disk ?

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      MIME E-mail message parser  >  All threads  >  Possible to unlink SaveBody messages from disk ?  >  (Un) Subscribe thread alerts  
Subject:Possible to unlink SaveBody messages from disk ?
Summary:how to get uniqueID to unlink saved message
Messages:16
Author:Pontus Lundin
Date:2013-01-12 06:24:54
Update:2013-01-18 02:06:22
 
  1 - 10   11 - 16  

  1. Possible to unlink SaveBody messages from disk ?   Reply   Report abuse  
Picture of Pontus Lundin
Pontus Lundin
2013-01-12 06:24:54
Hi! This is a great class.

I am using the SaveBody option for saving attachments and the body (the message in plain text). How can i within my script unlink/remove the message file (i cant retrive the unique ID?!) so it doesnt take up to much space (i am inserting it into a db instead)

So basically i only want the SaveBody function to store the attachments not the message itself.

Also, do you have any tip on best production method to save messages on disk, like a folder structure of year/month/day/uniqueID.

Thank you

  2. Re: Possible to unlink SaveBody messages from disk ?   Reply   Report abuse  
Picture of Manuel Lemos
Manuel Lemos
2013-01-12 10:55:11 - In reply to message 1 from Pontus Lundin
Just use the PHP unlink function to remove files.

The best way you store your message depends on what are your purposes. It is hard to suggest anything without knowing what you will do later with the message parts.

  3. Re: Possible to unlink SaveBody messages from disk ?   Reply   Report abuse  
Picture of Pontus Lundin
Pontus Lundin
2013-01-12 20:32:03 - In reply to message 2 from Manuel Lemos
Manuel thank you, but what variable holds the filename to unlink it?

  4. Re: Possible to unlink SaveBody messages from disk ?   Reply   Report abuse  
Picture of Pontus Lundin
Pontus Lundin
2013-01-12 23:15:04 - In reply to message 2 from Manuel Lemos
Another question i have is if i have a dynamic path on the SaveBody with mkdir it will (in my linux distro) be set as owner 'Nobody'. I can see that the message and attachments gets saved in this folder but now i am unable to get body parts (it works if i just dump everything into one folder).

$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 8024);
}
fclose($fd);

//create the email parser class
$mime=new mime_parser_class;
$mime->ignore_syntax_errors = 1;
$parameters=array(
'Data'=>$email,
'SaveBody'=>$filenamepath //dynamic path
);

$mime->Decode($parameters, $decoded);

From here i seem to not get the message body and parts within the script and insert into the db. Why? Isnt in memory ? How can that change becuase i have another folder structure.

  5. Re: Possible to unlink SaveBody messages from disk ?   Reply   Report abuse  
Picture of Manuel Lemos
Manuel Lemos
2013-01-12 23:27:42 - In reply to message 3 from Pontus Lundin
When you use the SaveBody parameter, the decoded message structure contains the file names of each decoded message part. Those are the file names you need to unlink when no longer needed.

  6. Re: Possible to unlink SaveBody messages from disk ?   Reply   Report abuse  
Picture of Pontus Lundin
Pontus Lundin
2013-01-13 04:56:28 - In reply to message 5 from Manuel Lemos
I am sorry manuel but i am unable to find where you store it in the decoded array. I have modifed your script so the parts gets a random name rather than 1 2 3 etc (this below stores file 1 ,randomName, randomattachmentfileName)

if ($filename!='1'){
$path .= rand().$filename;
}else{
$path .=$filename;
}
if(!($this->body_file = fopen($path, 'wb')))
return($this->SetPHPError('could not create file '.$path.' to save the message body part', $php_errormsg));
$decoded['BodyFile'] = $path;
$decoded['BodyPart'] = $this->body_part_number;
$decoded['BodyLength'] = 0;
$this->body_part_number++;
}

So like for attachment, i can find the name

foreach($decoded[0]['Parts'] as $part){
$counter++;
//check for attachments
if($part['FileDisposition'] == 'attachment'){

}

from here i can find the name of the attachment file(s) by exploding
$filenamarray = explode("/", $part['BodyFile']);
$filename=$filenamearray[7];

But i cant find what the actual message (normally refered to 1) is stored.

  7. Re: Possible to unlink SaveBody messages from disk ?   Reply   Report abuse  
Picture of Manuel Lemos
Manuel Lemos
2013-01-13 08:27:51 - In reply to message 3 from Pontus Lundin
It is always good that you read the documentation because it is all explained there.

http://www.phpclasses.org/browse/file/14673.html

As you may see the decode function returns an array that will the BodyFile element set to the path of the part file when you used the SaveBody option.

  8. Re: Possible to unlink SaveBody messages from disk ?   Reply   Report abuse  
Picture of Manuel Lemos
Manuel Lemos
2013-01-13 09:01:39 - In reply to message 4 from Pontus Lundin
The directory that you specify to save body parts must be writable by the user that runs the script. Otherwise the Decode function will fail to decode the message.

You always have to check if the return value of the Decode function is 1. When it is not 1 you need check the class error variable to see if what was the error, so you can fix your script to avoid it.

  9. Re: Possible to unlink SaveBody messages from disk ?   Reply   Report abuse  
Picture of Manuel Lemos
Manuel Lemos
2013-01-13 09:06:05 - In reply to message 6 from Pontus Lundin
That is probably because the Decode message is failing with an error, maybe due to not being able to write to the directory specified in the SaveBody parameter.

  10. Re: Possible to unlink SaveBody messages from disk ?   Reply   Report abuse  
Picture of Pontus Lundin
Pontus Lundin
2013-01-16 00:46:22 - In reply to message 7 from Manuel Lemos
Thanks Manuel,

However can you confirm that BodyFile will contain the filename for each part if SaveBody is on.

Becuause, if i run this:

foreach($decoded[0]['Parts'] as $part){
$thefilename=$thefilename.$part['BodyFile'];
}

it will upon not having attachment return the two paths for plain text and html message file (file 1 and 2). If i however is adding an attachment only the path for the attachment is in bodyfile.

Shouldn't i still be able to get all three names ? (normally refered to file 1 2 3 ?)

 
  1 - 10   11 - 16