Page 2 of 2

Posted: Fri May 04, 2007 10:53 am
by Lethality
Alright, I guess I could tell the browser to open all new windows in tabs instead. But how would I proceed to open those links in a new window then?

Posted: Fri May 04, 2007 11:05 am
by arturm
having this addresses you have to call a javascript function
it can be done something like this:

Code: Select all

foreach ($urls as $url) {
    $js .= "openWindow('".$url."');\n";
}

echo "<script>\n".$js."</script>\n";
but you sill need javascript function called openWindow() that does to job for you to open a new tab (if it is possible in js) or window

Posted: Fri May 04, 2007 1:40 pm
by Lethality
arturm wrote:having this addresses you have to call a javascript function
it can be done something like this:

Code: Select all

foreach ($urls as $url) {
    $js .= "openWindow('".$url."');\n";
}

echo "<script>\n".$js."</script>\n";
but you sill need javascript function called openWindow() that does to job for you to open a new tab (if it is possible in js) or window
Awesome! :D
It works. The window opening function is called window.open though.

Posted: Fri May 04, 2007 2:55 pm
by Lethality
I stumbled across a weird problem now as I've filled the inbox with new mail (I deleted the old test mails):
When writing to the file it only writes the last email and not the others. I'm not sure why that happens.

Code: Select all

for ($i = 1; $i <= $count; $i++) {
        $email = $pop3->get_mail($i);

        if ($email == false) {
                echo $pop3->error;
                continue;
        }

        echo '<pre>';
        print_r ($email);
        echo '</pre>';


$file = "email.log";
$fh = fopen($file, 'w') or die("Can't open file");
$readable_email = print_r ($email, true);
fwrite($fh, $readable_email);
fclose($fh);
print_r ($email); still shows me all the emails, but it wont write that same info to the file for some reason.

Posted: Fri May 04, 2007 3:03 pm
by arturm
you can do 2 things:
1. open the file before the "for" loop, write to the file in the loop and close the file after the loop (this is the most efficient way)
2. just change fopen function to append the file. fopen() with mode 'a' instead of 'w' will do the job.

Posted: Fri May 04, 2007 4:12 pm
by Lethality
Ok, that worked but it spawned another annoying problem

Code: Select all

$file = "email.log";
$fh = fopen($file, 'w') or die("Can't open file");

for ($i = 1; $i <= $count; $i++) {
        $email = $pop3->get_mail($i);

        if ($email == false) {
                echo $pop3->error;
                continue;
        }

	$readable_email = print_r($email, true);
	fwrite($fh, $readable_email);
        echo '<pre>';
        print_r ($email);
        echo '</pre>';
}


fclose($fh);

$fh = fopen($file, 'r') or die("Can't open file");
$theData = fread($fh, filesize($file));
fclose($fh);
"Warning: fread() [function.fread]: Length parameter must be greater than 0" ...?

Posted: Fri May 04, 2007 7:49 pm
by arturm
it looks like filesize() returned zero
maybe first show all errors - put this before your code:

Code: Select all

error_reporting(E_ALL);
and then check what's the output:

Code: Select all

echo "size: ".filesize($file)."<br>";

Posted: Sat May 05, 2007 6:54 am
by Lethality
This only happens if the inbox is empty, I just replaced the error with a "No emails" message.
I'm trying to make a filter now, to filter out certain urls. Is there an easy way to make a filter before urls are written to the file?

Posted: Sat May 05, 2007 2:05 pm
by arturm
use preg_match() function for filtering