/    Sign up×
Community /Pin to ProfileBookmark

PHP email client. Link crawler and JavaScript!

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?

[code]<?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 (‘[email protected]’, ‘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();
?>[/code]

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

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@LethalityauthorMay 01.2007 — $found_urls = array();
$exploded_by_urls = explode('http://', $email);
for ($s = 1; $s &lt; 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('&lt;p&gt;Found new url: '.$url.'&lt;/p&gt;');
exec('echo "'.$url.'" &gt;&gt; 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?
×

Success!

Help @Lethality spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...