topical media & game development
alt-bot-lib-pop3.php / php
<?php
/*
#################################################################
Copyright 2007, Michael Schrenk
This software is designed for use with the book,
"Webbots, Spiders, and Screen Scarpers", Michael Schrenk, 2007 No Starch Press, San Francisco CA
W3CŪ SOFTWARE NOTICE AND LICENSE
This work (and included software, documentation such as READMEs, or other
related items) is being provided by the copyright holders under the following license.
By obtaining, using and/or copying this work, you (the licensee) agree that you have read,
understood, and will comply with the following terms and conditions.
Permission to copy, modify, and distribute this software and its documentation, with or
without modification, for any purpose and without fee or royalty is hereby granted, provided
that you include the following on ALL copies of the software and documentation or portions thereof,
including modifications:
1. The full text of this NOTICE in a location viewable to users of the redistributed
or derivative work.
2. Any pre-existing intellectual property disclaimers, notices, or terms and conditions.
If none exist, the W3C Software Short Notice should be included (hypertext is preferred,
text is permitted) within the body of any redistributed or derivative code.
3. Notice of any changes or modifications to the files, including the date changes were made.
(We recommend you provide URIs to the location from which the code is derived.)
THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR FITNESS
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD
PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT
OF ANY USE OF THE SOFTWARE OR DOCUMENTATION.
The name and trademarks of copyright holders may NOT be used in advertising or publicity pertaining to the
software without specific, written prior permission. Title to copyright in this software and any associated
documentation will at all times remain with copyright holders.
#################################################################
*/
#################################################################
#
# LIB_pop3.php POP3 Mail Routines
#
# This library provides routines that read and delete mail form mail
#
servers that employ POP3 (Post Office Protocol)
#
# Detailed information about POP3 is found in RFC 1939
#
www.faqs.org/rfcs/rfc1939.html
#
#-----------------------------------------------------------------------
# FUNCTIONS
#
# POP3_connect Initiates a POP3 connection to a mail server and
# returns a connection hand and indication if the
# username and password were authenticated.
#
# POP3_list() Executes a POP3 LIST command
#
# POP3_retr() Executes a POP3 RETR command
#
# POP3_delete() Executes a POP3 DELE command
#
# POP3_quit() Executes a POP3 QUIT command
#
#-----------------------------------------------------------------------
*********************************************************************
POP3 Constants (scope = global)
----------------------------------------------------------------------
define("END_CHAR", "."); // Identifies the POP3 multi line
// termination character (if found
// at the beginning of a line.
define("POP3_PORT", "110"); // POP3 servers listen to port 110
*********************************************************************
POP3_connect(user, server. Uses pass to authenticate a user ith an
email account on array['login'] True if authentication is successful
otherwise false
array['message'] Signon message returned by mail server
INPUT:
user Email address of email account
function POP3_connect(server, pass)
{
handle = fsockopen(port=POP3_PORT, errstr, 30);
handle, 4096);
if(stristr(error = message;
// Send the username
fwrite(user."\n");
handle, 4096);
if(stristr(error = user_reply;
// Send the password
fwrite(pass."\n");
handle, 4096);
if(stristr(error = pass_reply;
// Evaluate the results of presenting user/pass credentials
if(strlen(ret_array['login']=true;
message;
}
else
{
ret_array['message']=ret_array['handle']=ret_array;
}
*********************************************************************
POP3_list(list_array[n][id size]
INPUT:
function POP3_list(handle)
{
// Initialization
reply="";
// Make "list" request
handle, "LIST\n");
handle);
// Fill an array with mail server reply
if(stristr(reply, END_CHAR))
{
handle);
if(!stristr(list_array, list_array;
}
}
*********************************************************************
POP3_retr(id)
-------------------------------------------------------------
DESCRIPTION:
Executes a POP3 RETR command
OUTPUT:
id
INPUT:
id From POP3_list() function
*********************************************************************
function POP3_retr(id)
{
// Initialize
message="";
// Make POP3 "RETR #id" request
fputs(id."\n");
// Gather the multiline response
while(this_line = fgets(this_line, 0, 1)==".")
message = this_line;
}
return
*********************************************************************
POP3_delete(handle, id, for deletion. The record is not actually
deleted until a QUIT command is issued.
INPUT:
function POP3_delete(handle, handle, "DELE ".reply = fgets(reply;
}
*********************************************************************
POP3_quit(handle From POP3_connect() function
*********************************************************************
function POP3_quit(handle, "QUIT\n");
handle);
return
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.