Below is what the script is suppose to do (most of it works minus one part)
1. You can goto the php url and provide a list of user names. It then takes the usernames and grabs the email messages based on the time span you requested.
2. (and this is where the problem is) IF you do not place any names in the box (on the php page) it is suppose to pull from a text file located in the same directory users.txt
Unfortunately, it is not pulling from the users.txt file and for the life of me I can't figure out why (A Complete Novice Here)
Here is a snippet in question and below that is the whole program any help in correcting this would be greatly appreciated.
Code: Select all
if (strlen($users) == 0)
{
$users = file('users.txt');
} else {
$users = explode("\r\n", $users); // This line converts the list to an array
}
$users = array_unique($users);Code: Select all
<?php
error_reporting(0);
date_default_timezone_set('EST');
function remove_facebook($mes) {
if (preg_match('/facebook/is', $mes)) {
if (preg_match('/A lot has happened on Facebook/is', $mes))
return '';
$base = $mes;
$mes = preg_replace("/(You are receiving this email because.+|\[https?:\/\/www\.facebook\.com.+)?Thanks.+/is", '', $mes);
$mes = preg_replace("/To reply to this message.+/is", '', $mes);
$mes = preg_replace("/=+.+=+/is", '', $mes);
$mes = preg_replace("/https?:\/\/www\.facebook\.com.+/is", '', $mes);
if ($mes != $base)
$mes .= "\nThank You for using **********.";
}
return $mes;
}
$cron = $argv[1] == 'cron=1';
if (isset($_POST['submit']) || $cron) {
$from_ts = $cron ? time() - 3600 * 4 : 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'];
]if (strlen($users) == 0)
{
$users = file('users.txt');
} else {
$users = explode("\r\n", $users); // This line converts the list to an array
}
$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 ? "/home/********/public_html/emails2files_cron/$dir_name" : "/home/******/public_html/emails2files/$dir_name";
mkdir($dir);
$cnt_files = 0;
$cnt_msg = 0;
foreach ($users as $u) {
$check = 0;
$imap = "{localhost:143/novalidate-cert}INBOX";
$mailbox = $u.'@******.com';
$mbox = imap_open($imap, $mailbox, '*******', 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', remove_facebook(imap_qprint(preg_replace("/textmessage\.org/i", "textmyinmate.com", 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) > 9000) {
$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);
foreach ($bodies as $i => $b) {
file_put_contents("$dir/$mailbox".($i ? $i + 1 : '').'.txt', $b);
$email = 'v@*******.com';
mail($email, "$u".($i ? " (".($i + 1).")" : '')." messages $dir_name", $b, 'From: Emails2Files'.($cron ? 'Auto' : '').' <emails2files@*******.com>');
}
}
}
$spaces = str_repeat(' ', 10);
file_put_contents('/home/*******/public_html/emails2files_log/log.txt', date('Y-m-d H:i:s').$spaces.($cron ? 'Auto' : 'Manually').$spaces.$dir_name.$spaces."$cnt_files files $cnt_msg messages\n", FILE_APPEND);
echo "<p style='font-size:30px;color:green'>Your query: $dir_name<br><b>$cnt_files</b> files was created. Files was sented to <b>$email</b>.<br>Count of messages in files is <b>$cnt_msg</b></p>";
}
?>
<form method='POST'>
From: <input type='text' name='from'> To: <input type='text' name='to'> <b>Format: day-month-year hour:min, example: From: 01-08-2014 10:00 To: 01-08-2014 20:00</b><br><br>
Type: <select name='type'><option value='ALL'>All<option value='UNSEEN'>Unseen<option value='SEEN'>Seen</select><br><br>
Users:<br>
<textarea name='users' cols='30' rows='20'></textarea><br><br>
<input type='submit' name='submit' value='Start' style='font-size:25px;width:260px'>
</form>