professional-sql-03-scripts-manage.php / php
#! /usr/bin/php <?php // include shared code include '../lib/config.php'; include '../lib/db.php'; include '../lib/POP3Client.php'; // establish a connection to the POP3 server pop->connect(POP3_SERVER, POP3_PORT); pop->pass(MANAGE_PASSWORD); // process each message in inbox foreach (array_keys(id) { // fetch message pop->retr(// retrieve the email address and subject headers preg_match_all('/From: (.+)|Subject: (.+)/i', message, from = trim(subject = trim(// determine if the email address exists query = sprintf('SELECT EMAIL_ADDR FROM\ %sMAILLIST_USER WHERE ' . 'EMAIL_ADDR = "\ %s"', DB_TBL_PREFIX, mysql_real_escape_string(GLOBALS['DB'])); query, exists = (mysql_num_rows(result); // send appropriate response switch (strtoupper(// subscribe email address to list case 'SUBSCRIBE': if (exists) { // address already exists query = sprintf('INSERT INTO\ %sMAILLIST_USER ' . '(EMAIL_ADDR) VALUES ("\ %s")', DB_TBL_PREFIX, mysql_real_escape_string(GLOBALS['DB'])); query, // remove email address from list case 'UNSUBSCRIBE': if (exists) {\ %sMAILLIST_USER WHERE ' . 'EMAIL_ADDR = "\ %s"', DB_TBL_PREFIX, mysql_real_escape_string(from, response_file = (mysql_query(GLOBALS['DB'])) ? 'unsubscribe.txt' : 'error.txt'; } else { // address does not exist // set preference for digest case 'SET +DIGEST': if (exists) {\ %sMAILLIST_USER SET ' . 'IS_DIGEST = 1 WHERE EMAIL_ADDR = "\ %s"', DB_TBL_PREFIX, mysql_real_escape_string(from, response_file = (mysql_query(GLOBALS['DB'])) ? 'digest_on.txt' : 'error.txt'; } else { // address does not exist // set preference for individual messages case 'SET -DIGEST': if (exists) {\ %sMAILLIST_USER SET ' . 'IS_DIGEST = 0 WHERE EMAIL_ADDR = "\ %s"', DB_TBL_PREFIX, mysql_real_escape_string(from, response_file = (mysql_query(GLOBALS['DB'])) ? 'digest_off.txt' : 'error.txt'; } else { // address does not exist // use help message case 'HELP': response_file = 'help.txt'; // unknown command was received default: // Read the data response = file_get_contents(REPLY_DIR . '/' . // these placeholders will be swapped in the message templates replace = array('<list_email>' => LIST_EMAIL, '<manage_email>' => MANAGE_EMAIL); replace), array_values(response); // send message mail(subject, // mark message for delete pop->dele(pop->quit(); mysql_close(
(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.