Refactoring the vault
This commit is contained in:
parent
bbb547199d
commit
643d5c1a1d
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -9,3 +9,4 @@ tmp/*
|
|||
*.swp
|
||||
*.swo
|
||||
vendors/tcpdf/cache/*
|
||||
tests/*
|
||||
|
|
|
|||
0
controllers/documents_controller.php
Normal file → Executable file
0
controllers/documents_controller.php
Normal file → Executable file
0
controllers/invoices_controller.php
Normal file → Executable file
0
controllers/invoices_controller.php
Normal file → Executable file
0
controllers/issue_actions_controller.php
Normal file → Executable file
0
controllers/issue_actions_controller.php
Normal file → Executable file
0
controllers/issues_controller.php
Normal file → Executable file
0
controllers/issues_controller.php
Normal file → Executable file
0
controllers/jobs_controller.php
Normal file → Executable file
0
controllers/jobs_controller.php
Normal file → Executable file
0
controllers/line_items_controller.php
Normal file → Executable file
0
controllers/line_items_controller.php
Normal file → Executable file
0
controllers/pages_controller.php
Normal file → Executable file
0
controllers/pages_controller.php
Normal file → Executable file
0
controllers/purchase_orders_controller.php
Normal file → Executable file
0
controllers/purchase_orders_controller.php
Normal file → Executable file
0
models/document.php
Normal file → Executable file
0
models/document.php
Normal file → Executable file
0
models/invoice.php
Normal file → Executable file
0
models/invoice.php
Normal file → Executable file
0
models/job.php
Normal file → Executable file
0
models/job.php
Normal file → Executable file
0
models/line_item.php
Normal file → Executable file
0
models/line_item.php
Normal file → Executable file
0
models/page.php
Normal file → Executable file
0
models/page.php
Normal file → Executable file
0
models/purchase_order.php
Normal file → Executable file
0
models/purchase_order.php
Normal file → Executable file
|
|
@ -1,13 +1,12 @@
|
|||
<?php
|
||||
class User extends AppModel {
|
||||
|
||||
var $name = 'User';
|
||||
|
||||
var $belongsTo = array('Group');
|
||||
var $name = 'User';
|
||||
|
||||
var $displayField = 'username';
|
||||
|
||||
/* TO DO: Fix up this validation stuff
|
||||
var $displayField = 'username';
|
||||
|
||||
/* TO DO: Fix up this validation stuff
|
||||
var $validate = array(
|
||||
'username' => array(
|
||||
'rule' => 'unique',
|
||||
|
|
@ -19,41 +18,35 @@ class User extends AppModel {
|
|||
'email' => array('email'),
|
||||
// 'job_title' => array('custom')
|
||||
);
|
||||
*/
|
||||
//The Associations below have been created with all possible keys, those that are not needed can be removed
|
||||
var $hasMany = array(
|
||||
'Enquiry' => array('className' => 'Enquiry',
|
||||
'foreignKey' => 'user_id',
|
||||
'dependent' => false,
|
||||
'conditions' => '',
|
||||
'fields' => '',
|
||||
'order' => '',
|
||||
'limit' => '',
|
||||
'offset' => '',
|
||||
'exclusive' => '',
|
||||
'finderQuery' => '',
|
||||
'counterQuery' => ''
|
||||
)
|
||||
);
|
||||
*/
|
||||
//The Associations below have been created with all possible keys, those that are not needed can be removed
|
||||
var $hasMany = array(
|
||||
'Enquiry' => array('className' => 'Enquiry',
|
||||
'foreignKey' => 'user_id',
|
||||
'dependent' => false,
|
||||
'conditions' => '',
|
||||
'fields' => '',
|
||||
'order' => '',
|
||||
'limit' => '',
|
||||
'offset' => '',
|
||||
'exclusive' => '',
|
||||
'finderQuery' => '',
|
||||
'counterQuery' => ''
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
var $actsAs = array('Acl' => array('requester'));
|
||||
var $belongsTo = array(
|
||||
'Principle' => array('className'=>'Principle',
|
||||
'foreignKey' =>'principle_id',
|
||||
|
||||
),
|
||||
'Customer' => array('className'=>'Customer',
|
||||
'foreignKey' =>'customer_id',
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
function parentNode() {
|
||||
if (!$this->id && empty($this->data)) {
|
||||
return null;
|
||||
}
|
||||
$data = $this->data;
|
||||
if (empty($this->data)) {
|
||||
$data = $this->read();
|
||||
}
|
||||
if (!$data['User']['group_id']) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return array('Group' => array('id' => $data['User']['group_id']));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
0
vendors/shells/firstpass.php
vendored
Normal file → Executable file
0
vendors/shells/firstpass.php
vendored
Normal file → Executable file
52
vendors/shells/users_migrate.php
vendored
Normal file → Executable file
52
vendors/shells/users_migrate.php
vendored
Normal file → Executable file
|
|
@ -24,8 +24,56 @@ class UsersMigrateShell extends Shell {
|
|||
$this->printCountLine($usersCount, 'Users');
|
||||
|
||||
$totalCount = $principleContactsCount + $contactsCount + $usersCount;
|
||||
$this->printCountLine($totalCount, 'Total Users after migration');
|
||||
|
||||
$this->printCountLine($totalCount, 'Total Users we should have after migration');
|
||||
|
||||
$principleContacts = $this->PrincipleContact->find('all');
|
||||
$newPrincipleUsers = array();
|
||||
foreach($principleContacts as $contact) {
|
||||
$newUser = array();
|
||||
|
||||
$newUser['User']['principle_id'] = $contact['PrincipleContact']['principle_id'];
|
||||
$newUser['User']['type'] = 'principle';
|
||||
$newUser['User']['username'] = trim($contact['PrincipleContact']['first_name']).' '.trim($contact['PrincipleContact']['last_name']);
|
||||
$newUser['User']['first_name'] = $contact['PrincipleContact']['first_name'];
|
||||
$newUser['User']['last_name'] = $contact['PrincipleContact']['last_name'];
|
||||
$newUser['User']['email'] = $contact['PrincipleContact']['email'];
|
||||
$newUser['User']['phone'] = $contact['PrincipleContact']['phone'];
|
||||
$newUser['User']['fax'] = $contact['PrincipleContact']['fax'];
|
||||
$newUser['User']['notes'] = $contact['PrincipleContact']['notes'];
|
||||
$newUser['User']['job_title'] = $contact['PrincipleContact']['job_title'];
|
||||
$this->User->create();
|
||||
//$newPrincipleUsers[] = $newUser;
|
||||
$this->User->save($newUser);
|
||||
}
|
||||
|
||||
$customerContacts = $this->Contact->find('all');
|
||||
$newCustomerUsers = array();
|
||||
foreach($customerContacts as $contact) {
|
||||
$newUser = array();
|
||||
|
||||
$newUser['User']['customer_id'] = $contact['Contact']['customer_id'];
|
||||
$newUser['User']['type'] = 'contact';
|
||||
$newUser['User']['username'] = trim($contact['Contact']['first_name']).' '.trim($contact['Contact']['last_name']);
|
||||
$newUser['User']['first_name'] = $contact['Contact']['first_name'];
|
||||
$newUser['User']['last_name'] = $contact['Contact']['last_name'];
|
||||
$newUser['User']['email'] = $contact['Contact']['email'];
|
||||
$newUser['User']['phone'] = $contact['Contact']['phone'];
|
||||
$newUser['User']['fax'] = $contact['Contact']['fax'];
|
||||
$newUser['User']['notes'] = $contact['Contact']['notes'];
|
||||
$newUser['User']['job_title'] = $contact['Contact']['job_title'];
|
||||
$newUser['User']['phone_extension'] = $contact['Contact']['phone_extension'];
|
||||
$newUser['User']['direct_phone'] = $contact['Contact']['direct_phone'];
|
||||
$this->User->create();
|
||||
//$newPrincipleUsers[] = $newUser;
|
||||
$this->User->save($newUser);
|
||||
}
|
||||
$newCount = $this->User->find('count');
|
||||
$this->printCountLine($newCount, 'Now have Total Users after migration');
|
||||
|
||||
//print_r($newPrincipleUsers);
|
||||
|
||||
//$this->User->save($newPrincipleUsers);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
542
vendors/shells/vault.php
vendored
542
vendors/shells/vault.php
vendored
|
|
@ -5,215 +5,215 @@ class VaultShell extends Shell {
|
|||
* then loads the data into the 'emails' table and the attachments in the 'email_attachments' table.
|
||||
* Emails are discared or moved to a subfolder once processed
|
||||
*/
|
||||
|
||||
|
||||
var $uses = array('Enquiry', 'Email', 'EmailAttachment');
|
||||
|
||||
function main() {
|
||||
|
||||
/******************************************************
|
||||
/******************************************************
|
||||
* Config Variables
|
||||
* *****************************************************/
|
||||
$testing = 1; //Whether to actually move the emails. 1=test, 0=production
|
||||
/* Setup Connection to the IMAP server */
|
||||
$username = 'vault';
|
||||
$password = 'xjdYOsmJWc37'; /* The password for the account to be checked */
|
||||
$email_dir = '/var/www/cakephp/app/emails';
|
||||
$testing = 1; //Whether to actually move the emails. 1=test, 0=production
|
||||
/* Setup Connection to the IMAP server */
|
||||
$username = 'vault';
|
||||
$password = 'xjdYOsmJWc37'; /* The password for the account to be checked */
|
||||
$email_dir = '/var/www/cakephp/app/emails';
|
||||
|
||||
|
||||
|
||||
$ripmime_path = '/usr/local/bin/ripmime';
|
||||
$ripmime_path = '/usr/local/bin/ripmime';
|
||||
|
||||
|
||||
if($testing == 1) {
|
||||
$email_dir = '/Users/karlcordes/Sites/quotenik/app/emails';
|
||||
$ripmime_path = '/opt/local/bin/ripmime';
|
||||
$mbox = imap_open("{192.168.0.8:143}INBOX", $username, $password) or die("can't connect: " . imap_last_error());
|
||||
}
|
||||
else {
|
||||
$mbox = imap_open("{192.168.0.8:143/novalidate-cert}INBOX", $username, $password) or die("can't connect: " . imap_last_error());
|
||||
}
|
||||
if($testing == 1) {
|
||||
$email_dir = '/Users/karlcordes/Sites/quotenik/app/emails';
|
||||
$ripmime_path = '/opt/local/bin/ripmime';
|
||||
$mbox = imap_open("{192.168.0.8:143}INBOX", $username, $password) or die("can't connect: " . imap_last_error());
|
||||
}
|
||||
else {
|
||||
$mbox = imap_open("{192.168.0.8:143/novalidate-cert}INBOX", $username, $password) or die("can't connect: " . imap_last_error());
|
||||
}
|
||||
|
||||
|
||||
|
||||
$MC = imap_check($mbox);
|
||||
$number_of_messages = $MC->Nmsgs;
|
||||
$MC = imap_check($mbox);
|
||||
$number_of_messages = $MC->Nmsgs;
|
||||
|
||||
echo "Number of messages to Process ".$number_of_messages."\n";
|
||||
echo "Number of messages to Process ".$number_of_messages."\n";
|
||||
|
||||
if($number_of_messages == 0) {
|
||||
exit(0);
|
||||
}
|
||||
if($number_of_messages == 0) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$enquiries = $this->Enquiry->find('all', array('recursive'=>0,'fields' => array('Enquiry.title', 'Enquiry.id')));
|
||||
$enquiries = $this->Enquiry->find('all', array('recursive'=>0,'fields' => array('Enquiry.title', 'Enquiry.id')));
|
||||
|
||||
|
||||
|
||||
foreach ($enquiries as $enq) {
|
||||
$enqNumber = $enq['Enquiry']['title'];
|
||||
$id = $enq['Enquiry']['id'];
|
||||
$enquiryList[$enqNumber] = $id;
|
||||
}
|
||||
foreach ($enquiries as $enq) {
|
||||
$enqNumber = $enq['Enquiry']['title'];
|
||||
$id = $enq['Enquiry']['id'];
|
||||
$enquiryList[$enqNumber] = $id;
|
||||
}
|
||||
|
||||
$storedArray = array();
|
||||
$discardArray = array();
|
||||
$storedArray = array();
|
||||
$discardArray = array();
|
||||
|
||||
|
||||
//exit(0);
|
||||
//exit(0);
|
||||
|
||||
|
||||
/* Loop through the messages and sort them into ones to be processed or discarded */
|
||||
|
||||
|
||||
for($i=1; $i <= $number_of_messages; $i++) {
|
||||
$this_header = imap_headerinfo($mbox, $i);
|
||||
$message = $this->getMessage($mbox, $i, $this_header);
|
||||
|
||||
//echo "Checking msg number: $i\tSubject: ".$message['subject']."\n";
|
||||
echo "Checking msg number: $i\n";
|
||||
|
||||
$enqID = $this->checkIfValidEnquiry($message['subject'], $enquiryList);
|
||||
/* Loop through the messages and sort them into ones to be processed or discarded */
|
||||
|
||||
|
||||
if($enqID != false) {
|
||||
echo "Found Message with enquiry ID: ".$enqID." Processing.\n";
|
||||
//Process it and store the message and its attachments.
|
||||
for($i=1; $i <= $number_of_messages; $i++) {
|
||||
$this_header = imap_headerinfo($mbox, $i);
|
||||
$message = $this->getMessage($mbox, $i, $this_header);
|
||||
|
||||
//Generate a Uniqid for this email.
|
||||
// $uniqid = $this->getUniqId($email_dir);
|
||||
//echo "Checking msg number: $i\tSubject: ".$message['subject']."\n";
|
||||
echo "Checking msg number: $i\n";
|
||||
|
||||
$this->Email->create();
|
||||
$this->data['Email']['enquiry_id'] = $enqID;
|
||||
$this->data['Email']['to'] = $message['to'];
|
||||
$this->data['Email']['cc'] = $message['cc'];
|
||||
$this->data['Email']['from'] = $message['from'];
|
||||
$this->data['Email']['date'] = $message['date'];
|
||||
$this->data['Email']['subject'] = $message['subject'];
|
||||
$this->data['Email']['body'] = "";
|
||||
$this->data['Email']['plainbody'] = "";
|
||||
|
||||
$structure = imap_fetchstructure($mbox, $i);
|
||||
$attachments = 1;
|
||||
if (empty($structure->parts)) { /* A single part message. No attachments and is plain text */
|
||||
$this->data['Email']['body'] = imap_body($mbox, $i);
|
||||
}
|
||||
else {
|
||||
$attachments = $this->fetchBodyAttachments($mbox, $i, $email_dir, $uniqid, $ripmime_path);
|
||||
if($attachments != 1) {
|
||||
foreach ($attachments as $attachment) {
|
||||
if($attachment['type'] == 'text/html') { //Assuming All HTML attachments are the body of the email
|
||||
if(file_exists($email_dir.'/'.$uniqid.'/'.$attachment['name'])) {
|
||||
$filecontents = file_get_contents($email_dir.'/'.$attachment['name']);
|
||||
$size = filesize($email_dir.'/'.$attachment['name']);
|
||||
$this->data['Email']['body'] .= $filecontents;
|
||||
}
|
||||
|
||||
}
|
||||
if($attachment['type'] == 'text/plain') { //Found plain text
|
||||
if(file_exists($email_dir.'/'.$attachment['name'])) {
|
||||
$filecontents = file_get_contents($email_dir.'/'.$attachment['name']);
|
||||
$size = filesize($email_dir.'/'.$attachment['name']);
|
||||
$this->data['Email']['plainbody'] .= $filecontents;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
$enqID = $this->checkIfValidEnquiry($message['subject'], $enquiryList);
|
||||
|
||||
|
||||
if( ($this->data['Email']['body'] != "") || ($this->data['Email']['plainbody'] != "") || ($attachments != 1) ) {
|
||||
if($enqID != false) {
|
||||
echo "Found Message with enquiry ID: ".$enqID." Processing.\n";
|
||||
//Process it and store the message and its attachments.
|
||||
|
||||
if($this->Email->save($this->data)) {
|
||||
$email_id = $this->Email->id;
|
||||
if($attachments != 1) {
|
||||
foreach ($attachments as $attachment) {
|
||||
if(file_exists($email_dir.'/'.$attachment['name']) != FALSE) {
|
||||
//Generate a Uniqid for this email.
|
||||
// $uniqid = $this->getUniqId($email_dir);
|
||||
|
||||
if( ($attachment['type'] != 'text/html') && ($attachment['type'] != 'multipart/mixed') &&
|
||||
($attachment['type'] != 'multipart/alternative') &&
|
||||
($attachment['type'] != 'multipart/report') &&
|
||||
($attachment['type'] != 'text/plain') &&
|
||||
($attachment['type'] != 'text/rfc822-headers') &&
|
||||
($attachment['type'] != 'message/delivery-status')
|
||||
$this->Email->create();
|
||||
$this->data['Email']['enquiry_id'] = $enqID;
|
||||
$this->data['Email']['to'] = $message['to'];
|
||||
$this->data['Email']['cc'] = $message['cc'];
|
||||
$this->data['Email']['from'] = $message['from'];
|
||||
$this->data['Email']['date'] = $message['date'];
|
||||
$this->data['Email']['subject'] = $message['subject'];
|
||||
$this->data['Email']['body'] = "";
|
||||
$this->data['Email']['plainbody'] = "";
|
||||
|
||||
$structure = imap_fetchstructure($mbox, $i);
|
||||
$attachments = 1;
|
||||
if (empty($structure->parts)) { /* A single part message. No attachments and is plain text */
|
||||
$this->data['Email']['body'] = imap_body($mbox, $i);
|
||||
}
|
||||
else {
|
||||
$attachments = $this->fetchBodyAttachments($mbox, $i, $email_dir, $uniqid, $ripmime_path);
|
||||
if($attachments != 1) {
|
||||
foreach ($attachments as $attachment) {
|
||||
if($attachment['type'] == 'text/html') { //Assuming All HTML attachments are the body of the email
|
||||
if(file_exists($email_dir.'/'.$uniqid.'/'.$attachment['name'])) {
|
||||
$filecontents = file_get_contents($email_dir.'/'.$attachment['name']);
|
||||
$size = filesize($email_dir.'/'.$attachment['name']);
|
||||
$this->data['Email']['body'] .= $filecontents;
|
||||
}
|
||||
|
||||
}
|
||||
if($attachment['type'] == 'text/plain') { //Found plain text
|
||||
if(file_exists($email_dir.'/'.$attachment['name'])) {
|
||||
$filecontents = file_get_contents($email_dir.'/'.$attachment['name']);
|
||||
$size = filesize($email_dir.'/'.$attachment['name']);
|
||||
$this->data['Email']['plainbody'] .= $filecontents;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
) {
|
||||
$this->EmailAttachment->create();
|
||||
$this->data['EmailAttachment']['email_id'] = $email_id;
|
||||
$this->data['EmailAttachment']['name'] = $attachment['name'];
|
||||
$this->data['EmailAttachment']['type'] = $attachment['type'];
|
||||
$this->data['EmailAttachment']['size'] = filesize($email_dir.'/'.$attachment['name']);
|
||||
$this->data['EmailAttachment']['filename'] = $email_dir.'/'.$attachment['name'];
|
||||
if ($this->EmailAttachment->save($this->data)) {
|
||||
echo "Saved file successfully to database\n";
|
||||
}
|
||||
else {
|
||||
echo "Error saving the file to the DB\n";
|
||||
}
|
||||
}
|
||||
if( ($this->data['Email']['body'] != "") || ($this->data['Email']['plainbody'] != "") || ($attachments != 1) ) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
echo "Email stored in the DB under enquiry ID".$enqID." Message will now be deleted\n";
|
||||
if($this->Email->save($this->data)) {
|
||||
$email_id = $this->Email->id;
|
||||
if($attachments != 1) {
|
||||
foreach ($attachments as $attachment) {
|
||||
if(file_exists($email_dir.'/'.$attachment['name']) != FALSE) {
|
||||
|
||||
//$storedArray[] = $i;
|
||||
if( ($attachment['type'] != 'text/html') && ($attachment['type'] != 'multipart/mixed') &&
|
||||
($attachment['type'] != 'multipart/alternative') &&
|
||||
($attachment['type'] != 'multipart/report') &&
|
||||
($attachment['type'] != 'text/plain') &&
|
||||
($attachment['type'] != 'text/rfc822-headers') &&
|
||||
($attachment['type'] != 'message/delivery-status')
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
echo 'Unable to save the Email\n';
|
||||
}
|
||||
} else {
|
||||
echo "Unable to find either HTML or Plaintext body to this email. Ignoring it";
|
||||
}
|
||||
} else {
|
||||
/* Can't find a valid-looking CMC Enquiry Number. Move the message to the discarded folder
|
||||
) {
|
||||
$this->EmailAttachment->create();
|
||||
$this->data['EmailAttachment']['email_id'] = $email_id;
|
||||
$this->data['EmailAttachment']['name'] = $attachment['name'];
|
||||
$this->data['EmailAttachment']['type'] = $attachment['type'];
|
||||
$this->data['EmailAttachment']['size'] = filesize($email_dir.'/'.$attachment['name']);
|
||||
$this->data['EmailAttachment']['filename'] = $email_dir.'/'.$attachment['name'];
|
||||
if ($this->EmailAttachment->save($this->data)) {
|
||||
echo "Saved file successfully to database\n";
|
||||
}
|
||||
else {
|
||||
echo "Error saving the file to the DB\n";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
echo "Email stored in the DB under enquiry ID".$enqID." Message will now be deleted\n";
|
||||
|
||||
//$storedArray[] = $i;
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
echo 'Unable to save the Email\n';
|
||||
}
|
||||
} else {
|
||||
echo "Unable to find either HTML or Plaintext body to this email. Ignoring it";
|
||||
}
|
||||
} else {
|
||||
/* Can't find a valid-looking CMC Enquiry Number. Move the message to the discarded folder
|
||||
* I may change this to simply delete the emails. This will do for now, but it's doubling up on the storage for useless files.
|
||||
* */
|
||||
|
||||
// $discardArray[] = $i;
|
||||
// $discardArray[] = $i;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* 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 */
|
||||
|
||||
//if($testing == 0) {
|
||||
//if($testing == 0) {
|
||||
|
||||
|
||||
|
||||
echo "Tidying up now. Moving messages to Stored or Discarded\n";
|
||||
echo "Tidying up now. Moving messages to Stored or Discarded\n";
|
||||
|
||||
|
||||
reset($discardArray);
|
||||
reset($storedArray);
|
||||
reset($discardArray);
|
||||
reset($storedArray);
|
||||
|
||||
$numberToStore = count($storedArray);
|
||||
$numberToDiscard= count($discardArray);
|
||||
$numberToStore = count($storedArray);
|
||||
$numberToDiscard= count($discardArray);
|
||||
|
||||
|
||||
if($numberToStore > 0) {
|
||||
echo "Got $numberToStore messages to store\n";
|
||||
$storeSet = implode(",", $storedArray);
|
||||
imap_mail_move($mbox, $storeSet, 'INBOX/Stored');
|
||||
}
|
||||
if($numberToStore > 0) {
|
||||
echo "Got $numberToStore messages to store\n";
|
||||
$storeSet = implode(",", $storedArray);
|
||||
imap_mail_move($mbox, $storeSet, 'INBOX/Stored');
|
||||
}
|
||||
|
||||
if($numberToDiscard > 0) {
|
||||
echo "Going to discard $numberToDiscard messages\n";
|
||||
$discardSet = implode(",",$discardArray);
|
||||
if($numberToDiscard > 0) {
|
||||
echo "Going to discard $numberToDiscard messages\n";
|
||||
$discardSet = implode(",",$discardArray);
|
||||
|
||||
imap_mail_move($mbox, $discardSet, 'INBOX/Discarded');
|
||||
}
|
||||
imap_mail_move($mbox, $discardSet, 'INBOX/Discarded');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -222,10 +222,10 @@ class VaultShell extends Shell {
|
|||
|
||||
|
||||
|
||||
//}
|
||||
//}
|
||||
|
||||
imap_expunge($mbox);
|
||||
imap_close($mbox);
|
||||
imap_expunge($mbox);
|
||||
imap_close($mbox);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -239,137 +239,197 @@ class VaultShell extends Shell {
|
|||
|
||||
|
||||
|
||||
$email_file = $email_dir.'/'.$uniqid.'.eml';
|
||||
imap_savebody($mailbox, $email_file, $msg_number);
|
||||
$command = "$ripmime_path -i $email_file -d $email_dir --prefix --paranoid -v --verbose-contenttype";
|
||||
$email_file = $email_dir.'/'.$uniqid.'.eml';
|
||||
imap_savebody($mailbox, $email_file, $msg_number);
|
||||
$command = "$ripmime_path -i $email_file -d $email_dir --prefix --paranoid -v --verbose-contenttype";
|
||||
|
||||
$output = array();
|
||||
exec($command, $output, $status);
|
||||
$output = array();
|
||||
exec($command, $output, $status);
|
||||
|
||||
/* Check the $output array and find the filenames of the attachments */
|
||||
/* Check the $output array and find the filenames of the attachments */
|
||||
|
||||
if($status == 0) {
|
||||
$attachments = array();
|
||||
if($status == 0) {
|
||||
$attachments = array();
|
||||
|
||||
for($i=0, $j=0; $i< count($output); $i++, $j++) {
|
||||
$words = explode(' ', $output[$i]);
|
||||
$type = explode('=', $words[1]);
|
||||
$name = explode('=', $words[2]);
|
||||
for($i=0, $j=0; $i< count($output); $i++, $j++) {
|
||||
$words = explode(' ', $output[$i]);
|
||||
$type = explode('=', $words[1]);
|
||||
$name = explode('=', $words[2]);
|
||||
|
||||
if($type[1] == "" || $name[1] == "") {
|
||||
continue;
|
||||
}
|
||||
if($type[1] == "" || $name[1] == "") {
|
||||
continue;
|
||||
}
|
||||
|
||||
$attachments[$j]['type'] = $type[1];
|
||||
$attachments[$j]['name'] = $name[1];
|
||||
//echo "in message number $msg_number ($uniqid): found attachment ".$attachments[$j]['name'].' '.$attachments[$j]['type']."\n";
|
||||
}
|
||||
unlink($email_file);
|
||||
return $attachments;
|
||||
$attachments[$j]['type'] = $type[1];
|
||||
$attachments[$j]['name'] = $name[1];
|
||||
//echo "in message number $msg_number ($uniqid): found attachment ".$attachments[$j]['name'].' '.$attachments[$j]['type']."\n";
|
||||
}
|
||||
unlink($email_file);
|
||||
return $attachments;
|
||||
|
||||
}
|
||||
else {
|
||||
unlink($email_file);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
unlink($email_file);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getMessage($mbox, $msgnumber, $headers) {
|
||||
|
||||
$subject = $headers->subject;
|
||||
//$subject = iconv_mime_decode($subject, 0, "ISO-8859-1//IGNORE");
|
||||
// $subject = mb_convert_encoding($subject, "ISO-8859-1");
|
||||
// $subject = mb_convert_encoding($subject, "UTF-8");
|
||||
$subject = mb_decode_mimeheader($subject);
|
||||
$subject = $headers->subject;
|
||||
//$subject = iconv_mime_decode($subject, 0, "ISO-8859-1//IGNORE");
|
||||
// $subject = mb_convert_encoding($subject, "ISO-8859-1");
|
||||
// $subject = mb_convert_encoding($subject, "UTF-8");
|
||||
$subject = mb_decode_mimeheader($subject);
|
||||
|
||||
$date = $headers->date;
|
||||
$recipients = $this->getRecipients($headers);
|
||||
$message['subject'] = $subject;
|
||||
$message['date'] = $date;
|
||||
$message['to'] = $recipients['to'];
|
||||
$message['from'] = $recipients['from'];
|
||||
$message['cc'] = $recipients['cc'];
|
||||
return $message;
|
||||
$date = $headers->date;
|
||||
$recipients = $this->getRecipients($headers);
|
||||
$message['subject'] = $subject;
|
||||
$message['date'] = $date;
|
||||
$message['to'] = $recipients['to'];
|
||||
$message['from'] = $recipients['from'];
|
||||
$message['cc'] = $recipients['cc'];
|
||||
return $message;
|
||||
|
||||
}
|
||||
/* get Recipients from the headers of an email */
|
||||
function getRecipients($headers) {
|
||||
|
||||
$recipients = array();
|
||||
$recipients['to'] = "";
|
||||
$recipients['from'] = "";
|
||||
$recipients['cc'] = "";
|
||||
$recipients = array();
|
||||
$recipients['to'] = "";
|
||||
$recipients['from'] = "";
|
||||
$recipients['cc'] = "";
|
||||
|
||||
if(isset($headers->to)) {
|
||||
$to = $headers->to;
|
||||
if(count($to) > 0) {
|
||||
foreach ($to as $id => $object) {
|
||||
$recipients['to'] .= "$object->mailbox@$object->host ";
|
||||
}
|
||||
}
|
||||
}
|
||||
if(isset($headers->cc)) {
|
||||
$cc = $headers->cc;
|
||||
if(count($cc) > 0) {
|
||||
foreach ($cc as $id => $object) {
|
||||
$recipients['cc'] .= "$object->mailbox@$object->host ";
|
||||
}
|
||||
if(isset($headers->to)) {
|
||||
$to = $headers->to;
|
||||
if(count($to) > 0) {
|
||||
foreach ($to as $id => $object) {
|
||||
$recipients['to'] .= "$object->mailbox@$object->host ";
|
||||
}
|
||||
}
|
||||
}
|
||||
if(isset($headers->cc)) {
|
||||
$cc = $headers->cc;
|
||||
if(count($cc) > 0) {
|
||||
foreach ($cc as $id => $object) {
|
||||
$recipients['cc'] .= "$object->mailbox@$object->host ";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($headers->from)) {
|
||||
$from = $headers->from;
|
||||
if(count($from) > 0) {
|
||||
foreach ($from as $id => $object) {
|
||||
$recipients['from'] .= "$object->mailbox@$object->host";
|
||||
}
|
||||
}
|
||||
}
|
||||
if(isset($headers->from)) {
|
||||
$from = $headers->from;
|
||||
if(count($from) > 0) {
|
||||
foreach ($from as $id => $object) {
|
||||
$recipients['from'] .= "$object->mailbox@$object->host";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $recipients;
|
||||
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;
|
||||
$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 checkIfValidEnquiry($subject, &$enqList) {
|
||||
$subject = iconv_mime_decode($subject, 0, "ISO-8859-1");
|
||||
$subject = iconv_mime_decode($subject, 0, "ISO-8859-1");
|
||||
|
||||
$output = array();
|
||||
$output = array();
|
||||
// $decoded_subject = iconv_mime_decode($subject, 2, "ISO-8859-1");
|
||||
|
||||
preg_match("/CMC\d+([NVQWSOT]|ACT|NT)E\d+-\d+/", $subject, $output);
|
||||
preg_match("/CMC\d+([NVQWSOT]|ACT|NT)E\d+-\d+/", $subject, $output);
|
||||
|
||||
|
||||
if(isset($output[0])) { //Found a valid-looking Enquiry Number
|
||||
$fetched_enquirynumber = $output[0];
|
||||
if(isset($output[0])) { //Found a valid-looking Enquiry Number
|
||||
$fetched_enquirynumber = $output[0];
|
||||
|
||||
if(array_key_exists($fetched_enquirynumber, $enqList)) { //check if it actually exists.
|
||||
$enqid = $enqList[$fetched_enquirynumber];
|
||||
if(array_key_exists($fetched_enquirynumber, $enqList)) { //check if it actually exists.
|
||||
$enqid = $enqList[$fetched_enquirynumber];
|
||||
|
||||
return $enqid;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
return $enqid;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapted from
|
||||
* http://www.electrictoolbox.com/function-extract-email-attachments-php-imap/
|
||||
* @param <type> $connection
|
||||
* @param <type> $message_number
|
||||
* @return <type>
|
||||
*/
|
||||
function extract_attachments($connection, $message_number) {
|
||||
|
||||
$attachments = array();
|
||||
$structure = imap_fetchstructure($connection, $message_number);
|
||||
|
||||
if(isset($structure->parts) && count($structure->parts)) {
|
||||
|
||||
for($i = 0; $i < count($structure->parts); $i++) {
|
||||
|
||||
$attachments[$i] = array(
|
||||
'is_attachment' => false,
|
||||
'filename' => '',
|
||||
'name' => '',
|
||||
'attachment' => ''
|
||||
);
|
||||
|
||||
if($structure->parts[$i]->ifparameters) {
|
||||
foreach($structure->parts[$i]->dparameters as $object) {
|
||||
if(strtolower($object->attribute) == 'filename') {
|
||||
$attachments[$i]['is_attachment'] = true;
|
||||
$attachments[$i]['filename'] = $object->value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($structure->parts[$i]->ifparameters) {
|
||||
foreach($structure->parts[$i]->parameters as $object) {
|
||||
if(strtolower($object->attribute) == 'name') {
|
||||
$attachments[$i]['is_attachment'] = true;
|
||||
$attachments[$i]['name'] = $object->value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($attachments[$i]['is_attachment']) {
|
||||
$attachments[$i]['attachment'] = imap_fetchbody($connection, $message_number, $i+1);
|
||||
if($structure->parts[$i]->encoding == 3) { // 3 = BASE64
|
||||
$attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);
|
||||
}
|
||||
elseif($structure->parts[$i]->encoding == 4) { // 4 = QUOTED-PRINTABLE
|
||||
$attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $attachments;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
0
vendors/shells/vault_two.php
vendored
Normal file → Executable file
0
vendors/shells/vault_two.php
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/classtrees_com-tecnick-tcpdf.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/classtrees_com-tecnick-tcpdf.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/com-tecnick-tcpdf/TCPDF.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/com-tecnick-tcpdf/TCPDF.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/com-tecnick-tcpdf/TCPDFBarcode.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/com-tecnick-tcpdf/TCPDFBarcode.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/com-tecnick-tcpdf/_barcodes.php.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/com-tecnick-tcpdf/_barcodes.php.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/com-tecnick-tcpdf/_config---tcpdf_config.php.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/com-tecnick-tcpdf/_config---tcpdf_config.php.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/com-tecnick-tcpdf/_htmlcolors.php.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/com-tecnick-tcpdf/_htmlcolors.php.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/com-tecnick-tcpdf/_tcpdf.php.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/com-tecnick-tcpdf/_tcpdf.php.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/com-tecnick-tcpdf/_unicode_data.php.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/com-tecnick-tcpdf/_unicode_data.php.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/elementindex.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/elementindex.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/elementindex_com-tecnick-tcpdf.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/elementindex_com-tecnick-tcpdf.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/errors.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/errors.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/index.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/index.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/li_com-tecnick-tcpdf.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/li_com-tecnick-tcpdf.html
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/media/background.png
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/media/background.png
vendored
Normal file → Executable file
|
Before Width: | Height: | Size: 238 B After Width: | Height: | Size: 238 B |
0
vendors/tcpdf/doc/media/empty.png
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/media/empty.png
vendored
Normal file → Executable file
|
Before Width: | Height: | Size: 206 B After Width: | Height: | Size: 206 B |
0
vendors/tcpdf/doc/media/style.css
vendored
Normal file → Executable file
0
vendors/tcpdf/doc/media/style.css
vendored
Normal file → Executable file
0
vendors/xfpdi.php
vendored
Normal file → Executable file
0
vendors/xfpdi.php
vendored
Normal file → Executable file
0
views/countries/complete_country.ctp
Normal file → Executable file
0
views/countries/complete_country.ctp
Normal file → Executable file
0
views/currencies/jsonlist.ctp
Normal file → Executable file
0
views/currencies/jsonlist.ctp
Normal file → Executable file
0
views/customers/csv.ctp
Normal file → Executable file
0
views/customers/csv.ctp
Normal file → Executable file
0
views/customers/similar_customers.ctp
Normal file → Executable file
0
views/customers/similar_customers.ctp
Normal file → Executable file
0
views/documents/add.ctp
Normal file → Executable file
0
views/documents/add.ctp
Normal file → Executable file
0
views/documents/edit.ctp
Normal file → Executable file
0
views/documents/edit.ctp
Normal file → Executable file
0
views/documents/index.ctp
Normal file → Executable file
0
views/documents/index.ctp
Normal file → Executable file
0
views/documents/view.ctp
Normal file → Executable file
0
views/documents/view.ctp
Normal file → Executable file
0
views/documents/viewDEFAULT.ctp
Normal file → Executable file
0
views/documents/viewDEFAULT.ctp
Normal file → Executable file
0
views/elements/info_table.ctp
Normal file → Executable file
0
views/elements/info_table.ctp
Normal file → Executable file
0
views/elements/isEmptyDate.ctp
Normal file → Executable file
0
views/elements/isEmptyDate.ctp
Normal file → Executable file
0
views/elements/issue_priority_select.ctp
Normal file → Executable file
0
views/elements/issue_priority_select.ctp
Normal file → Executable file
0
views/enquiries/do_search.ctp
Normal file → Executable file
0
views/enquiries/do_search.ctp
Normal file → Executable file
0
views/enquiries/search.ctp
Normal file → Executable file
0
views/enquiries/search.ctp
Normal file → Executable file
0
views/invoices/add.ctp
Normal file → Executable file
0
views/invoices/add.ctp
Normal file → Executable file
0
views/invoices/edit.ctp
Normal file → Executable file
0
views/invoices/edit.ctp
Normal file → Executable file
0
views/invoices/index.ctp
Normal file → Executable file
0
views/invoices/index.ctp
Normal file → Executable file
0
views/invoices/view.ctp
Normal file → Executable file
0
views/invoices/view.ctp
Normal file → Executable file
0
views/jobs/add.ctp
Normal file → Executable file
0
views/jobs/add.ctp
Normal file → Executable file
0
views/jobs/edit.ctp
Normal file → Executable file
0
views/jobs/edit.ctp
Normal file → Executable file
0
views/jobs/index.ctp
Normal file → Executable file
0
views/jobs/index.ctp
Normal file → Executable file
0
views/jobs/view.ctp
Normal file → Executable file
0
views/jobs/view.ctp
Normal file → Executable file
0
views/layouts/csv.ctp
Normal file → Executable file
0
views/layouts/csv.ctp
Normal file → Executable file
0
views/line_items/view_table.ctp
Normal file → Executable file
0
views/line_items/view_table.ctp
Normal file → Executable file
0
views/pages/add.ctp
Normal file → Executable file
0
views/pages/add.ctp
Normal file → Executable file
0
views/pages/edit.ctp
Normal file → Executable file
0
views/pages/edit.ctp
Normal file → Executable file
0
views/pages/index.ctp
Normal file → Executable file
0
views/pages/index.ctp
Normal file → Executable file
0
views/pages/view.ctp
Normal file → Executable file
0
views/pages/view.ctp
Normal file → Executable file
0
views/products/.LCKindex.ctp~
Normal file → Executable file
0
views/products/.LCKindex.ctp~
Normal file → Executable file
0
views/products/get_principle_products.ctp
Normal file → Executable file
0
views/products/get_principle_products.ctp
Normal file → Executable file
0
views/products/get_product_options.ctp
Normal file → Executable file
0
views/products/get_product_options.ctp
Normal file → Executable file
0
views/products/view_principle.ctp
Normal file → Executable file
0
views/products/view_principle.ctp
Normal file → Executable file
0
views/purchase_orders/add.ctp
Normal file → Executable file
0
views/purchase_orders/add.ctp
Normal file → Executable file
0
views/purchase_orders/edit.ctp
Normal file → Executable file
0
views/purchase_orders/edit.ctp
Normal file → Executable file
0
views/purchase_orders/index.ctp
Normal file → Executable file
0
views/purchase_orders/index.ctp
Normal file → Executable file
0
views/purchase_orders/view.ctp
Normal file → Executable file
0
views/purchase_orders/view.ctp
Normal file → Executable file
0
views/quotes/ajaxpdf.ctp
Normal file → Executable file
0
views/quotes/ajaxpdf.ctp
Normal file → Executable file
0
views/statuses/status_list.ctp
Normal file → Executable file
0
views/statuses/status_list.ctp
Normal file → Executable file
0
webroot/js/addLineItem.js
Normal file → Executable file
0
webroot/js/addLineItem.js
Normal file → Executable file
0
webroot/js/add_costing.js
Normal file → Executable file
0
webroot/js/add_costing.js
Normal file → Executable file
0
webroot/js/addjob.js
Normal file → Executable file
0
webroot/js/addjob.js
Normal file → Executable file
0
webroot/js/addpurchaseorder.js
Normal file → Executable file
0
webroot/js/addpurchaseorder.js
Normal file → Executable file
0
webroot/js/autocomplete-customer.js
Normal file → Executable file
0
webroot/js/autocomplete-customer.js
Normal file → Executable file
0
webroot/js/costing_dialog.js
Normal file → Executable file
0
webroot/js/costing_dialog.js
Normal file → Executable file
0
webroot/js/editLineItem.js
Normal file → Executable file
0
webroot/js/editLineItem.js
Normal file → Executable file
0
webroot/js/email_table.js
Normal file → Executable file
0
webroot/js/email_table.js
Normal file → Executable file
0
webroot/js/enquiry_table.js
Normal file → Executable file
0
webroot/js/enquiry_table.js
Normal file → Executable file
0
webroot/js/findcustomer.js
Normal file → Executable file
0
webroot/js/findcustomer.js
Normal file → Executable file
0
webroot/js/globalsearch.js
Normal file → Executable file
0
webroot/js/globalsearch.js
Normal file → Executable file
0
webroot/js/jobindex.js
Normal file → Executable file
0
webroot/js/jobindex.js
Normal file → Executable file
0
webroot/js/jquery.form.js
Normal file → Executable file
0
webroot/js/jquery.form.js
Normal file → Executable file
0
webroot/js/jquery.jeditable.mini.js
Normal file → Executable file
0
webroot/js/jquery.jeditable.mini.js
Normal file → Executable file
0
webroot/js/jquery.validate.min.js
vendored
Normal file → Executable file
0
webroot/js/jquery.validate.min.js
vendored
Normal file → Executable file
0
webroot/js/lineItemPriceNoCosting.js
Normal file → Executable file
0
webroot/js/lineItemPriceNoCosting.js
Normal file → Executable file
0
webroot/js/menu.js
Normal file → Executable file
0
webroot/js/menu.js
Normal file → Executable file
0
webroot/js/product-model-number-builder.js
Normal file → Executable file
0
webroot/js/product-model-number-builder.js
Normal file → Executable file
0
webroot/js/search.js
Normal file → Executable file
0
webroot/js/search.js
Normal file → Executable file
Loading…
Reference in a new issue