class.uebimiau.php

来自「通达OA2007SE源代码 非常好的」· PHP 代码 · 共 868 行 · 第 1/2 页

PHP
868
字号
<?
  class uebimiau_core
  {
    var $mail_connection = 0;
    var $mail_server = 'localhost';
    var $mail_port = 110;
    var $mail_error_msg = '';
    var $mail_user = 'unknown';
    var $mail_pass = '';
    var $mail_email = 'unknown@localhost';
    var $mail_protocol = 'pop3';
    var $use_html = false;
    var $charset = 'iso-8859-1';
    var $timezone = '+0000';
    var $debug = false;
    var $user_folder = './';
    var $temp_folder = './';
    var $timeout = 10;
    var $displayimages = false;
    var $save_temp_attachs = true;
    var $_msgbody = '';
    var $_content = array ();
    var $_sid = '';
    function _get_headers_from_cache ($strfile)
    {
      if (!file_exists ($strfile))
      {
        return null;
      }
      $f = fopen ($strfile, 'rb');
      while (!feof ($f))
      {
        ($result .= (chop (fread ($f, 1024)).'
'));
        $pos = strpos ($result, '
');
        if (!($pos === false))
        {
          $result = substr ($result, 0, $pos);
          break;
        }
      }
      fclose ($f);
      unset ($f);
      unset ($pos);
      unset ($strfile);
      return $result;
    }
    function _read_file ($strfile)
    {
      if ((($strfile == '') OR !file_exists ($strfile)))
      {
        return null;
      }
      $fd = fopen ($strfile, 'rb');
      while (!feof ($fd))
      {
        ($result .= (chop (fgets ($fd, 65536)).'
'));
      }
      fclose ($fd);
      return $result;
    }
    function _save_file ($filename, $content)
    {
      $tmpfile = fopen ($filename, 'wb');
      fwrite ($tmpfile, $content);
      fclose ($tmpfile);
      unset ($content);
      unset ($tmpfile);
    }
    function _rmdirr ($location)
    {
      if ((substr ($location, -1) != '/'))
      {
        $location = ($location.'/');
      }
      $all = opendir ($location);
      while ($file = readdir ($all))
      {
        if (((is_dir (($location.$file)) AND ($file != '..')) AND ($file != '.')))
        {
          $this->_RmdirR (($location.$file));
          unset ($file);
          continue;
        }
        else
        {
          if (!is_dir (($location.$file)))
          {
            unlink (($location.$file));
            unset ($file);
            continue;
          }
          continue;
        }
      }
      closedir ($all);
      unset ($all);
      rmdir ($location);
    }
    function mime_encode_headers ($string)
    {
      if (($string == ''))
      {
        return null;
      }
      if (!eregi ((''.'^([[:print:]]*)$'), $string))
      {
        $string = (((('=?'.$this->charset).'?Q?').str_replace ('+', '_', str_replace ('%', '=', urlencode ($string)))).'?=');
      }
      return $string;
    }
    function add_body ($strbody)
    {
      if (($this->_msgbody == ''))
      {
        $this->_msgbody = $strbody;
      }
      else
      {
        ($this->_msgbody .= ((''.'
<br>
<br>
<hr>
<br>
').$strbody));
      }
    }
    function decode_mime_string ($subject)
    {
      $string = $subject;
      if (($pos = strpos ($string, '=?') === false))
      {
        return $string;
      }
      while (!($pos === false))
      {
        ($newresult .= substr ($string, 0, $pos));
        $string = substr ($string, ($pos + 2), strlen ($string));
        $intpos = strpos ($string, '?');
        $charset = substr ($string, 0, $intpos);
        $enctype = strtolower (substr ($string, ($intpos + 1), 1));
        $string = substr ($string, ($intpos + 3), strlen ($string));
        $endpos = strpos ($string, '?=');
        $mystring = substr ($string, 0, $endpos);
        $string = substr ($string, ($endpos + 2), strlen ($string));
        if (($enctype == 'q'))
        {
          $mystring = quoted_printable_decode (ereg_replace ('_', ' ', $mystring));
        }
        else
        {
          if (($enctype == 'b'))
          {
            $mystring = base64_decode ($mystring);
          }
        }
        ($newresult .= $mystring);
        $pos = strpos ($string, '=?');
      }
      $result = ($newresult.$string);
      if (ereg ('koi8', $subject))
      {
        $result = convert_cyr_string ($result, 'k', 'w');
      }
      return $result;
    }
    function decode_header ($header)
    {
      $headers = explode ('
', $header);
      $decodedheaders = array ();
      for ($i = 0; ($i < count ($headers)); ++$i)
      {
        $thisheader = trim ($headers[$i]);
        if (!empty ($thisheader))
        {
          if (!ereg ('^[A-Z0-9a-z_-]+:', $thisheader))
          {
            ($decodedheaders[$lasthead] .= ((''.' ').$thisheader));
            continue;
          }
          else
          {
            $dbpoint = strpos ($thisheader, ':');
            $headname = strtolower (substr ($thisheader, 0, $dbpoint));
            $headvalue = trim (substr ($thisheader, ($dbpoint + 1)));
            if (($decodedheaders[$headname] != ''))
            {
              ($decodedheaders[$headname] .= ((''.'; ').$headvalue));
            }
            else
            {
              $decodedheaders[$headname] = $headvalue;
            }
            $lasthead = $headname;
            continue;
          }
          continue;
        }
      }
      return $decodedheaders;
    }
    function get_names ($strmail)
    {
      $ARfrom = array ();
      $strmail = stripslashes (ereg_replace ('	', '', ereg_replace ('
', '', ereg_replace ('
', '', $strmail))));
      if ((trim ($strmail) == ''))
      {
        return $ARfrom;
      }
      $armail = array ();
      $counter = 0;
      $inthechar = 0;
      $chartosplit = ',;';
      $protectchar = '"';
      $temp = '';
      $lt = '<';
      $gt = '>';
      $closed = 1;
      for ($i = 0; ($i < strlen ($strmail)); ++$i)
      {
        $thischar = $strmail[$i];
        if ((($thischar == $lt) AND $closed))
        {
          $closed = 0;
        }
        if ((($thischar == $gt) AND !$closed))
        {
          $closed = 1;
        }
        if (($thischar == $protectchar))
        {
          $inthechar = ($inthechar ? 0 : 1);
        }
        if (((!(strpos ($chartosplit, $thischar) === false) AND !$inthechar) AND $closed))
        {
          $armail[] = $temp;
          $temp = '';
          continue;
        }
        else
        {
          ($temp .= $thischar);
          continue;
        }
      }
      if ((trim ($temp) != ''))
      {
        $armail[] = trim ($temp);
      }
      for ($i = 0; ($i < count ($armail)); ++$i)
      {
        $thisPart = trim (eregi_replace ((''.'^"(.*)"$'), '\\1', trim ($armail[$i])));
        if (($thisPart != ''))
        {
          if (eregi ('(.*)<(.*)>', $thisPart, $regs))
          {
            $email = trim ($regs[2]);
            $name = trim ($regs[1]);
          }
          else
          {
            if (eregi ((''.'([-a-z0-9_$+.]+@[-a-z0-9_.]+[-a-z0-9_]+)((.*))'), $thisPart, $regs))
            {
              $email = $regs[1];
              $name = $regs[2];
            }
            else
            {
              $email = $thisPart;
            }
          }
          $email = preg_replace ('/<(.*)\\>/', '\\1', $email);
          $name = preg_replace ('/"(.*)"/', '\\1', trim ($name));
          $name = preg_replace ('/\\((.*)\\)/', '\\1', $name);
          if (($name == ''))
          {
            $name = $email;
          }
          if (($email == ''))
          {
            $email = $name;
          }
          $ARfrom[$i]['name'] = $this->decode_mime_string ($name);
          $ARfrom[$i]['mail'] = $email;
          unset ($name);
          unset ($email);
          continue;
        }
      }
      return $ARfrom;
    }
    function build_alternative_body ($ctype, $body)
    {
      $boundary = $this->get_boundary ($ctype);
      $part = $this->split_parts ($boundary, $body);
      $thispart = ($this->use_html ? $part[1] : $part[0]);
      $email = $this->fetch_structure ($thispart);
      $header = $email['header'];
      $body = $email['body'];
      $headers = $this->decode_header ($header);
      $body = $this->compile_body ($body, $headers['content-transfer-encoding'], $headers['content-type']);
      $this->add_body ($body);
    }
    function build_complex_body ($ctype, $body)
    {
      global $sid;
      global $lid;
      global $ix;
      global $folder;
      $Rtype = trim (substr ($ctype, (strpos ($ctype, 'type=') + 5), strlen ($ctype)));
      if ((strpos ($Rtype, ';') != 0))
      {
        $Rtype = substr ($Rtype, 0, strpos ($Rtype, ';'));
      }
      if (((substr ($Rtype, 0, 1) == '"') AND (substr ($Rtype, -1) == '"')))
      {
        $Rtype = substr ($Rtype, 1, (strlen ($Rtype) - 2));
      }
      $boundary = $this->get_boundary ($ctype);
      $part = $this->split_parts ($boundary, $body);
      for ($i = 0; ($i < count ($part)); ++$i)
      {
        $email = $this->fetch_structure ($part[$i]);
        $header = $email['header'];
        $body = $email['body'];
        $headers = $this->decode_header ($header);
        $ctype = $headers['content-type'];
        $cid = $headers['content-id'];
        $Actype = split (';', $headers['content-type']);
        $types = split ('/', $Actype[0]);
        $rctype = strtolower ($Actype[0]);
        $is_download = ((ereg ('name=', ($headers['content-disposition'].$headers['content-type'])) OR ($headers['content-id'] != '')) OR ($rctype == 'message/rfc822'));
        if (($rctype == 'multipart/alternative'))
        {
          $this->build_alternative_body ($ctype, $body);
          continue;
        }
        else
        {
          if ((($rctype == 'text/plain') AND !$is_download))
          {
            $body = $this->compile_body ($body, $headers['content-transfer-encoding'], $headers['content-type']);
            $this->add_body ($this->build_text_body ($body));
            continue;
          }
          else
          {
            if ((($rctype == 'text/html') AND !$is_download))
            {
              $body = $this->compile_body ($body, $headers['content-transfer-encoding'], $headers['content-type']);
              if (!$this->use_html)
              {
                $body = $this->build_text_body (strip_tags ($body));
              }
              $this->add_body ($body);
              continue;
            }
            else
            {
              if ($is_download)
              {
                $thisattach = $this->build_attach ($header, $body, $boundary, $i);
                $thisfile = ((((((((((((((((''.'download.php?sid=').$sid).'&tid=').$tid).'&lid=').$lid).'&folder=').urlencode ($folder)).'&ix=').$ix).'&bound=').base64_encode ($thisattach['boundary'])).'&part=').$thisattach['part']).'&filename=').urlencode ($thisattach['name']));
                $temp_attach = false;
                $filename = (((($this->user_folder.'_attachments/').md5 ($thisattach['boundary'])).'_').$thisattach['name']);
                if (($cid != ''))
                {
                  $temp_attach = true;
                  if ($this->save_temp_attachs)
                  {
                    ($thisfile .= '&cache=true');
                  }
                  if (((substr ($cid, 0, 1) == '<') AND (substr ($cid, -1) == '>')))
                  {
                    $cid = substr ($cid, 1, (strlen ($cid) - 2));
                  }
                  $cid = ((''.'cid:').$cid);
                  $this->_msgbody = str_replace ($cid, $thisfile, $this->_msgbody);
                }
                else
                {
                  if ($this->displayimages)
                  {
                    $ext = substr ($thisattach['name'], -4);
                    $allowed_ext = array ('.gif', '.jpg');
                    if (in_array ($ext, $allowed_ext))
                    {
                      $temp_attach = true;
                      if ($this->save_temp_attachs)
                      {
                        ($thisfile .= '&cache=true');
                      }
                      $this->add_body ((((''.'<img src="').$thisfile).'">'));
                    }
                  }
                }
                if (($temp_attach AND $this->save_temp_attachs))
                {
                  $this->save_attach ($header, $body, $filename);
                  continue;
                }
                continue;
              }
              $this->process_message ($header, $body);
              continue;
            }
            continue;
          }
          continue;
        }
      }
    }
    function build_text_body ($body)
    {
      $body = ereg_replace ('
', '', $body);
      $body = ereg_replace ('
', '<br>
', $this->make_link_clickable (htmlspecialchars ($body)));
      return (((''.'<font face="Courier New" size=2>').$body).'</font>');
    }
    function decode_qp ($text)
    {
      $text = ereg_replace ('
', '
', $text);
      $text = ereg_replace ('=
', '', $text);
      $text = ereg_replace ('

⌨️ 快捷键说明

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