Webbots, Spiders, and Screen Scrapers - Michael Schrenk [67]
# Request and display all messages in $list_array
for($xx=0; $xx // Parse the mail ID from the message size list($mail_id, $size) = explode(" ", $list_array[$xx]); // Request the message for the specific mail ID $message = POP3_retr($POP3_connection, $mail_id); // Display message and place mail ID, size, and message in an array echo "$mail_id, $size\n"; $mail_array[$xx]['ID'] = $mail_id; $mail_array[$xx]['SIZE'] = $size; $mail_array[$xx]['MESSAGE'] = $message; // Display message in // (in case script is run in a browser) echo " // Delete the message from the server POP3_delete($POP3_connection, $mail_id); } Listing 15-12: Reading, displaying, and deleting each message found on the server Finally, after each message is read and deleted from the server, the session is closed, as shown in Listing 15-13. // End the server session echo POP3_quit($POP3_connection); } else { echo "Login error"; } Listing 15-13: Closing the connection to the server, or noting the login error if necessary Subsequently, if the connection wasn't originally made to the server, the script returns an error message. Further Exploration With a little thought, you can devise many creative uses for webbots that can access email accounts. There are two general areas that may serve as inspiration. Use email as a means to control webbots. For example, you could use an email message to tell a spider which domain to use as a target, or you could send an email to a procurement bot (featured in Chapter 19) to indicate which items to purchase. Use an email-enabled webbot to interface incompatible systems. For example, you could upload a small file to an FTP sever from a BlackBerry if the file (the contents of the email) were sent to a special webbot that, after reading the email, sent the file to the specified server. This could effectively connect a legacy system to remote users. Email-Controlled Webbots Here are a few ideas to get you started with email-controlled webbots. Design a webbot that forwards messages from a mailing list to your personal email address based upon references to a preset list of terms. (For example, the webbot could forward all messages that reference the words robot, web crawler, webbot, and spider.) Develop a procurement bot that automatically reconfigures your eBay bidding strategy when it receives an email from eBay indicating that someone has outbid you. Create a strategy that forwards an email message to a webbot that, in turn, displays the message on a 48-foot scrolling marquee that is outside your office building (assuming you have access to such a display!). Email Interfaces Here are a few ways you can capitalize on email-enabled webbots to interface different systems. Develop a webbot that automatically updates your financial records based on email you receive from PayPal. Create a webbot that automatically forwards all email with the word support in the subject line to the person working the help desk at that time. Write a webbot that notifies you when one of your mail servers has reached its email (size) quota. Write a service that interfaces shipping notification email messages from FedEx to your company's fulfillment system. Develop an email-to-fax service that faxes an email message to the phone number in the email's subject line. (This isn't hard to do if you have an old fax/modem from the last century lying around.) Write a webbot that maintains statistics about your email accounts, indicating who is sending the most email, when servers are busiest, the number of messages that are deleted without being read, when servers fail, and email addresses that are returned as undeliverable. Chapter 16. WEBBOTS THAT SEND EMAIL In Chapter 15 you learned how to create webbots that read email. In this chapter I'll show you how to write webbots that can create massive amounts of email. On that note, let's talk briefly about email ethics. Email, Webbots, and Spam