Jump to content

Recommended Posts

Hello everyone,  I have had assistance with this and he has done a great job.   Everything works with the script  -- except-- this filtering portion.

 

Basically if it sees a specific phrase it should move the text file to a specific folder.    However it is not  :(     

 

Hoping someone can look at this snippet of coding and let me konw where they see the typo

 

 

if ($check) {
$bodies[] = $body;
$cnt_files += count($bodies);
foreach ($bodies as $i => $b) {
file_put_contents("$dir/$mailbox".($i ? $i + 1 : '').'.txt', $b);
          if(strpos($b,  'records indicate you are sending text messages on an expired account') !== false){
            file_put_contents("EXPIRED/$file_name", $content);
          }
          else if(strpos($b, 'PHOTO MSG REPLIES') !== false){
            file_put_contents("PHOTO MSG/$file_name", $content);
          }
          else{
            file_put_contents.....
Link to comment
https://forums.phpfreaks.com/topic/296329-a-little-coding-help-please-ifstrposb/
Share on other sites

I realize this is just a snippet but it is such a small snippet nobody here is going to be able to help you.

 

Here's what it is doing at the moment:

 

if some value ($check) is true you do the following:

 

- save an item called $body into an array called $bodies

- for each element of the $bodies array (only one so far!) you assign the element number and the value of that element to $i and $b

- you write the contents of $b to a file name based on the current value of $i - which will be strange when $i is a zero at the beginning

- THEN you check the contents in $b for some string write a message to something called $filename which we don't know about yet.

- if the contents in $b are not the first string you check for another string and again write some message to another thing called $filename in a different folder.

 

and then ???

 

Just how do you know nothing is being written? Do you get any kind of response from this or just a blank screen? Try turning on error checking (which you should already have on) or using some echo to show what you are doing each time thru this code (something like echo "just wrote $i to $dir/$mailbox" or echo "just wrote EXPIRED contents" or echo "just wrote photo_msg contents". That should help you see what is happening. Be sure to echo out $dir and $mailbox and $file_name at some point to see what they are.

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);

Since you say the issue seems to be it not adding the text file into it's folder...

 

try adding some checking to your code
echo out a message each step to see what actions it's doing
make sure directory exists is_dir()
What about folder permissions?
is_writable() will check if the directory exists and also is writable
file_exists() or is_file() to check it actually got there
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.