10.07.2015 Views

Beginning Web Development With Perl : From Novice to ... - Nabo

Beginning Web Development With Perl : From Novice to ... - Nabo

Beginning Web Development With Perl : From Novice to ... - Nabo

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

116CHAPTER 6 ■ NET:: TOOLS($messages,$size) = $pop3conn->popstat();print "There are $messages messages <strong>to</strong>taling $size bytes\n";Deleting E-Mail and QuittingAt this point, you’ve seen how <strong>to</strong> set up a connection object, as well as how <strong>to</strong> log in <strong>to</strong> the serverand view messages. The normal POP3 conversation involves two additional tasks: deleting themessages and quitting or closing the connection. These are accomplished through the delete()and quit() methods, respectively.DeleteIt’s important <strong>to</strong> note that the message isn’t actually deleted when you call delete(), but onlymarked <strong>to</strong> be deleted when the connection is closed. You could then, in theory, use the reset()method <strong>to</strong> unmark the messages <strong>to</strong> be deleted, thus preventing them from being deleted. Inpractice, the reset() method is not always helpful, since the connection <strong>to</strong> the server is oftenclosed immediately after you issue delete().To mark a message for deletion, simply call the delete() method with the number of themessage as the argument. For example, <strong>to</strong> mark message number 1 for deletion, the call wouldlook like this:$pop3conn->delete(1);Now when you close the connection using the quit() method, the messages that have beenmarked as deleted will be purged from the remote mail spool.QuitYou’ve seen the quit() method used throughout the examples in the chapter. Here it is again:$pop3conn->quit();But wait! What if you wanted <strong>to</strong> prevent that message from being deleted? As I noted inthe previous section, a call <strong>to</strong> the reset() method prior <strong>to</strong> closing the connection will preventthe message from being purged:$pop3conn->reset();Note that if you don’t use the quit() method <strong>to</strong> actually close the connection, the messageswill never be purged, even after the TCP session times out for the connection. This behaviormight vary depending on the implementation of the POP3 server, so I recommend explicitlyclosing the connection.■Note Other methods are available with Net::POP3. For more information about those methods, see thedocumentation for Net::POP3 at http://search.cpan.org/~gbarr/libnet-1.19/Net/POP3.pm orperldoc Net::POP3.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!