Click to See Complete Forum and Search --> : PHP email client. Link crawler and JavaScript!


Lethality
04-30-2007, 08:53 AM
I'm trying to make this little email client that can handle links. It's main purpose is to crawl all unread emails for links and store them in separate files. There will be one file for each day (so its date controlled). Each file will have a date and it will be filled with the links from all the emails that were sent to the inbox at that day.
Then eventually another script (Java perhaps) will open that file, go through the links and open them all in a browser.

This is how far I've come, with alot of help from djlosch at gentoo.org (great guy).
There are some issues. First, I cannot get those http:// links written to files, and it is very basic at the moment. There are no date stamps or whatever and I have no idea how to create that java script to open the links. Also, I dont know how to mark emails as read so that it wont open the emails twice.
So I ask you guys here for help. Any views?

<?php
require ('pop3.class.inc');
$newline = "<br \>";
$pop3 = new POP3;

// Connect to mail server
$do = $pop3->connect ('pop.server.domain',110);
if ($do == false) {
die($pop3->error);
}

echo 'Connected to mail server';
$do = $pop3->login ('account@server.domain', 'password');

if ($do == false) {
die($pop3->error);
}

echo '- - - - - ' ;
echo 'Logged in';

// Get office status
$status = $pop3->get_office_status();

if ($status == false) {
die($pop3->error);
}

$count = $status['count_mails'];
echo $newline;
echo $newline;
echo 'There are ' . $count . ' new e-mails waiting for you!';



echo $newline;
echo $newline;

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>';
$found_urls = array();
$exploded_by_urls = explode('http://', $email);
for ($s = 1; $s < count($exploded_by_urls); $s++)
$found_urls[] = substr($exploded_by_urls[$s], 0, strpos($exploded_by_urls[$s], ' '));
$already_linked = file('already_linked.log');
foreach ($found_urls as $url)
{
if (!in_array($url, $already_linked))
{
exec('wget "'.$url.'"');
echo('<p>Found new url: '.$url.'</p>');
exec('echo "'.$url.'" >> already_linked.log');
}
}
}


$pop3->close();
?>

pop3.class.inc can be found here http://www.phpclasses.org/browse/file/3925.html

Lethality
05-01-2007, 08:12 AM
$found_urls = array();
$exploded_by_urls = explode('http://', $email);
for ($s = 1; $s < count($exploded_by_urls); $s++)
$found_urls[] = substr($exploded_by_urls[$s], 0, strpos($exploded_by_urls[$s], ' '));
$already_linked = file('already_linked.log');
foreach ($found_urls as $url)
{
if (!in_array($url, $already_linked))
{
exec('wget "'.$url.'"');
echo('<p>Found new url: '.$url.'</p>');
exec('echo "'.$url.'" >> already_linked.log');
}
}
}

I think there is a problem here.

echo $exploded_by_urls[0]; and [1] has no output, and it won't write to the file. Any one able to help with that?