diff --git a/vendors/shells/vault.php b/vendors/shells/vault.php index 48daaf43..d1346fe7 100644 --- a/vendors/shells/vault.php +++ b/vendors/shells/vault.php @@ -7,7 +7,7 @@ class VaultShell extends Shell { */ - var $uses = array('Enquiry', 'Email', 'EmailAttachments'); + var $uses = array('Enquiry', 'Email', 'EmailAttachment'); function main() { @@ -47,6 +47,7 @@ class VaultShell extends Shell { $this->data['Email']['from'] = $message['from']; $this->data['Email']['date'] = $message['date']; $this->data['Email']['subject'] = $message['subject']; + $this->data['Email']['body'] = $message['body']; //Sanitize::clean($this->data); @@ -70,7 +71,8 @@ class VaultShell extends Shell { } echo "Email stored in the DB under enquiry ".$enquiry['Enquiry']['title']." Will be moved to the stored folder\n"; - $this->clearEmailAttachmentDirs($email_dir, $temp_filename, $attachment_dir, $attachments); + imap_mail_move($mbox, $i, 'INBOX/Stored'); //Move it to the stored folder. + $this->clearEmailAttachmentDirs($email_dir, $temp_filename, $attachment_dir, $attachment_files); } else { echo 'Unable to save the Email\n'; @@ -155,60 +157,91 @@ function getMessage($mbox, $msgnumber, $headers) { $subject = $headers->subject; $date = $headers->date; $recipients = $this->getRecipients($headers); - $message['subject'] = $subject; + $message['subject'] = Sanitize::paranoid($subject, array(' ', '@')); $message['date'] = $date; $message['to'] = $recipients['to']; $message['from'] = $recipients['from']; $message['cc'] = $recipients['cc']; - $message['body'] = imap_fetchbody($mbox, $msgnumber, '1'); + + + $message['body'] = $this->getBody($mbox, $msgnumber); return $message; } /* get Recipients from the headers of an email */ function getRecipients($headers) { - $to = $headers->to; - $cc = $headers->cc; - $from = $headers->from; -$recipients = array(); - if(count($to) > 0) { + $recipients = array(); + $recipients['to'] = ""; + $recipients['from'] = ""; + $recipients['cc'] = ""; + + if(isset($headers->to)) { + $to = $headers->to; + if(count($to) > 0) { foreach ($to as $id => $object) { - if(isset($object->personal)) { - $recipients['to'] .= "$object->personal $object->mailbox@$object->host "; - } - else { - $recipients['to'] .= "$object->mailbox@$object->host "; + $recipients['to'] .= "$object->mailbox@$object->host "; } } } - - if(count($cc) > 0) { + if(isset($headers->cc)) { + $cc = $headers->cc; + if(count($cc) > 0) { foreach ($cc as $id => $object) { - if(isset($object->personal)) { - $recipients['cc'] .= "$object->personal $object->mailbox@$object->host "; - } - else { $recipients['cc'] .= "$object->mailbox@$object->host "; } + } } - if(count($from) > 0) { + if(isset($headers->from)) { + $from = $headers->from; + if(count($from) > 0) { foreach ($from as $id => $object) { - if(isset($object->personal)) { - $recipients['from'] .= "$object->personal $object->mailbox@$object->host"; - } - else { $recipients['from'] .= "$object->mailbox@$object->host"; } } } + + + return $recipients; } +function getBody($mbox, $msgnumber) { + $structure = imap_fetchstructure($mbox, $msgnumber); + if (!empty($structure->parts)) { + $body = $this->getParts($structure->parts, $mbox, $msgnumber); + } + else { + $body = imap_body($mbox, $msgnumber); /* Or get the plaintext */ + } + return $body; +} +function getParts($parts, $mbox, $msgnumber) { + for ($i = 0, $j = count($parts); $i < $j; $i++) { + $part = $parts[$i]; + + + if ($part->subtype == 'HTML') { /* Find the HTML component of the body */ + $body = imap_fetchbody($mbox, $msgnumber, $i+1); + return $body; + } + elseif($part->subtype == 'PLAIN') { + $body = imap_fetchbody($mbox, $msgnumber, $i+1); + return $body; + } + elseif(isset($part->parts)) { + $body = $this->getParts($part->parts, $mbox, $msgnumber); /* Handle these goddamn Outlook messages */ + return $body; + } + } + + +}