Advertisement
johnburn

Decode for TigerBRRS@waraxe.us

Jan 24th, 2012
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 29.00 KB | None | 0 0
  1. <?php
  2. class PHPMailer {
  3.     var $Priority = 1;
  4.     var $CharSet = "iso-8859-1";
  5.     var $ContentType = "text/plain";
  6.     var $Encoding = "8bit";
  7.     var $ErrorInfo = "";
  8.     var $From = "root@localhost";
  9.     var $FromName = "Root User";
  10.     var $Sender = "";
  11.     var $Subject = "";
  12.     var $Body = "";
  13.     var $AltBody = "";
  14.     var $WordWrap = 0;
  15.     var $Mailer = "mail";
  16.     var $Sendmail = "/usr/sbin/sendmail";
  17.     var $PluginDir = "";
  18.     var $Version = "1.72";
  19.     var $ConfirmReadingTo = "";
  20.     var $Hostname = "";
  21.     var $Host = "localhost";
  22.     var $Port = 25;
  23.     var $Helo = "";
  24.     var $SMTPAuth = true;
  25.     var $Username = "";
  26.     var $Password = "";
  27.     var $Timeout = 10;
  28.     var $SMTPDebug = false;
  29.     var $SMTPKeepAlive = false;
  30.     var $smtp = NULL;
  31.     var $to = array();
  32.     var $cc = array();
  33.     var $bcc = array();
  34.     var $ReplyTo = array();
  35.     var $attachment = array();
  36.     var $CustomHeader = array();
  37.     var $message_type = "";
  38.     var $boundary = array();
  39.     var $language = array();
  40.     var $error_count = 0;
  41.     var $LE = "\n";
  42.     function IsHTML($bool) {
  43.         if ($bool == true) $this->ContentType = "text/html";
  44.         else $this->ContentType = "text/plain";
  45.     }
  46.     function IsSMTP() {
  47.         $this->Mailer = "smtp";
  48.     }
  49.     function IsMail() {
  50.         $this->Mailer = "mail";
  51.     }
  52.     function IsSendmail() {
  53.         $this->Mailer = "sendmail";
  54.     }
  55.     function IsQmail() {
  56.         $this->Sendmail = "/var/qmail/bin/sendmail";
  57.         $this->Mailer = "sendmail";
  58.     }
  59.     function AddAddress($address, $name = "") {
  60.         $cur = count($this->to);
  61.         $this->to[$cur][0] = trim($address);
  62.         $this->to[$cur][1] = $name;
  63.     }
  64.     function AddCC($address, $name = "") {
  65.         $cur = count($this->cc);
  66.         $this->cc[$cur][0] = trim($address);
  67.         $this->cc[$cur][1] = $name;
  68.     }
  69.     function AddBCC($address, $name = "") {
  70.         $cur = count($this->bcc);
  71.         $this->bcc[$cur][0] = trim($address);
  72.         $this->bcc[$cur][1] = $name;
  73.     }
  74.     function AddReplyTo($address, $name = "") {
  75.         $cur = count($this->ReplyTo);
  76.         $this->ReplyTo[$cur][0] = trim($address);
  77.         $this->ReplyTo[$cur][1] = $name;
  78.     }
  79.     function Send() {
  80.         $header = "";
  81.         $body = "";
  82.         $result = true;
  83.         if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
  84.             $this->SetError($this->Lang("provide_address"));
  85.             return false;
  86.         }
  87.         if (!empty($this->AltBody)) $this->ContentType = "multipart/alternative";
  88.         $this->error_count = 0;
  89.         $this->SetMessageType();
  90.         $header.= $this->CreateHeader();
  91.         $body = $this->CreateBody();
  92.         if ($body == "") {
  93.             return false;
  94.         }
  95.         switch ($this->Mailer) {
  96.             case "sendmail":
  97.                 $result = $this->SendmailSend($header, $body);
  98.             break;
  99.             case "mail":
  100.                 $result = $this->MailSend($header, $body);
  101.             break;
  102.             case "smtp":
  103.                 $result = $this->SmtpSend($header, $body);
  104.             break;
  105.             default:
  106.                 $this->SetError($this->Mailer . $this->Lang("mailer_not_supported"));
  107.                 $result = false;
  108.             break;
  109.         }
  110.         return $result;
  111.     }
  112.     function SendmailSend($header, $body) {
  113.         if ($this->Sender != "") $sendmail = sprintf("%s -oi -f %s -t", $this->Sendmail, $this->Sender);
  114.         else $sendmail = sprintf("%s -oi -t", $this->Sendmail);
  115.         if (!@$mail = popen($sendmail, "w")) {
  116.             $this->SetError($this->Lang("execute") . $this->Sendmail);
  117.             return false;
  118.         }
  119.         fputs($mail, $header);
  120.         fputs($mail, $body);
  121.         $result = pclose($mail) >> 8 & 0xFF;
  122.         if ($result != 0) {
  123.             $this->SetError($this->Lang("execute") . $this->Sendmail);
  124.             return false;
  125.         }
  126.         return true;
  127.     }
  128.     function MailSend($header, $body) {
  129.         $to = "";
  130.         for ($i = 0;$i < count($this->to);$i++) {
  131.             if ($i != 0) {
  132.                 $to.= ", ";
  133.             }
  134.             $to.= $this->to[$i][0];
  135.         }
  136.         if ($this->Sender != "" && strlen(ini_get("safe_mode")) < 1) {
  137.             $old_from = ini_get("sendmail_from");
  138.             ini_set("sendmail_from", $this->Sender);
  139.             $params = sprintf("-oi -f %s", $this->Sender);
  140.             $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, $header, $params);
  141.         } else $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, $header);
  142.         if (isset($old_from)) ini_set("sendmail_from", $old_from);
  143.         if (!$rt) {
  144.             $this->SetError($this->Lang("instantiate"));
  145.             return false;
  146.         }
  147.         return true;
  148.     }
  149.     function SmtpSend($header, $body) {
  150.         include_once ($this->PluginDir . "class.smtp.php");
  151.         $error = "";
  152.         $bad_rcpt = array();
  153.         if (!$this->SmtpConnect()) return false;
  154.         $smtp_from = ($this->Sender == "") ? $this->From : $this->Sender;
  155.         if (!$this->smtp->Mail($smtp_from)) {
  156.             $error = $this->Lang("from_failed") . $smtp_from;
  157.             $this->SetError($error);
  158.             $this->smtp->Reset();
  159.             return false;
  160.         }
  161.         for ($i = 0;$i < count($this->to);$i++) {
  162.             if (!$this->smtp->Recipient($this->to[$i][0])) $bad_rcpt[] = $this->to[$i][0];
  163.         }
  164.         for ($i = 0;$i < count($this->cc);$i++) {
  165.             if (!$this->smtp->Recipient($this->cc[$i][0])) $bad_rcpt[] = $this->cc[$i][0];
  166.         }
  167.         for ($i = 0;$i < count($this->bcc);$i++) {
  168.             if (!$this->smtp->Recipient($this->bcc[$i][0])) $bad_rcpt[] = $this->bcc[$i][0];
  169.         }
  170.         if (count($bad_rcpt) > 0) {
  171.             for ($i = 0;$i < count($bad_rcpt);$i++) {
  172.                 if ($i != 0) {
  173.                     $error.= ", ";
  174.                 }
  175.                 $error.= $bad_rcpt[$i];
  176.             }
  177.             $error = $this->Lang("recipients_failed") . $error;
  178.             $this->SetError($error);
  179.             $this->smtp->Reset();
  180.             return false;
  181.         }
  182.         if (!$this->smtp->Data($header . $body)) {
  183.             $this->SetError($this->Lang("data_not_accepted"));
  184.             $this->smtp->Reset();
  185.             return false;
  186.         }
  187.         if ($this->SMTPKeepAlive == true) $this->smtp->Reset();
  188.         else $this->SmtpClose();
  189.         return true;
  190.     }
  191.     function SmtpConnect() {
  192.         if ($this->smtp == NULL) {
  193.             $this->smtp = new SMTP();
  194.         }
  195.         $this->smtp->do_debug = $this->SMTPDebug;
  196.         $hosts = explode(";", $this->Host);
  197.         $index = 0;
  198.         $connection = ($this->smtp->Connected());
  199.         while ($index < count($hosts) && $connection == false) {
  200.             if (preg_match('#(([a-z]+://)?[^:]+):(\d+)#i', $hosts[$index], $match)) {
  201.                 $host = $match[1];
  202.                 $port = $match[3];
  203.             } else {
  204.                 $host = $hosts[$index];
  205.                 $port = $this->Port;
  206.             }
  207.             if ($this->smtp->Connect($host, $port, $this->Timeout)) {
  208.                 if ($this->Helo != '') $this->smtp->Hello($this->Helo);
  209.                 else $this->smtp->Hello($this->ServerHostname());
  210.                 if ($this->SMTPAuth) {
  211.                     if (!$this->smtp->Authenticate($this->Username, $this->Password)) {
  212.                         $this->SetError($this->Lang("authenticate"));
  213.                         $this->smtp->Reset();
  214.                         $connection = false;
  215.                     }
  216.                 }
  217.                 $connection = true;
  218.             }
  219.             $index++;
  220.         }
  221.         if (!$connection) $this->SetError($this->Lang("connect_host"));
  222.         return $connection;
  223.     }
  224.     function SmtpClose() {
  225.         if ($this->smtp != NULL) {
  226.             if ($this->smtp->Connected()) {
  227.                 $this->smtp->Quit();
  228.                 $this->smtp->Close();
  229.             }
  230.         }
  231.     }
  232.     function SetLanguage($lang_type, $lang_path = "language/") {
  233.         if (file_exists($lang_path . 'phpmailer.lang-' . $lang_type . '.php')) include ($lang_path . 'phpmailer.lang-' . $lang_type . '.php');
  234.         else if (file_exists($lang_path . 'phpmailer.lang-en.php')) include ($lang_path . 'phpmailer.lang-en.php');
  235.         else {
  236.             $this->SetError("Could not load language file");
  237.             return false;
  238.         }
  239.         $this->language = $PHPMAILER_LANG;
  240.         return true;
  241.     }
  242.     function AddrAppend($type, $addr) {
  243.         $addr_str = $type . ": ";
  244.         $addr_str.= $this->AddrFormat($addr[0]);
  245.         if (count($addr) > 1) {
  246.             for ($i = 1;$i < count($addr);$i++) $addr_str.= ", " . $this->AddrFormat($addr[$i]);
  247.         }
  248.         $addr_str.= $this->LE;
  249.         return $addr_str;
  250.     }
  251.     function AddrFormat($addr) {
  252.         if (empty($addr[1])) $formatted = $addr[0];
  253.         else {
  254.             $formatted = $this->EncodeHeader($addr[1], 'phrase') . " <" . $addr[0] . ">";
  255.         }
  256.         return $formatted;
  257.     }
  258.     function WrapText($message, $length, $qp_mode = false) {
  259.         $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
  260.         $message = $this->FixEOL($message);
  261.         if (substr($message, -1) == $this->LE) $message = substr($message, 0, -1);
  262.         $line = explode($this->LE, $message);
  263.         $message = "";
  264.         for ($i = 0;$i < count($line);$i++) {
  265.             $line_part = explode(" ", $line[$i]);
  266.             $buf = "";
  267.             for ($e = 0;$e < count($line_part);$e++) {
  268.                 $word = $line_part[$e];
  269.                 if ($qp_mode and (strlen($word) > $length)) {
  270.                     $space_left = $length - strlen($buf) - 1;
  271.                     if ($e != 0) {
  272.                         if ($space_left > 20) {
  273.                             $len = $space_left;
  274.                             if (substr($word, $len - 1, 1) == "=") $len--;
  275.                             elseif (substr($word, $len - 2, 1) == "=") $len-= 2;
  276.                             $part = substr($word, 0, $len);
  277.                             $word = substr($word, $len);
  278.                             $buf.= " " . $part;
  279.                             $message.= $buf . sprintf("=%s", $this->LE);
  280.                         } else {
  281.                             $message.= $buf . $soft_break;
  282.                         }
  283.                         $buf = "";
  284.                     }
  285.                     while (strlen($word) > 0) {
  286.                         $len = $length;
  287.                         if (substr($word, $len - 1, 1) == "=") $len--;
  288.                         elseif (substr($word, $len - 2, 1) == "=") $len-= 2;
  289.                         $part = substr($word, 0, $len);
  290.                         $word = substr($word, $len);
  291.                         if (strlen($word) > 0) $message.= $part . sprintf("=%s", $this->LE);
  292.                         else $buf = $part;
  293.                     }
  294.                 } else {
  295.                     $buf_o = $buf;
  296.                     $buf.= ($e == 0) ? $word : (" " . $word);
  297.                     if (strlen($buf) > $length and $buf_o != "") {
  298.                         $message.= $buf_o . $soft_break;
  299.                         $buf = $word;
  300.                     }
  301.                 }
  302.             }
  303.             $message.= $buf . $this->LE;
  304.         }
  305.         return $message;
  306.     }
  307.     function SetWordWrap() {
  308.         if ($this->WordWrap < 1) return;
  309.         switch ($this->message_type) {
  310.             case "alt":
  311.             case "alt_attachment":
  312.                 $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
  313.             break;
  314.             default:
  315.                 $this->Body = $this->WrapText($this->Body, $this->WordWrap);
  316.             break;
  317.         }
  318.     }
  319.     function CreateHeader() {
  320.         $result = "";
  321.         $uniq_id = md5(uniqid(time()));
  322.         $this->boundary[1] = "b1_" . $uniq_id;
  323.         $this->boundary[2] = "b2_" . $uniq_id;
  324.         $result.= $this->HeaderLine("Date", $this->RFCDate());
  325.         if ($this->Sender == "") $result.= $this->HeaderLine("Return-Path", trim($this->From));
  326.         else $result.= $this->HeaderLine("Return-Path", trim($this->Sender));
  327.         if ($this->Mailer != "mail") {
  328.             if (count($this->to) > 0) $result.= $this->AddrAppend("To", $this->to);
  329.             else if (count($this->cc) == 0) $result.= $this->HeaderLine("To", "undisclosed-recipients:;");
  330.             if (count($this->cc) > 0) $result.= $this->AddrAppend("Cc", $this->cc);
  331.         }
  332.         $from = array();
  333.         $from[0][0] = trim($this->From);
  334.         $from[0][1] = $this->FromName;
  335.         $result.= $this->AddrAppend("From", $from);
  336.         if ((($this->Mailer == "sendmail") || ($this->Mailer == "mail")) && (count($this->bcc) > 0)) $result.= $this->AddrAppend("Bcc", $this->bcc);
  337.         if (count($this->ReplyTo) > 0) $result.= $this->AddrAppend("Reply-to", $this->ReplyTo);
  338.         if ($this->Mailer != "mail") $result.= $this->HeaderLine("Subject", $this->EncodeHeader(trim($this->Subject)));
  339.         $result.= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
  340.         $result.= $this->HeaderLine("X-Priority", $this->Priority);
  341.         $result.= $this->HeaderLine("X-Mailer", "PHPMailer [version " . $this->Version . "]");
  342.         if ($this->ConfirmReadingTo != "") {
  343.             $result.= $this->HeaderLine("Disposition-Notification-To", "<" . trim($this->ConfirmReadingTo) . ">");
  344.         }
  345.         for ($index = 0;$index < count($this->CustomHeader);$index++) {
  346.             $result.= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
  347.         }
  348.         $result.= $this->HeaderLine("MIME-Version", "1.0");
  349.         switch ($this->message_type) {
  350.             case "plain":
  351.                 $result.= $this->HeaderLine("Content-Transfer-Encoding", $this->Encoding);
  352.                 $result.= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
  353.             break;
  354.             case "attachments":
  355.             case "alt_attachments":
  356.                 if ($this->InlineImageExists()) {
  357.                     $result.= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", "multipart/related", $this->LE, $this->LE, $this->boundary[1], $this->LE);
  358.                 } else {
  359.                     $result.= $this->HeaderLine("Content-Type", "multipart/mixed;");
  360.                     $result.= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  361.                 }
  362.             break;
  363.             case "alt":
  364.                 $result.= $this->HeaderLine("Content-Type", "multipart/alternative;");
  365.                 $result.= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  366.             break;
  367.         }
  368.         if ($this->Mailer != "mail") $result.= $this->LE . $this->LE;
  369.         return $result;
  370.     }
  371.     function CreateBody() {
  372.         $result = "";
  373.         $this->SetWordWrap();
  374.         switch ($this->message_type) {
  375.             case "alt":
  376.                 $result.= $this->GetBoundary($this->boundary[1], "", "text/plain", "");
  377.                 $result.= $this->EncodeString($this->AltBody, $this->Encoding);
  378.                 $result.= $this->LE . $this->LE;
  379.                 $result.= $this->GetBoundary($this->boundary[1], "", "text/html", "");
  380.                 $result.= $this->EncodeString($this->Body, $this->Encoding);
  381.                 $result.= $this->LE . $this->LE;
  382.                 $result.= $this->EndBoundary($this->boundary[1]);
  383.             break;
  384.             case "plain":
  385.                 $result.= $this->EncodeString($this->Body, $this->Encoding);
  386.             break;
  387.             case "attachments":
  388.                 $result.= $this->GetBoundary($this->boundary[1], "", "", "");
  389.                 $result.= $this->EncodeString($this->Body, $this->Encoding);
  390.                 $result.= $this->LE;
  391.                 $result.= $this->AttachAll();
  392.             break;
  393.             case "alt_attachments":
  394.                 $result.= sprintf("--%s%s", $this->boundary[1], $this->LE);
  395.                 $result.= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", "multipart/alternative", $this->LE, $this->boundary[2], $this->LE . $this->LE);
  396.                 $result.= $this->GetBoundary($this->boundary[2], "", "text/plain", "") . $this->LE;
  397.                 $result.= $this->EncodeString($this->AltBody, $this->Encoding);
  398.                 $result.= $this->LE . $this->LE;
  399.                 $result.= $this->GetBoundary($this->boundary[2], "", "text/html", "") . $this->LE;
  400.                 $result.= $this->EncodeString($this->Body, $this->Encoding);
  401.                 $result.= $this->LE . $this->LE;
  402.                 $result.= $this->EndBoundary($this->boundary[2]);
  403.                 $result.= $this->AttachAll();
  404.             break;
  405.         }
  406.         if ($this->IsError()) $result = "";
  407.         return $result;
  408.     }
  409.     function GetBoundary($boundary, $charSet, $contentType, $encoding) {
  410.         $result = "";
  411.         if ($charSet == "") {
  412.             $charSet = $this->CharSet;
  413.         }
  414.         if ($contentType == "") {
  415.             $contentType = $this->ContentType;
  416.         }
  417.         if ($encoding == "") {
  418.             $encoding = $this->Encoding;
  419.         }
  420.         $result.= $this->TextLine("--" . $boundary);
  421.         $result.= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
  422.         $result.= $this->LE;
  423.         $result.= $this->HeaderLine("Content-Transfer-Encoding", $encoding);
  424.         $result.= $this->LE;
  425.         return $result;
  426.     }
  427.     function EndBoundary($boundary) {
  428.         return $this->LE . "--" . $boundary . "--" . $this->LE;
  429.     }
  430.     function SetMessageType() {
  431.         if (count($this->attachment) < 1 && strlen($this->AltBody) < 1) $this->message_type = "plain";
  432.         else {
  433.             if (count($this->attachment) > 0) $this->message_type = "attachments";
  434.             if (strlen($this->AltBody) > 0 && count($this->attachment) < 1) $this->message_type = "alt";
  435.             if (strlen($this->AltBody) > 0 && count($this->attachment) > 0) $this->message_type = "alt_attachments";
  436.         }
  437.     }
  438.     function HeaderLine($name, $value) {
  439.         return $name . ": " . $value . $this->LE;
  440.     }
  441.     function TextLine($value) {
  442.         return $value . $this->LE;
  443.     }
  444.     function AddAttachment($path, $name = "", $encoding = "base64", $type = "application/octet-stream") {
  445.         if (!@is_file($path)) {
  446.             $this->SetError($this->Lang("file_access") . $path);
  447.             return false;
  448.         }
  449.         $filename = basename($path);
  450.         if ($name == "") $name = $filename;
  451.         $cur = count($this->attachment);
  452.         $this->attachment[$cur][0] = $path;
  453.         $this->attachment[$cur][1] = $filename;
  454.         $this->attachment[$cur][2] = $name;
  455.         $this->attachment[$cur][3] = $encoding;
  456.         $this->attachment[$cur][4] = $type;
  457.         $this->attachment[$cur][5] = false;
  458.         $this->attachment[$cur][6] = "attachment";
  459.         $this->attachment[$cur][7] = 0;
  460.         return true;
  461.     }
  462.     function AttachAll() {
  463.         $mime = array();
  464.         for ($i = 0;$i < count($this->attachment);$i++) {
  465.             $bString = $this->attachment[$i][5];
  466.             if ($bString) $string = $this->attachment[$i][0];
  467.             else $path = $this->attachment[$i][0];
  468.             $filename = $this->attachment[$i][1];
  469.             $name = $this->attachment[$i][2];
  470.             $encoding = $this->attachment[$i][3];
  471.             $type = $this->attachment[$i][4];
  472.             $disposition = $this->attachment[$i][6];
  473.             $cid = $this->attachment[$i][7];
  474.             $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
  475.             $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
  476.             $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
  477.             if ($disposition == "inline") $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
  478.             $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $name, $this->LE . $this->LE);
  479.             if ($bString) {
  480.                 $mime[] = $this->EncodeString($string, $encoding);
  481.                 if ($this->IsError()) {
  482.                     return "";
  483.                 }
  484.                 $mime[] = $this->LE . $this->LE;
  485.             } else {
  486.                 $mime[] = $this->EncodeFile($path, $encoding);
  487.                 if ($this->IsError()) {
  488.                     return "";
  489.                 }
  490.                 $mime[] = $this->LE . $this->LE;
  491.             }
  492.         }
  493.         $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
  494.         return join("", $mime);
  495.     }
  496.     function EncodeFile($path, $encoding = "base64") {
  497.         if (!@$fd = fopen($path, "rb")) {
  498.             $this->SetError($this->Lang("file_open") . $path);
  499.             return "";
  500.         }
  501.         $file_buffer = fread($fd, filesize($path));
  502.         $file_buffer = $this->EncodeString($file_buffer, $encoding);
  503.         fclose($fd);
  504.         return $file_buffer;
  505.     }
  506.     function EncodeString($str, $encoding = "base64") {
  507.         $encoded = "";
  508.         switch (strtolower($encoding)) {
  509.             case "base64":
  510.                 $encoded = chunk_split(base64_encode($str), 76, $this->LE);
  511.             break;
  512.             case "7bit":
  513.             case "8bit":
  514.                 $encoded = $this->FixEOL($str);
  515.                 if (substr($encoded, -(strlen($this->LE))) != $this->LE) $encoded.= $this->LE;
  516.                 break;
  517.             case "binary":
  518.                 $encoded = $str;
  519.                 break;
  520.             case "quoted-printable":
  521.                 $encoded = $this->EncodeQP($str);
  522.                 break;
  523.             default:
  524.                 $this->SetError($this->Lang("encoding") . $encoding);
  525.                 break;
  526.             }
  527.             return $encoded;
  528.     }
  529.     function EncodeHeader($str, $position = 'text') {
  530.         $x = 0;
  531.         switch (strtolower($position)) {
  532.             case 'phrase':
  533.                 if (!preg_match('/[\200-\377]/', $str)) {
  534.                     $encoded = addcslashes($str, "\0..\37\177\\\"");
  535.                     if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) return ($encoded);
  536.                     else return ("\"$encoded\"");
  537.                 }
  538.                 $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
  539.                 break;
  540.             case 'comment':
  541.                 $x = preg_match_all('/[()"]/', $str, $matches);
  542.             case 'text':
  543.             default:
  544.                 $x+= preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
  545.                 break;
  546.             }
  547.             if ($x == 0) return ($str);
  548.             $maxlen = 75 - 7 - strlen($this->CharSet);
  549.             if (strlen($str) / 3 < $x) {
  550.                 $encoding = 'B';
  551.                 $encoded = base64_encode($str);
  552.                 $maxlen-= $maxlen % 4;
  553.                 $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  554.             } else {
  555.                 $encoding = 'Q';
  556.                 $encoded = $this->EncodeQ($str, $position);
  557.                 $encoded = $this->WrapText($encoded, $maxlen, true);
  558.                 $encoded = str_replace("=" . $this->LE, "\n", trim($encoded));
  559.             }
  560.             $encoded = preg_replace('/^(.*)$/m', " =?" . $this->CharSet . "?$encoding?\\1?=", $encoded);
  561.             $encoded = trim(str_replace("\n", $this->LE, $encoded));
  562.             return $encoded;
  563.         }
  564.         function EncodeQP($str) {
  565.             $encoded = $this->FixEOL($str);
  566.             if (substr($encoded, -(strlen($this->LE))) != $this->LE) $encoded.= $this->LE;
  567.             $encoded = preg_replace('/([\000-\010\013\014\016-\037\075\177-\377])/e', "'='.sprintf('%02X', ord('\\1'))", $encoded);
  568.             $encoded = preg_replace("/([\011\040])" . $this->LE . "/e", "'='.sprintf('%02X', ord('\\1')).'" . $this->LE . "'", $encoded);
  569.             $encoded = $this->WrapText($encoded, 74, true);
  570.             return $encoded;
  571.         }
  572.         function EncodeQ($str, $position = "text") {
  573.             $encoded = preg_replace("[\r\n]", "", $str);
  574.             switch (strtolower($position)) {
  575.                 case "phrase":
  576.                     $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  577.                 break;
  578.                 case "comment":
  579.                     $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  580.                 case "text":
  581.                 default:
  582.                     $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e', "'='.sprintf('%02X', ord('\\1'))", $encoded);
  583.                 break;
  584.             }
  585.             $encoded = str_replace(" ", "_", $encoded);
  586.             return $encoded;
  587.         }
  588.         function AddStringAttachment($string, $filename, $encoding = "base64", $type = "application/octet-stream") {
  589.             $cur = count($this->attachment);
  590.             $this->attachment[$cur][0] = $string;
  591.             $this->attachment[$cur][1] = $filename;
  592.             $this->attachment[$cur][2] = $filename;
  593.             $this->attachment[$cur][3] = $encoding;
  594.             $this->attachment[$cur][4] = $type;
  595.             $this->attachment[$cur][5] = true;
  596.             $this->attachment[$cur][6] = "attachment";
  597.             $this->attachment[$cur][7] = 0;
  598.         }
  599.         function AddEmbeddedImage($path, $cid, $name = "", $encoding = "base64", $type = "application/octet-stream") {
  600.             if (!@is_file($path)) {
  601.                 $this->SetError($this->Lang("file_access") . $path);
  602.                 return false;
  603.             }
  604.             $filename = basename($path);
  605.             if ($name == "") $name = $filename;
  606.             $cur = count($this->attachment);
  607.             $this->attachment[$cur][0] = $path;
  608.             $this->attachment[$cur][1] = $filename;
  609.             $this->attachment[$cur][2] = $name;
  610.             $this->attachment[$cur][3] = $encoding;
  611.             $this->attachment[$cur][4] = $type;
  612.             $this->attachment[$cur][5] = false;
  613.             $this->attachment[$cur][6] = "inline";
  614.             $this->attachment[$cur][7] = $cid;
  615.             return true;
  616.         }
  617.         function InlineImageExists() {
  618.             $result = false;
  619.             for ($i = 0;$i < count($this->attachment);$i++) {
  620.                 if ($this->attachment[$i][6] == "inline") {
  621.                     $result = true;
  622.                     break;
  623.                 }
  624.             }
  625.             return $result;
  626.         }
  627.         function ClearAddresses() {
  628.             $this->to = array();
  629.         }
  630.         function ClearCCs() {
  631.             $this->cc = array();
  632.         }
  633.         function ClearBCCs() {
  634.             $this->bcc = array();
  635.         }
  636.         function ClearReplyTos() {
  637.             $this->ReplyTo = array();
  638.         }
  639.         function ClearAllRecipients() {
  640.             $this->to = array();
  641.             $this->cc = array();
  642.             $this->bcc = array();
  643.         }
  644.         function ClearAttachments() {
  645.             $this->attachment = array();
  646.         }
  647.         function ClearCustomHeaders() {
  648.             $this->CustomHeader = array();
  649.         }
  650.         function SetError($msg) {
  651.             $this->error_count++;
  652.             $this->ErrorInfo = $msg;
  653.         }
  654.         function RFCDate() {
  655.             $tz = date("Z");
  656.             $tzs = ($tz < 0) ? "-" : "+";
  657.             $tz = abs($tz);
  658.             $tz = ($tz / 3600) * 100 + ($tz % 3600) / 60;
  659.             $result = sprintf("%s %s%04d", date("D, j M Y H:i:s"), $tzs, $tz);
  660.             return $result;
  661.         }
  662.         function ServerVar($varName) {
  663.             global $HTTP_SERVER_VARS;
  664.             global $HTTP_ENV_VARS;
  665.             if (!isset($_SERVER)) {
  666.                 $_SERVER = $HTTP_SERVER_VARS;
  667.                 if (!isset($_SERVER["REMOTE_ADDR"])) $_SERVER = $HTTP_ENV_VARS;
  668.             }
  669.             if (isset($_SERVER[$varName])) return $_SERVER[$varName];
  670.             else return "";
  671.         }
  672.         function ServerHostname() {
  673.             if ($this->Hostname != "") $result = $this->Hostname;
  674.             elseif ($this->ServerVar('SERVER_NAME') != "") $result = $this->ServerVar('SERVER_NAME');
  675.             else $result = "localhost.localdomain";
  676.             return $result;
  677.         }
  678.         function Lang($key) {
  679.             if (count($this->language) < 1) $this->SetLanguage("en");
  680.             if (isset($this->language[$key])) return $this->language[$key];
  681.             else return "Language string failed to load: " . $key;
  682.         }
  683.         function IsError() {
  684.             return ($this->error_count > 0);
  685.         }
  686.         function FixEOL($str) {
  687.             $str = str_replace("\r\n", "\n", $str);
  688.             $str = str_replace("\r", "\n", $str);
  689.             $str = str_replace("\n", $this->LE, $str);
  690.             return $str;
  691.         }
  692.         function AddCustomHeader($custom_header) {
  693.             $this->CustomHeader[] = explode(":", $custom_header, 2);
  694.         }
  695.     }
  696. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement