+ /**
+ * Add attachment to message object
+ * @param string $type attachment type
+ * @param string $name attachment name
+ * @param string $location path to attachment
+ */
+ function initAttachment($type, $name, $location) {
+ $attachment = new Message();
+ $mime_header = new MessageHeader();
+ $mime_header->setParameter('name', $name);
+ // FIXME: duplicate code. see ContentType class
+ $pos = strpos($type, '/');
+ if ($pos > 0) {
+ $mime_header->type0 = substr($type, 0, $pos);
+ $mime_header->type1 = substr($type, $pos+1);
+ } else {
+ $mime_header->type0 = $type;
+ }
+ $attachment->att_local_name = $location;
+ $disposition = new Disposition('attachment');
+ $disposition->properties['filename'] = $name;
+ $mime_header->disposition = $disposition;
+ $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();
+ }
+ }
+}