* Centralise the attachment deleting code into the Message class
[squirrelmail.git] / class / mime / Message.class.php
index 1e516d54dfdea766557479f9e4e499a4bec0fc04..4a82be71a7fbf20484e1a4d8db4d1226cf0efeb4 100644 (file)
@@ -1056,6 +1056,20 @@ class Message {
         $attachment->mime_header = $mime_header;
         $this->entities[]=$attachment;
     }
+
+    /**
+     * Delete all attachments from this object from disk.
+     * @since 1.5.1
+     */
+    function purgeAttachments() {
+        if ($this->att_local_name && file_exists($this->att_local_name)) {
+            unlink($this->att_local_name);
+        }
+        // recursively delete attachments from entities contained in this object
+        for ($i=0, $entCount=count($this->entities);$i< $entCount; ++$i) {
+            $this->entities[$i]->purgeAttachments();
+        }
+    }
 }
 
-?>
\ No newline at end of file
+?>