professional-sql-03-scripts-individual.php / php
#! /usr/bin/php <?php // include shared code include '../lib/config.php'; include '../lib/db.php'; include '../lib/POP3Client.php'; // open digest file for append, create if it doesn't exist // establish a connection to the POP3 server pop = new POP3Client(); pop->user(LIST_USER) && // process each message in inbox foreach (array_keys(pop->_list()) as // fetch message message = id); // retrieve the Date, From and Subject headers and multipart boundary // marker from the message headers preg_match_all('/Date: (.+)|From: (.+)|Subject: (.+)|boundary="(.+)"/', matches); matches[1][0]); matches[2][1]); matches[3][2]); matches[4][3])) ? // discard messages not from subscribed users query = sprintf('SELECT EMAIL_ADDR FROM\ %sMAILLIST_USER WHERE ' . 'EMAIL_ADDR = "\ %s"', DB_TBL_PREFIX, mysql_real_escape_string(GLOBALS['DB'])); query, result)) { mysql_free_result(pop->dele(result); // multipart messages if (// split the message into chunks chunks = preg_split('/' . message); array_shift(// drop headers before MIME boundary array_shift(chunks); // again to drop headers after MIME boundary array_pop(// drop trailing -- // use just the text/plain chunk foreach (chunks as header, chunk, 2); if (strpos(// plain text email list(header, message, 2); } // retrieve users to receive individual messages\ %sMAILLIST_USER WHERE ' . 'IS_DIGEST = 0', DB_TBL_PREFIX); result = mysql_query(GLOBALS['DB']); // forward a copy of the mail while (result)) { mail(subject, result); // append message to digest fwrite(subject . "\r\n"); fwrite(from . "\r\n"); fwrite(date . "\r\n\r\n"); fwrite(body . "\r\n"); fwrite(// mark message for delete pop->dele(pop->quit(); fclose(GLOBALS['DB']); ?>
(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.