/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! |
Achieving true agility is a never-ending effort. We will showcase how you can become agile incrementally, a few practices at the time.Which practices should any agile team strive to adopt? What additional practices should you consider based on your needs to scale? Adopting practices are however made much easier with the right tool support. What about if your tools adapt to your practices? We will take a look at how the Jazz technology can be leveraged to make your process change the behavior of your tools. FREE! Go There Now!
|
|
|
|
Build secure Web services with transport-level security using IBM Rational Application Developer V7 and IBM WebSphere Application Server V6.1. Follow this three-part series for step-by-step instructions about how to develop Web services and clients, configure HTTP basic authentication, and configure HTTP over SSL (HTTPS). This first part of the series walks you through building a Web service for a simple calculator application. You generate and test two different types of Web services clients: a Java Platform, Enterprise Edition (Java EE) client and a stand-alone Java client. You also handle user-defined exceptions in Web services. 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 Software Analyzer Developer Edition V7.0 to identify bug defects earlier in the software development cycle. Rational Software Analyzer is an extensible software development solution that reduces the expense of bug-fixes by enabling static analysis code reviews and bug identification very early in the development cycle. FREE! Go There Now!
|
|
|
|
Secure your Web applications with IBM Rational AppScan Standard Edition V7.7, previously known as Watchfire AppScan. This Web application security testing tool automates vulnerability assessments and scans and tests for common Web application vulnerabilities. Visit IBM developerWorks to download a free trial of IBM Rational AppScan Standard Edition V7.7. FREE! Go There Now!
|
|
|
|
Rational Modeling Extension for Microsoft .NET enhances usability for code generation supporting a more intelligent refactoring. The latest enhancements enable organizations with Java and .NET systems and software development maintain architectural integrity across heterogeneous platforms. FREE! Go There Now!
|
|
|
|
Discover how Rational tools and best practices for testing can make your job easier. The new Rational Testing eKits provide you with valuable resources – including demos, webcasts, tutorials, and articles – that help you address your specific testing needs across the software lifecycle. Five new eKits are available covering the topics of Requirements and Test Management, Functional Testing, Performance Testing, Code Quality and Embedded Systems, and SOA and Web Services Testing. FREE! Go There Now!
|
|
|
|
Learn the basics of the IBM Customer Information Control System (CICS). With a hands-on exercise, learn how to get your first CICS application up and running on your desktop using TXSeries V6.1 for Windows. The tutorial shows you how to download and install a free trial version of TXSeries V6.1. FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Method Composer V7.2 which helps you deliver customized yet consistent process guidance to your project teams and IT organization, and includes the latest version of IBM Rational Unified Process (RUP), which has provided process guidance to teams since 1996. FREE! Go There Now!
|
|
|
|
The Eclipse community is constantly working to extend Eclipse's functionality. In this webcast, learn about some of the most important and feature-rich projects under development. From multi-language support to plug-in development, tune in to see what Eclipse is capable of now. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |