Hello and thanks for taking the time to respond. I see my info was to vague.
Basically, this program grabs emails... removes all unimportant material for our purposes and sends the rest of the contents to a specified folder as a text file.
If the file (the contents of the email says "photo msg replies" it -- should-- put that text file into the -- photo msg-- folder on our server (unfortunately it does not
if the file (the contents of the email says "expired...." it should put the text file into the expired folder again unfortuantely it does not.
However it does seem to put files that say facebook into the facebook folder.
Supplying more content removing the private info Thank You for taking the time to look at this.
The key thing is from what I see somehow it is not moving the messages to the correct folders based on the above criterior.
$cron = $argv[1] == 'cron=1';
if (isset($_POST['submit']) || $cron) {
$from_ts = $cron ? time() - 3600 * 2 : strtotime($_POST['from']);
$to_ts = $cron ? time() : strtotime($_POST['to']);
$from = date('d M Y', $from_ts);
$to = date('d M Y', $to_ts);
$users = $_POST['users'];
$type = $cron ? 'UNSEEN' : $_POST['type'];
$users = explode("\r\n", $users);
$users = array_unique($users);
$str = ($from == $to ? "ON \"$from\"" : "SINCE \"$from\" BEFORE \"".date('d M Y', $to_ts + 3600 * 24)."\"")." $type";
$dir_name = "$type From ".date('d-m-Y H:i', $from_ts).' To '.date('d-m-Y H:i', $to_ts);
$dir = $cron ? "xxxxxxxxxxxxxxxxxxx" : "xxxxxxxxxxxx";
mkdir($dir);
$cnt_files = 0;
$cnt_msg = 0;
foreach ($users as $u) {
$check = 0;
$imap = "{localhost:143/novalidate-cert}INBOX";
$mailbox = $u.'@xxxxxxxxx.com';
$mbox = imap_open($imap, $mailbox, 'xxxxxxx', OP_READONLY);
$emails = imap_search($mbox, $str);
$bodies = array();
$body = '';
foreach ($emails as $e) {
$msg = imap_headerinfo($mbox, $e);
if ($msg->udate > $from_ts && $msg->udate < $to_ts) {
$text = preg_replace("/(?:\S{70,}\s*)+/is", 'Image not viewable in corrlinks', remove_facebook(imap_qprint(preg_replace("/textmessage\.org/i", "** xxxxxxxxxxxxxxxxxxxxxrvice ends Saturday 11-04-2015*** write back with UPGRADE! in the subject line", imap_fetchbody($mbox, $e, 1)))));
if (!$text)
continue;
$subj = 'From: '.$msg->fromaddress."\nSent: ".$msg->date."\nTo: ".$msg->toaddress."\nSubject: ".$msg->subject;
if (strlen($body) + strlen($text) + strlen($subj) > 6000) {
$bodies[] = $body;
$body = '';
}
$body .= $subj."\n\n".$text."\n".str_repeat('*', 10)."\n";
$cnt_msg++;
$check = 1;
}
}
if ($check) {
$bodies[] = $body;
$cnt_files += count($bodies);