Added (slow) firstpass to try and cull these damned messages
This commit is contained in:
parent
6e7febb93f
commit
ec17513933
143
vendors/shells/firstpass.php
vendored
Normal file
143
vendors/shells/firstpass.php
vendored
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* file: firstpass.php
|
||||
*
|
||||
* Scan through a (long) list of emails, marking ones that don't have a CMC technologies enquiry number
|
||||
* in the subject for deletion.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class FirstpassShell extends Shell {
|
||||
|
||||
|
||||
var $uses = array('Enquiry');
|
||||
|
||||
|
||||
function main() {
|
||||
|
||||
|
||||
$username = 'vault';
|
||||
$password = 'xjdYOsmJWc37'; /* The password for the account to be checked */
|
||||
|
||||
$testing = 0;
|
||||
|
||||
if($testing == 1) {
|
||||
|
||||
$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;
|
||||
|
||||
echo "Number of messages to Process ".$number_of_messages."\n";
|
||||
|
||||
if($number_of_messages == 0) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
for($i=1; $i <= $number_of_messages; $i++) {
|
||||
//for($i=1; $i <= 50; $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);
|
||||
|
||||
if($enqID == false) {
|
||||
echo "Deleting msg number: $i\tSubject: ".$message['subject']."\n";
|
||||
imap_delete($mbox, $i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
echo "Tidying up now.\n";
|
||||
|
||||
imap_expunge($mbox);
|
||||
imap_close($mbox);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function checkIfValidEnquiry($subject, &$enqList) {
|
||||
$subject = iconv_mime_decode($subject, 0, "ISO-8859-1");
|
||||
|
||||
$output = array();
|
||||
// $decoded_subject = iconv_mime_decode($subject, 2, "ISO-8859-1");
|
||||
|
||||
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];
|
||||
|
||||
echo "'$fetched_enquirynumber'\n";
|
||||
|
||||
if(array_key_exists($fetched_enquirynumber, $enqList)) { //check if it actually exists.
|
||||
$enqid = $enqList[$fetched_enquirynumber];
|
||||
|
||||
return $enqid;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
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);
|
||||
|
||||
$date = $headers->date;
|
||||
|
||||
$message['subject'] = $subject;
|
||||
|
||||
return $message;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
4
vendors/shells/vault.php
vendored
4
vendors/shells/vault.php
vendored
|
|
@ -160,7 +160,7 @@ class VaultShell extends Shell {
|
|||
}
|
||||
echo "Email stored in the DB under enquiry ID".$enqID." Will be moved to the stored folder\n";
|
||||
|
||||
$storedArray[] = $i;
|
||||
//$storedArray[] = $i;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -175,7 +175,7 @@ class VaultShell extends Shell {
|
|||
* 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;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
echo $javascript->link('jquery-ui');
|
||||
echo $javascript->link('jquery.form');
|
||||
echo $javascript->link('menu');
|
||||
echo $javascript->link('search');
|
||||
echo $javascript->link('ckeditor/adapters/jquery');
|
||||
|
||||
echo $scripts_for_layout;
|
||||
|
|
@ -106,7 +107,7 @@
|
|||
</li>*/
|
||||
?>
|
||||
|
||||
<li><?php echo $html->link('Search', '/enquiries/search'); ?>
|
||||
<li><?php echo $html->link('Search', '/enquiries/search', array('id'=>'searchLink')); ?>
|
||||
</li>
|
||||
<li><?php echo $html->link('Help', '/pages/help'); ?>
|
||||
<ul>
|
||||
|
|
@ -140,6 +141,35 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="dialogDiv">
|
||||
|
||||
|
||||
|
||||
<?php echo $form->create('Enquiry', array('default'=>false));
|
||||
echo '<h2>Search';
|
||||
echo $html->image('system-search.png');
|
||||
echo '</h2>';
|
||||
echo "<p>Enter part of an Enquiry Number, Customer Name or Contact Name</p>";
|
||||
echo $form->input('Enquiry.search_string', array('label'=>false, 'id'=>'searchString'));
|
||||
|
||||
//echo $form->input('Customer.id', array('type'=>'hidden'));
|
||||
|
||||
//echo $form->end('Search');
|
||||
|
||||
?>
|
||||
|
||||
<div class ="ui-widget">
|
||||
<button id="searchButton">Search</button>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<div id="results"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<?php
|
||||
$mem_usage = memory_get_usage(true);
|
||||
|
||||
|
|
|
|||
|
|
@ -69,7 +69,6 @@ h1 {
|
|||
margin: 0.1em 0;
|
||||
}
|
||||
h2 {
|
||||
background:#fff;
|
||||
color: #e32;
|
||||
font-family:'Gill Sans','lucida grande',helvetica, arial, sans-serif;
|
||||
font-size: 190%;
|
||||
|
|
|
|||
|
|
@ -7,13 +7,35 @@
|
|||
*/
|
||||
|
||||
$(function() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$("#dialogDiv").hide();
|
||||
|
||||
|
||||
|
||||
$("#dialogDiv").dialog({
|
||||
autoOpen: false,
|
||||
height: 800,
|
||||
|
||||
modal: true
|
||||
|
||||
});
|
||||
|
||||
|
||||
$("#searchLink").click(function() {
|
||||
|
||||
$("#dialogDiv").dialog('open');
|
||||
return false;
|
||||
});
|
||||
|
||||
$("#searchButton").button().click(function() {
|
||||
|
||||
doSearch();
|
||||
return false;
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
|
@ -31,5 +53,8 @@ function doSearch() {
|
|||
}
|
||||
|
||||
|
||||
function searchDialog() {
|
||||
$("")
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue