maillist.php
来自「eGroupWare is a multi-user, web-based gr」· PHP 代码 · 共 497 行 · 第 1/2 页
PHP
497 行
#!/usr/bin/php -q<?php/**************************************************************************** copyright : (C) 2001-2003 Advanced Internet Designs Inc.* email : forum@prohost.org* $Id: maillist.php,v 1.5 2004/04/01 16:04:58 petere78 Exp $** This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or * (at your option) any later version.***************************************************************************/class fud_emsg{ var $subject, $body, $headers, $to, $from_email, $from_name, $ip, $msg_id; var $subject_cleanup_rgx, $body_cleanup_rgx, $subject_cleanup_rep, $body_cleanup_rep; var $user_id; var $reply_to_msg_id; var $reply_to, $thread_id; var $raw_msg; var $body_s, $body_sc; var $attachments; function read_data($data='') { $this->raw_msg = !$data ? file_get_contents("php://stdin") : $data; } function split_hdr_body() { if (!preg_match("!^(.*?)\r?\n\r?\n(.*)!s", $this->raw_msg, $m)) { return; } $this->body = $m[2]; $this->headers = $m[1]; } function format_header() { $this->headers = str_replace("\r\n", "\n", $this->headers); // cleanup multiline headers $this->headers = preg_replace("!\n(\t| )+!", ' ', $this->headers); $hdr = explode("\n", trim($this->headers)); $this->headers = array(); foreach ($hdr as $v) { $hk = substr($v, 0, ($p = strpos($v, ':'))); // Skip non-valid header lines if (empty($hk) || ($v[++$p] != ' ' && $v[$p] != "\t")) { continue; } $hv = substr($v, $p); $hk = strtolower(trim($hk)); if (!isset($this->headers[$hk])) { $this->headers[$hk] = decode_header_value($hv); } else { $this->headers[$hk] .= ' '.decode_header_value($hv); } } } function parse_multival_headers($val, $key) { if (($p = strpos($val, ';')) !== false) { $this->headers[$key] = strtolower(trim(substr($val, 0, $p))); $val = ltrim(substr($val, $p+1)); if (!empty($val) && preg_match_all('!([-A-Za-z]+)="?(.*?)"?\s*(;|$)!', $val, $m)) { $c = count($m[0]); for ($i=0; $i<$c; $i++) { $this->headers['__other_hdr__'][$key][strtolower($m[1][$i])] = $m[2][$i]; } } } else { $this->headers[$key] = strtolower(trim($val)); } } function handle_content_headers() { // This functions performs special handling needed for parsing message data if (isset($this->headers['content-type'])) { $this->parse_multival_headers($this->headers['content-type'], 'content-type'); } else { $this->headers['content-type'] = 'text/plain'; $this->headers['__other_hdr__']['content-type']['charset'] = 'us-ascii'; } if (isset($this->headers['content-disposition'])) { $this->parse_multival_headers($this->headers['content-disposition'], 'content-disposition'); } else { $this->headers['content-disposition'] = 'inline'; } if (isset($this->headers['content-transfer-encoding'])) { $this->parse_multival_headers($this->headers['content-transfer-encoding'], 'content-transfer-encoding'); } else { $this->headers['content-transfer-encoding'] = '7bit'; } } function boudry_split($boundry, $html) { $boundry = '--'.$boundry; $b_len = strlen($boundry); // Remove 1st & last boundry since they are not needed for our perpouses $this->body = substr($this->body, strpos($this->body, $boundry)+$b_len); $this->body = substr($this->body, 0, strrpos($this->body, $boundry)-$b_len-1); // Isolate boundry sections $tmp = explode($boundry, $this->body); $this->body_sc = 0; foreach ($tmp as $p) { // Parse inidividual body sections $this->body_s[$this->body_sc] = new fud_emsg; $this->body_s[$this->body_sc]->parse_input($html, $p, true); $this->body_sc++; } } function decode_body($html=0) { switch ($this->headers['content-type']) { case 'text/plain': $this->decode_message_body(); break; case 'text/html': $this->decode_message_body(); $this->body = (!$html ? strip_tags($this->body) : $this->body); break; case 'multipart/parallel': // Apparently same as multipart/mixed but order of body parts does not matter case 'multipart/report': // RFC1892 ( 1st part is human readable, identical to multipart/mixed ) case 'multipart/signed': // PGP or OpenPGP (appear same) ( 1st part is human readable ) case 'multipart/alternative': // various alternate formats of message most common html or text case 'multipart/related': // ignore those, contains urls/links to 'stuff' on the net case 'multipart/mixed': case 'message/rfc822': // *scary* if (!isset($this->headers['__other_hdr__']['content-type']['boundary'])) { $this->body = ''; return; } $this->boudry_split($this->headers['__other_hdr__']['content-type']['boundary'], $html); // In some cases in multi-part messages there will only be 1 body, // in those situations we assing that body and info to the primary message // and hide the fact this was multi-part message if ($this->body_sc == 1) { $this->body = $this->body_s[0]->body; $this->headers['__other_hdr__'] = $this->body_s[0]->headers['__other_hdr__']; } else if ($this->body_sc > 1) { // We got many bodies to pick from, Yey!. Lets find something we can use, // preference given to 'text/plain' or if not found go for 'text/html' $final_id = $html_id = null; for ($i = 0; $i < $this->body_sc; $i++) { switch ($this->body_s[$i]->headers['content-type']) { case 'text/html': if (!isset($html_id)) { $html_id = $i; } break; case 'text/plain': if (!isset($final_id)) { $final_id = $i; } break; } // look if message has any attached files if ($this->body_s[$i]->headers['content-disposition'] == 'attachment') { // Determine the file name if (isset($this->body_s[$i]->headers['__other_hdr__']['content-disposition']['filename'])) { $file_name = $this->body_s[$i]->headers['__other_hdr__']['content-disposition']['filename']; } else if (isset($this->body_s[$i]->headers['__other_hdr__']['content-type']['name'])) { $file_name = $this->body_s[$i]->headers['__other_hdr__']['content-type']['name']; } else { // No name for file, skipping continue; } $this->attachments[$file_name] = $this->body_s[$i]->body; } } if (!isset($final_id) && isset($html_id)) { $final_id = $html_id; } if (isset($final_id)) { $this->body = $this->body_s[$final_id]->body; if (isset($this->body_s[$final_id]->headers['__other_hdr__'])) { $this->headers['__other_hdr__'] = $this->body_s[$final_id]->headers['__other_hdr__']; } } else { $this->body = ''; } } else { // Bad mail client didn't format message properly. $this->body = ''; } break; default: $this->decode_message_body(); break; // case 'multipart/digest': will/can contain many messages, ignore for our perpouse } } function decode_message_body() { $this->body = decode_string($this->body, $this->headers['content-transfer-encoding']); } function parse_input($html=0, $data='', $internal=false) { $this->read_data($data); $this->split_hdr_body(); $this->format_header(); $this->handle_content_headers(); $this->decode_body($html); } function fetch_useful_headers() { $this->subject = $this->headers['subject']; // Attempt to Get Poster's IP from fields commonly used to store it if (isset($this->headers['x-posted-by'])) { $this->ip = parse_ip($this->headers['x-posted-by']); } else if (isset($this->headers['x-originating-ip'])) { $this->ip = parse_ip($this->headers['x-originating-ip']); } else if (isset($this->headers['x-senderip'])) { $this->ip = parse_ip($this->headers['x-senderip']); } else if (isset($this->headers['x-mdremoteip'])) { $this->ip = parse_ip($this->headers['x-mdremoteip']); } else if (isset($this->headers['received'])) { $this->ip = parse_ip($this->headers['received']); } // Fetch From email and Possible name if (preg_match('!(.*?)<(.*?)>!', $this->headers['from'], $matches)) { $this->from_email = trim($matches[2]); if (!empty($matches[1])) { $matches[1] = trim($matches[1]);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?