Vault fixed enough. Still has a nasty error sometimes that I cant figure out. Will come back to it

This commit is contained in:
Karl Cordes 2009-06-30 15:35:07 +10:00
parent 38e512a4bb
commit 9b671b11a6

View file

@ -31,6 +31,7 @@ class VaultShell extends Shell {
echo "Number of messages to Process ".$number_of_messages."\n"; echo "Number of messages to Process ".$number_of_messages."\n";
/* Loop through the messages and sort them into ones to be processed or discarded */ /* Loop through the messages and sort them into ones to be processed or discarded */
for ($i=1; $i <= $number_of_messages; $i++) { for ($i=1; $i <= $number_of_messages; $i++) {
echo "Checking msg number $i\n";
$this_header = imap_headerinfo($mbox, $i); $this_header = imap_headerinfo($mbox, $i);
$message = $this->getMessage($mbox, $i, $this_header); $message = $this->getMessage($mbox, $i, $this_header);
$enquiry = $this->checkIfValidEnquiry($message['subject'], $testing); $enquiry = $this->checkIfValidEnquiry($message['subject'], $testing);
@ -77,7 +78,7 @@ class VaultShell extends Shell {
} }
//Sanitize::clean($this->data); //Sanitize::clean($this->data);
if( ($this->data['Email']['body'] != "") || ($this->data['Email']['plainbody'] != "") ) { if( ($this->data['Email']['body'] != "") || ($this->data['Email']['plainbody'] != "") || ($attachments != 1) ) {
if($this->Email->save($this->data)) { if($this->Email->save($this->data)) {
$email_id = $this->Email->id; $email_id = $this->Email->id;
@ -100,7 +101,7 @@ class VaultShell extends Shell {
echo "Something went wrong saving the file to the DB\n"; echo "Something went wrong saving the file to the DB\n";
} }
} }
unlink($email_dir.'/'.$attachment['name']); #Delete this attachment now we're done with it. //unlink($email_dir.'/'.$attachment['name']); #Delete this attachment now we're done with it.
} }
} }
} }
@ -112,15 +113,14 @@ class VaultShell extends Shell {
if($attachments != 1) { // if($attachments != 1) {
//$this->clearEmailAttachmentDirs($email_dir, $temp_filename, $attachments); // $this->clearEmailAttachmentDirs($email_dir, $temp_filename, $attachments);
unlink($email_dir.'/'.$temp_filename); #remove the temp email. start again //unlink($email_dir.'/'.$temp_filename); #remove the temp email. start again
} // }
} }
else { else {
echo 'Unable to save the Email\n'; echo 'Unable to save the Email\n';
} }
@ -145,7 +145,11 @@ class VaultShell extends Shell {
} }
} }
}
$this->rmdirr($email_dir); //delete all attachments from the working directory. Easiest way to stop random files persisting
}
/* Finished working with the IMAP server. Make the changes and close the connection */ /* Finished working with the IMAP server. Make the changes and close the connection */
imap_expunge($mbox); imap_expunge($mbox);
imap_close($mbox); imap_close($mbox);
@ -165,7 +169,6 @@ function fetchBodyAttachments($mailbox, $msg_number, $filename, $email_dir) {
imap_savebody($mailbox, $email_file, $msg_number); imap_savebody($mailbox, $email_file, $msg_number);
$command = "/usr/local/bin/ripmime -i $email_file -d $email_dir -v --verbose-contenttype --paranoid --prefix $msg_number"; $command = "/usr/local/bin/ripmime -i $email_file -d $email_dir -v --verbose-contenttype --paranoid --prefix $msg_number";
// $command = "/usr/local/bin/ripmime -i $email_file -d $email_dir --verbose-contenttype --paranoid --prefix $msg_number";
$output = array(); $output = array();
exec($command, $output, $status); exec($command, $output, $status);
@ -291,6 +294,43 @@ function checkIfValidEnquiry($subject, $testing) {
} }
}
/**
* Delete a file, or a folder and its contents (recursive algorithm)
*
* @author Aidan Lister <aidan@php.net>
* @version 1.0.3
* @link http://aidanlister.com/repos/v/function.rmdirr.php
* @param string $dirname Directory to delete
* @return bool Returns TRUE on success, FALSE on failure
*/
function rmdirr($dirname)
{
// Sanity check
if (!file_exists($dirname)) {
return false;
}
// Simple delete for a file
if (is_file($dirname) || is_link($dirname)) {
return unlink($dirname);
}
// Loop through the folder
$dir = dir($dirname);
while (false !== $entry = $dir->read()) {
// Skip pointers
if ($entry == '.' || $entry == '..') {
continue;
}
// Recurse
$this->rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);
}
// Clean up
$dir->close();
return; //removing the last recursion - should remove the deletion of the last directory I hope. Lazy hack using this but should work
//rmdir($dirname);
}
}
?> ?>