/Program to check a POP3 mail server for mail,
//retrieve the number of messages,play an audio
//file as an alert and start the fetchmail program.
//
//Written by Robert Tucci
By : bob0099
//Program to check a POP3 mail server for mail,
//retrieve the number of messages,play an audio
//file as an alert and start the fetchmail program.
//
//Written by Robert Tucci.
<?php
//call function with validation
//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
$conn=pop3_connect();
if(!$conn)
echo "no connection";
exit;
//start of function
//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
function pop3_connect()
{
$pop_timeout=10;
$pop_server="mail.whoever.net";
$pop_port=110;
$pop_user="foo";
$pop_pass="foobar";
//connect to pop3 server
//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
if(!pop_timeout){
$pop_handle = fsockopen($pop_server,$pop_port);
}
else{
$pop_handle = fsockopen($pop_server,$pop_port,$errno,$errstr,$pop_timeout);
}
if(!pop_handle){
echo "Connection Failed\n";
exit();
}
else{
echo "Connected\n";
}
//start transaction
//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
$listen = fgets($pop_handle,1024);
fputs($pop_handle,"USER ".$pop_user."\n");
$listen = fgets($pop_handle,1024);
fputs($pop_handle,"PASS ".$pop_pass."\n");
$listen = fgets($pop_handle,1024);
fputs($pop_handle,"STAT\n");
$listen = fgets($pop_handle,1024);
fputs($pop_handle,"QUIT\n");
$quit = fgets($pop_handle,1024);
//manipulate STAT message from pop3 server
//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
$str=substr($listen,0,4);
$message = split(" ",$listen);
if(trim($str) != "+OK"){
echo "Got no OK from server";
exit();
}
//If no mail
//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
if(trim($str) == "+OK" && $message[1] == "0"){
echo "No mail for ",$pop_user;
echo "$quit";
exit();
}
//If mail
//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
if(trim($str) == "+OK" && $message[1] != "0"){
echo "You have ",$message[1],"messages";
echo "$quit";
//Play wav file and start fetchmail
//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
exec("play /home/bob/my_wav.wav");
exec("fetchmail");
exit();
}
else{
echo "$quit";
echo "Failed to retrieve number of messages";
exit();
}
}
?>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Miscellaneous Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
Learn field-tested SOA principles, methodology, technology and implementation from the global SOA market leader - in a new e-book by an IBM SOA expert. Written by IBM Certified SOA Solution Designer Bobby Woolf, "Exploring IBM SOA Technology & Practice" is the ultimate insider's guide to SOA - a PDF e-book packed cover to cover with IBM's specific advice on how to make your SOA implementation a success. FREE! Go There Now!
|
|
|
|
Effective governance for lean development isn’t about command and control. Instead, the focus is on enabling the right behaviors and practices through collaborative and supportive techniques. Hear from Scott Ambler on how it is far more effective to motivate people to do the right thing than it is to force them to do so. Learn how to form a lightweight, collaboration-based framework that reflects the realities of modern IT organizations. FREE! Go There Now!
|
|
|
|
Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo. FREE! Go There Now!
|
|
|
|
Download a free trial version of IBM DB2 9.5 for Linux, UNIX, and Windows. DB2 9 is the result of a five-year development project that transformed traditional (static) database technology into an interactive data server that merges the high performance and ease of use of DB2 with the self-describing benefits of XML. FREE! Go There Now!
|
|
|
|
Download a free trial version of IBM Rational Developer for System i V7.1, which provides a complete development environment for traditional i5/OS application development. IBM Rational Developer for System i is a new eclipse-based workstation offering for i5/OS application development that provides a comprehensive Integrated Development Environment for edit/compile/debug of traditional RPG/COBOL/C/C++ i5/OS applications. FREE! Go There Now!
|
|
|
|
Rational Build Forge Express Edition is an automation framework that packages the latest enterprise-grade technologies into a reliable, flexible and robust configuration designed and priced specifically for small to midsize businesses. The new Rational Build Forge Express eKit provides you with valuable resources – including a case study, podcast, demo, and articles – to help you increase staff productivity, compress development cycles and deliver better software, fast. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on December 11 at 1:00 pm ET to get tips on building your own plugins with Rational Method Composer. Get your questions answered! FREE! Go There Now!
|
|
|
|
Try the latest version of IBM Rational Manual Tester V7.0.1 by downloading a free trial from IBM developerWorks. This manual test authoring and execution tool promotes test step reuse to reduce the impact of software change on testers and business analysts and addresses the needs of teams performing at least a portion of their testing manually. FREE! Go There Now!
|
|
|
|
As businesses grow increasingly dependent upon Web applications, these complex entities grow more difficult to secure. Most companies equip their Web sites with firewalls, Secure Sockets Layer (SSL), and network and host security, but the majority of attacks are on applications themselves – and these technologies cannot prevent them. This paper explains what you can do to help protect your organization, and it discusses an approach for improving your organization’s Web application security. FREE! Go There Now!
|
|
|
|
Viper 2 brings a great value to developer communities including SQL, XML, PHP, Ruby, .NET and Java. You probably already know that DB2 Express-C is free for developers to develop, deploy and distribute. Viper 2 provides a variety of means that help move your application from the development stage to deployment more rapidly. This webcast shows how to best utilize the latest tools available for developing DB2 applications. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |