<?php // script to access domain mail and gather content // of mail intended for insertion into // the site_content table. // Variables: // $uname: mailbox username // $upass: mailbox password // $mailserver: mail server to access // $parent: the document ID to set as this document's parent (for Ditto call) // $template: the template to use for this document // to-do: make this a module and set these in the module configuration $uname = '[email protected]'; $upass = 'password'; $mailserver = 'mail.domain.com'; $parent = 3; $template = 3; // connect to the mail server $mbox = imap_open("{localhost:143}INBOX", $uname, $upass); $listing = imap_search($mbox, "SUBJECT Submission"); if(imap_num_msg($mbox) > 0) { foreach($listing as $msg) { $message = imap_body($mbox, $msg); $arr = explode("\n", $message); // break it up $pagetitle = array_shift($arr); // shift off the first three lines $createdby = array_shift($arr); $introtext = array_shift($arr); $content = implode("\n", $arr); // put the rest of it back together // won't be needed when this is made into a module include "manager/includes/config.inc.php"; $conn = mysql_connect($database_server, $database_user, $database_password) or die(mysql_error()); $db = mysql_select_db(trim($dbase, '`')) or die(mysql_error()); // clean it up $pagetitle = mysql_real_escape_string(trim($pagetitle)); $introtext = mysql_real_escape_string(trim($introtext)); $content = mysql_real_escape_string(trim($content)); $createdby = mysql_real_escape_string(trim($createdby)); // get submitter's ID $sql = "SELECT internalKey FROM " . $table_prefix . "user_attributes WHERE fullname = '$createdby'"; $res = mysql_query($sql) or die(mysql_error()); $num = mysql_num_rows($res); if($num == 1) { $createdby = mysql_result($res, 0); $sql = "INSERT INTO " . $table_prefix . "site_content (pagetitle, introtext, content, parent, template, createdon, createdby) VALUES ('$pagetitle', '$introtext', '$content', $parent, $template, time() '$createdby')"; mysql_query($sql) or die(mysql_error()); } } }
). The module would then compare the "from" email address to the manager user table and grab the UserID that way. If there’s no match, the email is discarded (or reported in the Event Log).