maillist.php

来自「eGroupWare is a multi-user, web-based gr」· PHP 代码 · 共 497 行 · 第 1/2 页

PHP
497
字号
				if ($matches[1][0] == '"' && substr($matches[1], -1) == '"') {					$this->from_name = substr($matches[1], 1, -1);				} else {					$this->from_name = $matches[1];				}			} else {				$this->from_name = $this->from_email;			}			if (preg_match('![^A-Za-z0-9\-_\s]!', $this->from_name)) {				$this->from_name = substr($this->from_email, 0, strpos($this->from_email, '@'));			}		} else {			$this->from_email = trim($this->headers['from']);			$this->from_name = substr($this->from_email, 0, strpos($this->from_email, '@'));		}		if (empty($this->from_email) || empty($this->from_name)) {			mlist_error_log("no name or email for ".$this->headers['from'], $this->raw_msg);		}		if (isset($this->headers['message-id'])) {			$this->msg_id = substr(trim($this->headers['message-id']), 1, -1);		} else {			mlist_error_log("No message id", $this->raw_msg);		}		// This fetches the id of the message if this is a reply to an existing message		if (!empty($this->headers['in-reply-to']) && preg_match('!.*<([^>]+)>$!', trim($this->headers['in-reply-to']), $match)) {			$this->reply_to_msg_id = $match[1];		} else if (!empty($this->headers['references']) && preg_match('!.*<([^>]+)>!', trim($this->headers['references']), $match)) {			$this->reply_to_msg_id = $match[1];		}	}	function clean_up_data()	{		if ($this->subject_cleanup_rgx) {			$this->subject = trim(preg_replace($this->subject_cleanup_rgx, $this->subject_cleanup_rep, $this->subject));		}		if ($this->body_cleanup_rgx) {			$this->body = trim(preg_replace($this->body_cleanup_rgx, $this->body_cleanup_rep, $this->body));		}	}}function mlist_error_log($error, $msg_data, $level='WARNING'){	$error_log_path = $GLOBALS['ERROR_PATH'].'.mlist/error_log';	$err_msg_cpy = $GLOBALS['ERROR_PATH'].'.mlist/'.time().'_'.md5($msg_data);	if ($level != 'LOG') {		if (!($fp = fopen($err_msg_cpy, 'wb'))) {			exit("no perms to write ".$err_msg_cpy."\n");		}		fwrite($fp, $msg_data);		fclose($fp);	} else {		$err_msg_cpy = '';	}	if (!($fp = fopen($error_log_path, 'ab'))) {		exit("no perms to write ".$error_log_path."\n");	}	fwrite($fp, $level." :: ".date("r")." :: ".$error." :: ".$err_msg_cpy."\n");	fclose($fp);	if ($level == 'ERROR') {		exit;	}}	define('forum_debug', 1);	if (!ini_get("register_argc_argv")) {		exit("Enable the 'register_argc_argv' php.ini directive\n");	}	if ($_SERVER['argc'] < 2) {		exit("Missing Forum ID Paramater\n");	}	if (strncmp($_SERVER['argv'][0], '.', 1)) {		require (dirname($_SERVER['argv'][0]) . '/GLOBALS.php');	} else {		require (getcwd() . '/GLOBALS.php');	}	if (!($FUD_OPT_1 & 1)) {		exit("Forum is currently disabled.\n");	}	$GLOBALS['phpgw_info']['flags']['currentapp'] = 'fudforum';	$egw_dir = realpath($GLOBALS['WWW_ROOT_DISK'] . "../../");	require_once($egw_dir. '/header.inc.php');	if (!empty($GLOBALS['phpgw_info']['server']['use_adodb'])) {		// open your own connection, as ADOdb does not export the use Link_ID	        switch ($GLOBALS['phpgw_info']['server']['db_type']) {	        	case 'mysql':	                	$func = $GLOBALS['phpgw_info']['server']['db_persistent'] ? 'mysql_pconnect' : 'mysql_connect';				define('fud_sql_lnk',$func($GLOBALS['phpgw']->db->Host,				$GLOBALS['phpgw']->db->User, $GLOBALS['phpgw']->db->Password));	                	mysql_select_db($GLOBALS['phpgw']->db->Database,fud_sql_lnk);	                        break;			case 'pgsql':				$func = $GLOBALS['phpgw_info']['server']['db_persistent'] ? 'pg_pconnect' : 'pg_connect';				define('fud_sql_lnk',$func('dbname='.$GLOBALS['phpgw']->db->Database.						' host='.$GLOBALS['phpgw']->db->Host.						' user='.$GLOBALS['phpgw']->db->User.						' password='.$GLOBALS['phpgw']->db->Password));				break;	                                                                                                                                                                                                                                                                                                                                                                                                        			default:				die('FUDforum only supports mysql or pgsql !!!');		}	} else {		define('fud_sql_lnk', $GLOBALS['phpgw']->db->Link_ID);	}	fud_use('err.inc');	fud_use('db.inc');	fud_use('imsg.inc');	fud_use('imsg_edt.inc');	fud_use('th.inc');	fud_use('th_adm.inc');	fud_use('wordwrap.inc');	fud_use('isearch.inc');	fud_use('replace.inc');	fud_use('forum.inc');	fud_use('rev_fmt.inc');	fud_use('iemail.inc');	fud_use('post_proc.inc');	fud_use('is_perms.inc');	fud_use('users.inc');	fud_use('users_reg.inc');	fud_use('attach.inc');	fud_use('rhost.inc');	fud_use('smiley.inc');	fud_use('fileio.inc');	fud_use('mlist.inc', true);	fud_use('scripts_common.inc', true);	define('sql_p', $DBHOST_TBL_PREFIX);	if (is_numeric($_SERVER['argv'][1])) {		$mlist = db_sab('SELECT * FROM '.sql_p.'mlist WHERE id='.$_SERVER['argv'][1]);	} else {		$mlist = db_sab("SELECT * FROM ".sql_p."mlist WHERE name='".addslashes($_SERVER['argv'][1])."'");	}	if (!$mlist) {		exit('Invalid list identifier');	}	$CREATE_NEW_USERS = $mlist->mlist_opt & 64;	$FUD_OPT_2 |= $FUD_OPT_2 &~ (1024|8388608);	$FUD_OPT_2 |= 128;	$frm = db_sab('SELECT id, forum_opt, message_threshold, (max_attach_size * 1024) AS max_attach_size, max_file_attachments FROM '.sql_p.'forum WHERE id='.$mlist->forum_id);	$emsg = new fud_emsg();	$emsg->subject_cleanup_rgx = $mlist->subject_regex_haystack;	$emsg->subject_cleanup_rep = $mlist->subject_regex_needle;	$emsg->body_cleanup_rgx = $mlist->body_regex_haystack;	$emsg->body_cleanup_rep = $mlist->body_regex_needle;	$emsg->parse_input($mlist->mlist_opt & 16);	$emsg->fetch_useful_headers();	$emsg->clean_up_data();	$msg_post = new fud_msg_edit;	// Handler for our own messages, which do not need to be imported.	if (isset($emsg->headers['x-fudforum']) && preg_match('!([A-Za-z0-9]{32}) <([0-9]+)>!', $emsg->headers['x-fudforum'], $m)) {		if ($m[1] == md5($GLOBALS['WWW_ROOT'])) {			q("UPDATE ".sql_p."msg SET mlist_msg_id='".addslashes($emsg->msg_id)."' WHERE id=".intval($m[2])." AND mlist_msg_id IS NULL");			if (db_affected()) {				exit;			}		}	}	$msg_post->body = apply_custom_replace($emsg->body);	if (!($mlist->mlist_opt & 16)) {		if ($frm->forum_opt & 16) {			$msg_post->body = tags_to_html($msg_post->body, 0);		} else {			$msg_post->body = nl2br($msg_post->body);		}	}	fud_wordwrap($msg_post->body);	$msg_post->subject = htmlspecialchars(apply_custom_replace($emsg->subject));	if (!strlen($msg_post->subject)) {		mlist_error_log("Blank Subject", $emsg->raw_msg);	}	if (!$emsg->from_email || !$emsg->from_name) {		$msg_post->poster_id = 0;	} else {		$msg_post->poster_id = match_user_to_post($emsg->from_email, $emsg->from_name, $mlist->mlist_opt & 64, $emsg->user_id);	}	$msg_post->ip_addr = $emsg->ip;	$msg_post->mlist_msg_id = addslashes($emsg->msg_id);	$msg_post->attach_cnt = 0;	$msg_post->poll_id = 0;	$msg_post->msg_opt = 2;	$msg_post->post_stamp = !empty($emsg->headers['date']) ? strtotime($emsg->headers['date']) : 0;	if ($msg_post->post_stamp < 1 || $msg_post->post_stamp > __request_timestamp__) {		mlist_error_log("Invalid Date", $emsg->raw_msg);		if (($p = strpos($emsg->headers['received'], '; ')) !== false) {			$p += 2;			$msg_post->post_stamp = strtotime(substr($emsg->headers['received'], $p, (strpos($emsg->headers['received'], '00 ', $p) + 2 - $p)));		}		if ($msg_post->post_stamp < 1 || $msg_post->post_stamp > __request_timestamp__) {			$msg_post->post_stamp = __request_timestamp__;		}	}	// try to determine whether this message is a reply or a new thread	list($msg_post->reply_to, $msg_post->thread_id) = get_fud_reply_id($mlist->mlist_opt & 32, $frm->id, $msg_post->subject, $emsg->reply_to_msg_id);	$msg_post->add($frm->id, $frm->message_threshold, 0, 0, false);	// Handle File Attachments	if ($mlist->mlist_opt & 8 && isset($emsg->attachments) && is_array($emsg->attachments)) {		foreach($emsg->attachments as $key => $val) {			$tmpfname = tempnam($TMP, 'FUDf_');			$fp = fopen($tmpfname, 'wb');			fwrite($fp, $val);			fclose($fp);			$id = attach_add(array('name' => $key, 'size' => strlen($val), 'tmp_name' => $tmpfname), $msg_post->poster_id, 0, 1);			$attach_list[$id] = $id;		}		if (isset($attach_list)) {			attach_finalize($attach_list, $msg_post->id);		}	}	if (!($mlist->mlist_opt & 1)) {		$msg_post->approve($msg_post->id, true);	}?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?