function SendRaw(&$email)
 {
     $hdr = 'From: ' . $email->from . "\n";
     foreach ($email->headers as $val) {
         $hdr .= $val . "\n";
     }
     $hdr .= "MIME-Version: 1.0\n";
     if (!count($email->attachments)) {
         $hdr .= 'Content-Type: text/html; charset=' . $email->charset . "\n";
         $body = $email->body;
     } else {
         $str = $email->body;
         foreach ($email->attachments as $att) {
             $str .= $att->content;
         }
         $boundary = $this->GenerateBoundary($str);
         $hdr .= 'Content-Type: multipart/mixed; boundary="' . $boundary . '"' . "\n";
         $attachs = '';
         foreach ($email->attachments as $att) {
             if (strpos($att->mimeType, '/') === false) {
                 SystemDie("Invalid MIME type of the attachment.");
             }
             $attachs .= "--{$boundary}\n";
             $attachs .= 'Content-Type: ' . $att->mimeType;
             if ($att->contentName != '') {
                 $attachs .= '; name="' . $att->contentName . '"';
             }
             $attachs .= "\n";
             $attachs .= "Content-Transfer-Encoding: base64\n";
             if ($att->fileName != '') {
                 $attachs .= 'Content-Disposition: attachment; filename="' . $att->fileName . '"' . "\n";
             }
             if ($att->contentId != '') {
                 $attachs .= 'Content-ID: <' . $att->contentId . ">\n";
             }
             $attachs .= "\n";
             $attachs .= chunk_split(base64_encode($att->content)) . "\n";
         }
         $body = "--{$boundary}\n";
         $body .= "Content-type: text/html; charset=" . $email->charset . "\n\n";
         $body .= $email->body . "\n" . $attachs;
         $body .= "--{$boundary}--\n";
     }
     if (DEBUG_ENABLE) {
         $msg = '<b>SendMail to "' . $email->to . '" with subject "' . $email->subject . '"</b>';
         if (!GetConfigValue("send_mail")) {
             $msg .= ' <span style="color:red;">(Sending email is disabled)</span>';
         }
         DebugWrite($msg, MSG_NORMAL);
         DebugWritePre('Headers', $hdr);
         DebugWritePre('Body', $body);
     }
     if (GetConfigValue("send_mail")) {
         mail($email->to, $email->subject, $body, $hdr);
     }
 }
 function GetOne(&$cmd)
 {
     $res = $this->InternalQuery($cmd);
     if ($res === false) {
         return null;
     }
     if ($res === true) {
         if (DEBUG_ENABLE) {
             DebugWrite("'" . htmlspecialchars($cmd->cmdText) . "' is not a SELECT query", MSG_ERROR);
         }
         return array();
     }
     if ($row = mysql_fetch_assoc($res)) {
         $fld = GetFirstValue($row);
     } else {
         $fld = null;
     }
     mysql_free_result($res);
     return $fld;
 }
function DebugWritePre($str, $msg, $type = MSG_NORMAL)
{
    if (!DEBUG_ENABLE) {
        return;
    }
    DebugWrite("<b>{$str}</b><br />" . nl2br(str_replace(' ', '&nbsp;', htmlspecialchars($msg))));
}