} if ($_REQUEST["msgid"] > 1) { $smarty->assign('prev', $_REQUEST["msgid"] - 1); } else { $smarty->assign('prev', ''); } $full = $pop3->getMsg($_REQUEST["msgid"]); $pop3->disconnect(); $output = mime::decode($full); //echo "<pre>OUTPUT:";print_r($output); echo"</pre>"; $bodies = mime::get_bodies($output); $temp_max = count($bodies); for ($i = 0; $i < $temp_max; $i++) { $bodies[$i] = strip_tags($bodies[$i], "<a><b><i><table><tr><td><th><ul><li><img><hr><ol><br /><h1><h2><h3><h4><h5><h6><div><span><font><form><input><textarea><checkbox><select>"); } $attachments = mime::get_attachments($output); $smarty->assign('attachs', $attachments); $smarty->assign('bodies', $bodies); $allbodies = join("\n", $bodies); $allbodies = "\n\n------------------------------------------\n" . $allbodies; $smarty->assign('allbodies', htmlspecialchars($allbodies)); $to_addresses = $output['header']["from"]; // Get email addresses from the "from" portion $to_addresses = split(',', $to_addresses); $temp_max = count($to_addresses); for ($i = 0; $i < $temp_max; $i++) { preg_match("/<([^>]+)>/", $to_addresses[$i], $add); if (isset($add[1])) { $to_addresses[$i] = $add[1]; } }
function process_inbound_mail($forumId, $suppressErrors = false) { // require_once ("lib/webmail/pop3.php"); require_once "lib/webmail/net_pop3.php"; require_once "lib/mail/mimelib.php"; //require_once ("lib/webmail/mimeDecode.php"); include_once "lib/webmail/htmlMimeMail.php"; $info = $this->get_forum($forumId); // for any reason my sybase test machine adds a space to // the inbound_pop_server field in the table. $info["inbound_pop_server"] = trim($info["inbound_pop_server"]); if (!$info["inbound_pop_server"] || empty($info["inbound_pop_server"])) { return; } $pop3 = new Net_POP3(); $pop3->connect($info["inbound_pop_server"]); $pop3->login($info["inbound_pop_user"], $info["inbound_pop_password"]); if (!$pop3) { return; } $mailSum = $pop3->numMsg(); //we don't want the operation to time out... this would result in the same messages being imported over and over... //(messages are only removed from the pop server on a gracefull connection termination... ie .not php or webserver a timeout) //$maximport should be in a admin config screen, but I don't know how to do that yet. $maxImport = 10; if ($mailSum > $maxImport) { $mailSum = $maxImport; } for ($i = 1; $i <= $mailSum; $i++) { //echo 'loop ' . $i; $aux = $pop3->getParsedHeaders($i); // If the connection is done, or the mail has an error, or whatever, // we try to delete the current mail (because something is wrong with it) // and continue on. --rlpowell if ($aux == FALSE) { $pop3->deleteMsg($i); continue; } //echo '<pre>'; //print_r ($aux); //echo '</pre>'; if (!isset($aux['From'])) { if (isset($aux['Return-path'])) { $aux['From'] = $aux['Return-path']; } else { $aux['From'] = ""; $aux['Return-path'] = ""; } } //try to get the date from the email: $postDate = strtotime($aux['Date']); if ($postDate == false) { $postDate = $this->now; } //save the original email address, if we don't get a user match, then we //can at least give some info about the poster. $original_email = $aux["From"]; //fix mailman addresses, or there is no chance to get a match $aux["From"] = str_replace(' at ', '@', $original_email); preg_match('/<?([-!#$%&\'*+\\.\\/0-9=?A-Z^_`a-z{|}~]+@[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\\.[-!#$%&\'*+\\.\\/0-9=?A-Z^_`a-z{|}~]+)>?/', $aux["From"], $mail); // should we throw out emails w/ invalid (possibly obfusicated) email addressses? //this should be an admin option, but I don't know how to put it there yet. $throwOutInvalidEmails = false; if (!array_key_exists(1, $mail)) { if ($throwOutInvalidEmails) { continue; } } $email = $mail[1]; $full = $pop3->getMsg($i); $message = $pop3->getBody($i); $output = mime::decode($full); //unset ($parts); //$this->parse_output($output, $parts, 0); if (isset($output["text"][0])) { $body = $output["text"][0]; } elseif (isset($output['parts'][0]["text"][0])) { $body = $output['parts'][0]["text"][0]; } elseif (isset($output['body'])) { $body = $output['body']; } elseif (isset($output['parts'][0]['html'][0])) { // some html message does not have a text part $body = $this->htmldecode(strip_tags(preg_replace('/\\n\\r/', '', $output['parts'][0]['html'][0]))); } elseif (isset($output['parts'][0]['parts'][0]['text'][0])) { $body = $output['parts'][0]['parts'][0]['text'][0]; } else { $body = ""; } // Remove 're:' and [forum]. -rlpowell $title = trim(preg_replace("/[rR][eE]:/", "", preg_replace("/\\[[-A-Za-z _:]*\\]/", "", $output['header']['subject']))); //Todo: check permissions $message_id = substr($output['header']["message-id"], 1, strlen($output['header']["message-id"]) - 2); if (isset($output['header']["in-reply-to"])) { $in_reply_to = substr($output['header']["in-reply-to"], 1, strlen($output['header']["in-reply-to"]) - 2); } else { $in_reply_to = ''; } // Determine user from email $userName = $this->table('users_users')->fetchOne('login', array('email' => $email)); //use anonomus name feature if we don't have a real name if (!$userName) { $anonName = $original_email; } // Determine if the thread already exists. $parentId = $this->table('tiki_comments')->fetchOne('threadId', array('object' => $forumId, 'objectType' => 'forum', 'parentId' => 0, 'title' => $title)); if (!$parentId) { /* This doesn't make any sense to me... why would we say an inbound email is a'thread to discuss a page'? I've updated this to just make a new thread w/ the original email info by seting $parentId = 0 // No thread already; create it. $temp_msid = ''; $parentId = $this->post_new_comment( 'forum:' . $forumId, 0, $userName, $title, sprintf(tra("Use this thread to discuss the %s page."), "[tiki-index.php?page=$title|$title]"), $temp_msid, $in_reply_to ); $this->register_forum_post($forumId,0); // First post is in reply to this one $in_reply_to = $temp_msid; */ $parentId = 0; } // post $threadid = $this->post_new_comment('forum:' . $forumId, $parentId, $userName, $title, $body, $message_id, $in_reply_to, 'n', '', '', '', $anonName, $postDate); $this->register_forum_post($forumId, $parentId); // Process attachments if (array_key_exists('parts', $output) && count($output['parts']) > 1) { $forum_info = $this->get_forum($forumId); if ($forum_info['att'] != 'att_no') { $errors = array(); foreach ($output['parts'] as $part) { if (array_key_exists('disposition', $part)) { if ($part['disposition'] == 'attachment') { if (strlen($part['d_parameters']['filename']) > 0) { $part_name = $part['d_parameters']['filename']; } else { $part_name = "Unnamed File"; } $this->add_thread_attachment($forum_info, $threadid, $errors, $part_name, $part['type'], strlen($part['body']), 1, '', $part['body'], $suppressErrors); } elseif ($part['disposition'] == 'inline') { foreach ($part['parts'] as $p) { $this->add_thread_attachment($forum_info, $threadid, $errors, '-', $p['type'], strlen($p['body']), 1, '', $p['body'], $suppressErrors); } } } } } } // Deal with mail notifications. if (array_key_exists('outbound_mails_reply_link', $info) && $info['outbound_mails_for_inbound_mails'] == 'y') { //phpinfo(); include_once 'lib/notifications/notificationemaillib.php'; sendForumEmailNotification('forum_post_thread', $threadid, $info, $title, $body, $userName, $title, $message_id, $in_reply_to, $threadid, $parentId); } $pop3->deleteMsg($i); } $pop3->disconnect(); }
function decode($input, $default_ctype = 'text/plain', $crlf = "\r\n") { $back = array(); $pos = strpos($input, $crlf . $crlf); if (!$pos) { $crlf = "\n"; $pos = strpos($input, $crlf . $crlf); if (!$pos) { return false; } } $header = substr($input, 0, $pos); $body = substr($input, $pos + 2 * strlen($crlf)); $headparsed = preg_replace('/' . $crlf . "(\t| )/", ' ', $header); $heads = explode($crlf, trim($headparsed)); if (substr($heads[0], 0, 5) == 'From ') { $heads[0] = str_replace('From ', 'x-From: ', $heads[0]); } foreach ($heads as $line) { $hdr_name = trim(substr($line, 0, strpos($line, ':'))); $hdr_value = trim(substr($line, strpos($line, ':') + 1)); if (substr($hdr_value, 0, 1) == ' ') { $hdr_value = substr($hdr_value, 1); } $hdr_value = preg_replace('/(=\\?[^?]+\\?(Q|B|q|b)\\?[^?]*\\?=)( |' . "\t|" . $crlf . ')+=\\?/', '\\1=?', $hdr_value); while (preg_match('/(=\\?([^?]+)\\?(Q|B|q|b)\\?([^?]*)\\?=)/', $hdr_value, $matches)) { list(, $encoded, $charset, $encoding, $text) = $matches; switch ($encoding) { case 'B': case 'b': $text = base64_decode($text); break; case 'Q': case 'q': $text = str_replace('_', ' ', $text); preg_match_all('/=([A-F0-9]{2})/', $text, $matches); foreach ($matches[1] as $value) { $text = str_replace('=' . $value, chr(hexdec($value)), $text); } break; } if ($charset == 'iso-8859-1') { $text = utf8_encode($text); } elseif ($charset != 'utf-8' && function_exists('mb_convert_encoding')) { $text = mb_convert_encoding($text, 'utf-8', $charset); } $hdr_value = str_replace($encoded, $text, $hdr_value); } $lname = strtolower($hdr_name); if (isset($back['header'][$lname]) and !is_array($back['header'][$lname])) { $back['header'][$lname] = array($back['header'][$lname]); $back['header'][$lname][] = $hdr_value; } elseif (isset($back['header'][$lname])) { $back['header'][$lname][] = $hdr_value; } else { $back['header'][$lname] = $hdr_value; } $headers["{$lname}"] = $hdr_value; } while (list($key, $value) = each($headers)) { $input = $headers[$key]; $it = array(); if (($pos = strpos($input, ';')) !== false) { $it['value'] = trim(substr($input, 0, $pos)); $input = trim(substr($input, $pos + 1)); if (strlen($input) > 0) { preg_match_all('/(([[:alnum:]]+)="?([^"]*)"?\\s?;?)+/i', $input, $matches); for ($i = 0, $icount_matches = count($matches[2]); $i < $icount_matches; $i++) { $it['other'][strtolower($matches[2][$i])] = $matches[3][$i]; } } } else { $it['value'] = trim($input); } switch ($key) { case 'content-type': $content_type = $it; $back['type'] = $content_type['value']; if (isset($content_type['other'])) { while (list($p_name, $p_value) = each($content_type['other'])) { $back['ctype_parameters'][$p_name] = $p_value; } } break; case 'content-disposition': $content_disposition = $it; $back['disposition'] = $content_disposition['value']; if (isset($content_disposition['other'])) { while (list($p_name, $p_value) = each($content_disposition['other'])) { $back['d_parameters'][$p_name] = $p_value; } } break; case 'content-transfer-encoding': $content_transfer_encoding = $it; break; } } if (isset($content_type)) { $type = 'text'; switch (strtolower($content_type['value'])) { case 'text/html': $type = 'html'; case 'text/plain': if (!empty($content_disposition) && $content_disposition['value'] == 'attachment') { $back['attachments'][] = $back['d_parameters']; } $encoding = isset($content_transfer_encoding) ? $content_transfer_encoding['value'] : '7bit'; $back['body'] = mime::decodeBody($body, $encoding); if (array_key_exists('ctype_parameters', $back) and isset($back['ctype_parameters']) and $back['ctype_parameters'] and (!isset($back['ctype_parameters']['charset']) or strtolower($back['ctype_parameters']['charset']) == 'iso-8858-1') and function_exists('utf8_encode')) { $back[$type][] = utf8_encode($back['body']); } elseif (array_key_exists('ctype_parameters', $back) and isset($back['ctype_parameters']) and $back['ctype_parameters'] and strtolower($back['ctype_parameters']['charset']) != 'utf-8' and function_exists('mb_convert_encoding')) { $back[$type][] = mb_convert_encoding($back['body'], 'utf-8', $back['ctype_parameters']['charset']); } else { $back[$type][] = $back['body']; } break; case 'multipart/signed': case 'multipart/digest': case 'multipart/alternative': case 'multipart/related': case 'multipart/mixed': $default_ctype = strtolower($content_type['value']) === 'multipart/digest' ? 'message/rfc822' : 'text/plain'; $tmp = explode('--' . $content_type['other']['boundary'], $body); for ($i = 1, $icount_tmp = count($tmp); $i < $icount_tmp - 1; $i++) { $parts[] = $tmp[$i]; } for ($i = 0, $icount_parts = count($parts); $i < $icount_parts; $i++) { $back['parts'][] = mime::decode($parts[$i], $default_ctype); } break; case 'message/rfc822': $back['parts'][] = mime::decode($body); break; default: if (!isset($content_transfer_encoding['value'])) { $content_transfer_encoding['value'] = '7bit'; } $back['body'] = mime::decodeBody($body, $content_transfer_encoding['value']); break; } } else { $back['body'] = mime::decodeBody($body); } $ctype = explode('/', $default_ctype); $back['ctype_primary'] = $ctype[0]; $back['ctype_secondary'] = $ctype[1]; return $back; }
$hash['contributions'] = $_REQUEST['contributions']; } if (!empty($_REQUEST['contributors'])) { $hash['contributors'] = $_REQUEST['contributors']; } if (isset($_FILES['userfile1']) && is_uploaded_file($_FILES['userfile1']['tmp_name'])) { check_ticket('edit-page'); require "lib/mail/mimelib.php"; $fp = fopen($_FILES['userfile1']['tmp_name'], "rb"); $data = ''; while (!feof($fp)) { $data .= fread($fp, 8192 * 16); } fclose($fp); $name = $_FILES['userfile1']['name']; $output = mime::decode($data); $parts = array(); parse_output($output, $parts, 0); $last_part = ''; $last_part_ver = 0; usort($parts, 'compare_import_versions'); foreach ($parts as $part) { if ($part["version"] > $last_part_ver) { $last_part_ver = $part["version"]; $last_part = $part["body"]; } if (isset($part["pagename"])) { $pagename = urldecode($part["pagename"]); $version = urldecode($part["version"]); $author = urldecode($part["author"]); $lastmodified = $part["lastmodified"];
function process_inbound_mail($forumId) { // require_once ("lib/webmail/pop3.php"); require_once "lib/webmail/net_pop3.php"; require_once "lib/mail/mimelib.php"; //require_once ("lib/webmail/mimeDecode.php"); include_once "lib/webmail/class.rc4crypt.php"; include_once "lib/webmail/htmlMimeMail.php"; $info = $this->get_forum($forumId); // for any reason my sybase test machine adds a space to // the inbound_pop_server field in the table. $info["inbound_pop_server"] = trim($info["inbound_pop_server"]); if (!$info["inbound_pop_server"] || empty($info["inbound_pop_server"])) { return; } $pop3 = new Net_POP3(); $pop3->connect($info["inbound_pop_server"]); $pop3->login($info["inbound_pop_user"], $info["inbound_pop_password"]); if (!$pop3) { return; } $mailsum = $pop3->numMsg(); $pop3->disconnect(); for ($i = 1; $i <= $mailsum; $i++) { // Just changed the code to close and re-open the POP3 session for // each message; it used to try to retrieve everything in one // session. // // We close and re-open for each message because POP3 won't // delete mail until the client quits (so you can back out of // accidental deletions in a real user client). This doesn't apply // here, and as it stands if the mailbox gets very full, we end up // hitting the mailbox over and over without changing anything, // because eventually the session times out. // // As a side effect, $i doesn't really get used (we're always // retrieving the first message). // // -Robin Powell, 8 Nov 2004 $pop3->connect($info["inbound_pop_server"]); $pop3->login($info["inbound_pop_user"], $info["inbound_pop_password"]); $aux = $pop3->getParsedHeaders(1); // If the connection is done, or the mail has an error, or whatever, // we try to delete the current mail (because something is wrong with it) // and continue on. --rlpowell if ($aux == FALSE) { $pop3->deleteMsg(1); continue; } if (!isset($aux["From"])) { $aux['From'] = $aux['Return-path']; } preg_match('/<?([-!#$%&\'*+\\.\\/0-9=?A-Z^_`a-z{|}~]+@[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\\.[-!#$%&\'*+\\.\\/0-9=?A-Z^_`a-z{|}~]+)>?/', $aux["From"], $mail); $email = $mail[1]; $full = $pop3->getMsg(1); $message = $pop3->getBody(1); // print( "<pre>" ); // print_r( $full ); // print( "</pre>" ); $output = mime::decode($full); //unset ($parts); //$this->parse_output($output, $parts, 0); // print( "<pre>" ); // print_r( $output ); // print( "</pre>" ); if (isset($output["text"][0])) { $body = $output["text"][0]; } elseif (isset($output['parts'][0]["text"][0])) { $body = $output['parts'][0]["text"][0]; } elseif (isset($output['body'])) { $body = $output['body']; } else { $body = ""; } // print( "<pre>" ); // print_r( $body ); // print( "</pre>" ); // Remove 're:' and [forum]. -rlpowell $title = trim(preg_replace("/[rR][eE]:/", "", preg_replace("/\\[[-A-Za-z _:]*\\]/", "", $output['header']['subject']))); if (stristr($aux['Subject'], "=?iso-8859-1?") == $aux['Subject']) { $title = utf8_encode($title); } //Todo: check permissions $message_id = substr($output['header']["message-id"], 1, strlen($output['header']["message-id"]) - 2); if (isset($output['header']["in-reply-to"])) { $in_reply_to = substr($output['header']["in-reply-to"], 1, strlen($output['header']["in-reply-to"]) - 2); } else { $in_reply_to = ''; } // Determine user from email $userName = $this->getOne("select `login` from `users_users` where `email`=?", array($email)); if (!$userName) { $user = ''; } // Determine if the thread already exists. $parentId = $this->getOne("select `threadId` from `tiki_comments` where\n\t\t `object`=? and `objectType` = 'forum' and\n\t\t `parentId`=0 and `title`=?", array($forumId, $title)); // print( "<pre>parentid:" ); // print_r( $parentId ); // print( "</pre>" ); if (!$parentId) { // No thread already; create it. $temp_msid = ''; $parentId = $this->post_new_comment('forum:' . $forumId, 0, $userName, $title, sprintf(tra("Use this thread to discuss the %s page."), "[tiki-index.php?page={$title}|{$title}]"), $temp_msid, $in_reply_to); $this->register_forum_post($forumId, 0); // First post is in reply to this one $in_reply_to = $temp_msid; } // post $threadid = $this->post_new_comment('forum:' . $forumId, $parentId, $userName, $title, $body, $message_id, $in_reply_to); $this->register_forum_post($forumId, $parentId); // Process attachments if (array_key_exists('parts', $output) && count($output['parts']) > 1) { foreach ($output['parts'] as $part) { if (array_key_exists('disposition', $part) && $part['disposition'] == "attachment") { if (strlen($part['d_parameters']['filename']) > 0) { $part_name = $part['d_parameters']['filename']; } else { $part_name = "Unnamed File"; } $forum_info = $this->get_forum($forumId); $this->add_thread_attachment($forum_info, $threadid, '', $part['body'], $part_name, $part['type'], strlen($part['body']), 1); } } } // Deal with mail notifications. if (array_key_exists('outbound_mails_reply_link', $info) && $info['outbound_mails_for_inbound_mails'] == 'y') { //phpinfo(); include_once 'lib/notifications/notificationemaillib.php'; sendForumEmailNotification('forum_post_thread', $threadid, $info, $title, $body, $userName, $title, $message_id, $in_reply_to, $threadid, $parentId); } $pop3->deleteMsg(1); $pop3->disconnect(); } }
function process_inbound_mail($forumId) { global $prefs; require_once "lib/webmail/net_pop3.php"; require_once "lib/mail/mimelib.php"; $info = $this->get_forum($forumId); // for any reason my sybase test machine adds a space to // the inbound_pop_server field in the table. $info["inbound_pop_server"] = trim($info["inbound_pop_server"]); if (!$info["inbound_pop_server"] || empty($info["inbound_pop_server"])) { return; } $pop3 = new Net_POP3(); $pop3->connect($info["inbound_pop_server"]); $pop3->login($info["inbound_pop_user"], $info["inbound_pop_password"]); if (!$pop3) { return; } $mailSum = $pop3->numMsg(); //we don't want the operation to time out... this would result in the same messages being imported over and over... //(messages are only removed from the pop server on a gracefull connection termination... ie .not php or webserver a timeout) //$maximport should be in a admin config screen, but I don't know how to do that yet. $maxImport = 10; if ($mailSum > $maxImport) { $mailSum = $maxImport; } for ($i = 1; $i <= $mailSum; $i++) { //echo 'loop ' . $i; $aux = $pop3->getParsedHeaders($i); // If the mail came from Tiki, we don't need to add it again if (isset($aux['X-Tiki']) && $aux['X-Tiki'] == 'yes') { $pop3->deleteMsg($i); continue; } // If the connection is done, or the mail has an error, or whatever, // we try to delete the current mail (because something is wrong with it) // and continue on. --rlpowell if ($aux == FALSE) { $pop3->deleteMsg($i); continue; } //echo '<pre>'; //print_r ($aux); //echo '</pre>'; if (!isset($aux['From'])) { if (isset($aux['Return-path'])) { $aux['From'] = $aux['Return-path']; } else { $aux['From'] = ""; $aux['Return-path'] = ""; } } //try to get the date from the email: $postDate = strtotime($aux['Date']); if ($postDate == false) { $postDate = $this->now; } //save the original email address, if we don't get a user match, then we //can at least give some info about the poster. $original_email = $aux["From"]; //fix mailman addresses, or there is no chance to get a match $aux["From"] = str_replace(' at ', '@', $original_email); preg_match('/<?([-!#$%&\'*+\\.\\/0-9=?A-Z^_`a-z{|}~]+@[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\\.[-!#$%&\'*+\\.\\/0-9=?A-Z^_`a-z{|}~]+)>?/', $aux["From"], $mail); // should we throw out emails w/ invalid (possibly obfusicated) email addressses? //this should be an admin option, but I don't know how to put it there yet. $throwOutInvalidEmails = false; if (!array_key_exists(1, $mail)) { if ($throwOutInvalidEmails) { continue; } } $email = $mail[1]; $full = $pop3->getMsg($i); $mimelib = new mime(); $output = $mimelib->decode($full); $body = ''; if ($output['type'] == 'multipart/report') { // mimelib doesn't seem to parse error reports properly $pop3->deleteMsg($i); // and we almost certainly don't want them in the forum continue; // so do what exactly? log them somewhere? TODO } require_once 'lib/htmlpurifier_tiki/HTMLPurifier.tiki.php'; if ($prefs['feature_forum_parse'] === 'y' && $prefs['forum_inbound_mail_parse_html'] === 'y') { $body = $mimelib->getPartBody($output, 'html'); if ($body) { // on some systems HTMLPurifier fails with smart quotes in the html $body = $mimelib->cleanQuotes($body); // some emails have invalid font and span tags that create incorrect purifying of lists $body = preg_replace_callback('/\\<(ul|ol).*\\>(.*)\\<\\/(ul|ol)\\>/Umis', array($this, 'process_inbound_mail_cleanlists'), $body); // Clean the string using HTML Purifier next $body = HTMLPurifier($body); // html emails require some speciaal handling $body = preg_replace('/--(.*)--/', '~np~--$1--~/np~', $body); // disable strikethough syntax $body = preg_replace('/\\{(.*)\\}/', '~np~{$1}~/np~', $body); // disable plugin type things // special handling for MS links which contain underline tags in the label which wiki doesn't like $body = preg_replace('/(\\<a .*\\>)\\<font .*\\>\\<u\\>(.*)\\<\\/u\\>\\<\\/font\\>\\<\\/a\\>/Umis', '$1$2</a>', $body); $body = str_replace("<br /><br />", "<br /><br /><br />", $body); // double linebreaks seem to work better as three? $body = TikiLib::lib('edit')->parseToWiki($body); $body = str_replace("\n\n", "\n", $body); // for some reason emails seem to get line feeds quadrupled $body = preg_replace('/\\[\\[(.*?)\\]\\]/', '[~np~~/np~[$1]]', $body); // links surrounded by [square brackets] need help } } if (!$body) { $body = $mimelib->getPartBody($output, 'text'); if (empty($body)) { // no text part so look for html $body = $mimelib->getPartBody($output, 'html'); $body = HTMLPurifier($body); $body = $this->htmldecode(strip_tags($body)); $body = str_replace("\n\n", "\n", $body); // and again $body = str_replace("\n\n", "\n", $body); } if ($prefs['feature_forum_parse'] === 'y') { $body = preg_replace('/--(.*)--/', '~np~--$1--~/np~', $body); // disable strikethough if... $body = preg_replace('/\\{(.*)\\}/', '~np~\\{$1\\}~/np~', $body); // disable plugin type things } $body = $mimelib->cleanQuotes($body); } if (!empty($info['outbound_mails_reply_link']) && $info['outbound_mails_reply_link'] === 'y') { $body = preg_replace('/^.*?Reply Link\\: \\<[^\\>]*\\>.*\\r?\\n/m', '', $body); // remove previous reply links to reduce clutter and confusion // remove "empty" lines at the end $lines = preg_split("/(\r\n|\n|\r)/", $body); $body = ''; $len = count($lines) - 1; $found = false; for ($line = $len; $line >= 0; $line--) { if ($found || !preg_match('/^\\s*\\>*\\s*[\\-]*\\s*$/', $lines[$line])) { $body = "{$lines[$line]}\r\n{$body}"; $found = true; } } } // Remove 're:' and [forum]. -rlpowell $title = trim(preg_replace("/[rR][eE]:/", "", preg_replace("/\\[[-A-Za-z _:]*\\]/", "", $output['header']['subject']))); $title = $mimelib->cleanQuotes($title); // trim off < and > from message-id $message_id = substr($output['header']["message-id"], 1, strlen($output['header']["message-id"]) - 2); if (isset($output['header']["in-reply-to"])) { $in_reply_to = substr($output['header']["in-reply-to"], 1, strlen($output['header']["in-reply-to"]) - 2); } else { $in_reply_to = ''; } // Determine user from email $userName = $this->table('users_users')->fetchOne('login', array('email' => $email)); //use anonomus name feature if we don't have a real name if (!$userName) { $anonName = $original_email; } //Todo: check permissions // Determine if the thread already exists first by looking for a mail this is a reply to. if (!empty($in_reply_to)) { $parentId = $this->table('tiki_comments')->fetchOne('threadId', array('object' => $forumId, 'objectType' => 'forum', 'message_id' => $in_reply_to)); } else { $parentId = 0; } // if not, check if there's a topic with exactly this title if (!$parentId) { $parentId = $this->table('tiki_comments')->fetchOne('threadId', array('object' => $forumId, 'objectType' => 'forum', 'parentId' => 0, 'title' => $title)); } if (!$parentId) { // create a thread to discuss a wiki page if the feature is on AND the page exists if ($prefs['feature_wiki_discuss'] === 'y' && TikiLib::lib('tiki')->page_exists($title)) { // No thread already; create it. $temp_msid = ''; $parentId = $this->post_new_comment('forum:' . $forumId, 0, $userName, $title, sprintf(tra("Use this thread to discuss the %s page."), "(({$title}))"), $temp_msid, $in_reply_to); $this->register_forum_post($forumId, 0); // First post is in reply to this one $in_reply_to = $temp_msid; } else { $parentId = 0; } } // post $threadid = $this->post_new_comment('forum:' . $forumId, $parentId, $userName, $title, $body, $message_id, $in_reply_to, 'n', '', '', '', $anonName, $postDate); $this->register_forum_post($forumId, $parentId); // Process attachments if (array_key_exists('parts', $output) && count($output['parts']) > 1) { $forum_info = $this->get_forum($forumId); if ($forum_info['att'] != 'att_no') { $errors = array(); foreach ($output['parts'] as $part) { if (array_key_exists('disposition', $part)) { if ($part['disposition'] == 'attachment') { if (!empty($part['d_parameters']['filename'])) { $part_name = $part['d_parameters']['filename']; } else { if (preg_match('/filename=([^;]*)/', $part['d_parameters']['atend'], $mm)) { // not sure what this is but it seems to have the filename in it $part_name = $mm[1]; } else { $part_name = "Unnamed File"; } } $this->add_thread_attachment($forum_info, $threadid, $errors, $part_name, $part['type'], strlen($part['body']), 1, '', '', $part['body']); } elseif ($part['disposition'] == 'inline') { if (!empty($part['parts'])) { foreach ($part['parts'] as $p) { $this->add_thread_attachment($forum_info, $threadid, $errors, '-', $p['type'], strlen($p['body']), 1, '', '', $p['body']); } } else { if (!empty($part['body'])) { $this->add_thread_attachment($forum_info, $threadid, $errors, '-', $part['type'], strlen($part['body']), 1, '', '', $part['body']); } } } } } } } // Deal with mail notifications. if (array_key_exists('outbound_mails_reply_link', $info) && $info['outbound_mails_for_inbound_mails'] == 'y') { include_once 'lib/notifications/notificationemaillib.php'; sendForumEmailNotification('forum_post_thread', $threadid, $info, $title, $body, $userName, $title, $message_id, $in_reply_to, $threadid, $parentId); } $pop3->deleteMsg($i); } $pop3->disconnect(); }
if ($aux === FALSE) { $content .= "Headers not parsed.<br />"; } else { // else $aux not FALSE if (!isset($aux["From"])) { $aux['From'] = $aux['Return-path']; } $fromEmail = $aux["From"]; $fromEmail = str_replace('<', '', $fromEmail); $fromEmail = str_replace('>', '', $fromEmail); preg_match('/<?([-!#$%&\'*+\\.\\/0-9=?A-Z^_`a-z{|}~]+@[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\\.[-!#$%&\'*+\\.\\/0-9=?A-Z^_`a-z{|}~]+)>?/', $aux["From"], $mail); $email_from = $mail[1]; $aux["msgid"] = $i; $aux["realmsgid"] = preg_replace('/[<>]/', '', $aux["Message-ID"]); $message = $pop3->getMsg($i); $mimelib = new mime(); $output = $mimelib->decode($message); $content .= "<br />Reading a request.<br />From: " . $aux["From"] . "<br />Subject: " . $output['header']['subject'] . "<br />"; $content .= "sender email: " . $email_from . "<br />"; $aux["sender"]["user"] = $userlib->get_user_by_email($email_from); $content .= "sender user: "******"sender"]["user"] . "<br />"; $cantUseMailIn = $acc["anonymous"] == 'n' && empty($aux["sender"]["user"]); if ($cantUseMailIn) { $errorMsg = "Anonymous user access denied, sending auto-reply to email address: " . $fromEmail . "<br />"; $logslib->add_log('mailin', mailin_preplog($errorMsg), $logUser); $content .= $errorMsg; $mail = new TikiMail(); $mail->setFrom($acc["account"]); $l = $prefs['language']; $mail->setSubject(tra('Tiki mail-in auto-reply', $l)); $mail->setText(tra("Sorry, you can't use this feature.", $l));
$hash['contributions'] = $_REQUEST['contributions']; } if (!empty($_REQUEST['contributors'])) { $hash['contributors'] = $_REQUEST['contributors']; } if (isset($_FILES['userfile1']) && is_uploaded_file($_FILES['userfile1']['tmp_name'])) { check_ticket('edit-page'); require "lib/mail/mimelib.php"; $fp = fopen($_FILES['userfile1']['tmp_name'], "rb"); $data = ''; while (!feof($fp)) { $data .= fread($fp, 8192 * 16); } fclose($fp); $name = $_FILES['userfile1']['name']; $mimelib = new mime(); $output = $mimelib->decode($data); $parts = array(); parse_output($output, $parts, 0); $last_part = ''; $last_part_ver = 0; usort($parts, 'compare_import_versions'); foreach ($parts as $part) { if ($part["version"] > $last_part_ver) { $last_part_ver = $part["version"]; $last_part = $part["body"]; } if (isset($part["pagename"])) { $pagename = urldecode($part["pagename"]); $version = urldecode($part["version"]); $author = urldecode($part["author"]);
$pop3 = new Net_Pop3(); $pop3->connect($acc["pop"]); $pop3->login($acc["username"], $acc["pass"]); $mailsum = $pop3->numMsg(); for ($i = 1; $i <= $mailsum; $i++) { $aux = $pop3->getParsedHeaders($i); var_dump($aux); if (!isset($aux["From"])) { $aux['From'] = $aux['Return-path']; } preg_match('/<?([-!#$%&\'*+\\.\\/0-9=?A-Z^_`a-z{|}~]+@[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\\.[-!#$%&\'*+\\.\\/0-9=?A-Z^_`a-z{|}~]+)>?/', $aux["From"], $mail); $email_from = $mail[1]; $aux["msgid"] = $i; $aux["realmsgid"] = ereg_replace("[<>]", "", $aux["Message-ID"]); $message = $pop3->getMsg($i); $output = mime::decode($message); //mailin_parse_output($output, $parts, 0); $content .= "Reading a request.<br />From: " . $aux["From"] . "<br />Subject: " . $output['header']['subject'] . "<br />"; $content .= "sender email: " . $email_from . "<br />"; $aux["sender"]["user"] = $userlib->get_user_by_email($email_from); $content .= "sender user: "******"sender"]["user"] . "<br />"; $cantUseMailIn = $acc["anonymous"] == 'n' && empty($aux["sender"]["user"]); if ($cantUseMailIn) { $content .= "Anonymous user acces denied, sending auto-reply to email address: " . $aux["From"] . "<br />"; $mail = new TikiMail(); $mail->setFrom($acc["account"]); $c = $tikilib->get_preference("default_mail_charset", "utf8"); $mail->setHeadCharset($c); $mail->setTextCharset($c); $l = $tikilib->get_preference("language", "en"); $mail->setSubject(tra('Tiki mail-in auto-reply', $l));