Duyuruyu Kapat
Facebook Gözat
Twitter Gözat

karakter sorunu yaşamaktayım

Konu, 'PHP' kısmında squeaL tarafından paylaşıldı.

  1. squeaL

    squeaL Yeni Üye

    Kayıt:
    18 Aralık 2006
    Mesajlar:
    5
    Beğenilen Mesajlar:
    0
    Selam arkadaşlar bir mail sistemi üzerinde değişikler yapmaktayım

    kısaca mail sisteminden bahsedeyim
    editlediğim mail sistemi pop3'e bağlanarak pop3teki maili mysqle ekliyor
    fakat karakter sorunu yaşamaktayım

    gmailden mail gönderdiklerinde: wwwsin yazan mailde görüldüpü gibi oluyor
    hotmailden gönderdiklerinde: zeynep yazan mailde olduğu gibi konu bölümünde türkçe karakter sorunu var

    [​IMG]

    scripttin kodları biraz karışık ama büyük ihtimalle bu dosyadan kaynaklanmaktadır:
    mysql e girdiğimde subject bölümüne konu bilgisini hatalı şekilde eklemiş durumda oluyor
    normal birşey yazdığımızda sorun yok sadece türkçe karakter sorunumuz var


    şimdiden yardım ve önerileriniz için teşekkür ederim inş. hallederiz

    Kod:
    <?php
    
    function AddMessage($mess)
    {
        $box = GetLocalEmail($mess["sentto"]);
        $boxid = BoxToID($box);
        if ($boxid==-1) return;
        $data = array();
        $data["box"] = $boxid;
        $data["from"] = $mess["from"];
        $data["subject"] = $mess["subject"];
        $data["type"] = $mess["type"];
        $data["body"] = $mess["body"];
        $data["read"] = 0;
        $data["timestamp"] = time();
        $data["fromname"] = $mess["fromname"];
        $data["folder"] = -2;
        $data["to"] = $mess["to"];
        $data["cc"] = $mess["cc"];
        $data["hasattachments"] = 0;
        $data["searchdata"] = ExtractSearchData($mess);
        $data["insearch"] = 0;
        $data["size"] = $mess["size"];
        if (count($mess["attachments"])>0) $data["hasattachments"] = 1;
        ValidateThread();
        InsertRecord("tbl_messages",$data);
        ValidateThread();
        $orecord = GetOwnerByBox($box);if ($orecord!=null) IncrementQuota($orecord["name"],$data["size"]);
        return GetMessageId($boxid,$data["timestamp"]);
    }
    
    function SendSingleMass($box,$fromname,$fromemail,$subject,$message)
    {
        $mess = array();
        $mess["sentto"] = $box."@".$config_emaildomain;
        $mess["cc"] = "";
        $mess["from"] = $fromemail;
        $mess["subject"] = $subject;
        $mess["type"] = "html";
        $mess["body"] = $message;
        $mess["fromname"] = $fromname;
        $mess["size"] = strlen($subject)+strlen($message);
        $mess["attachments"] = array();
        AddMessage($mess);
    }
    
    function SendMass($fromname,$fromemail,$subject,$message)
    {
       $records = GetAllRegisteredOwners();
       if ($records==null) return;
       foreach($records as $record) SendSingleMass($record["box"],$fromname,$fromemail,$subject,$message);
       return count($records);
    }
    
    function MassMail($fromname,$fromemail,$subject,$message,&$count)
    {
        $fromname = trim($fromname);
        $fromemail = trim($fromemail);
        $subject = trim($subject);
        $message = trim($message);
        if (($fromname=="") || ($fromemail=="") || ($subject=="") || ($message=="")) return "All fields are required.";
        if (!check_email($fromemail)) return "The from email is invalid.";
        $count = SendMass($fromname,$fromemail,$subject,$message);
        AddMass($subject,$message,$count);
        return "";
    }
    
    function ExtractSearchData($mess)
    {
        $build = $mess["from"]." ";
        $build .= $mess["fromname"]." ";
        $build .= $mess["to"]." ";
        $build .= $mess["subject"]." ";
        $build .= $mess["body"];
        return " ".ExtractWords(GetTextFrom($build),true)." ";
    }
    
    function GetMessageId($boxid,$timestamp)
    {
        $query = "SELECT * FROM tbl_messages WHERE (`box` = '".SqlEncode($boxid)."') AND (`timestamp` = '".SqlEncode($timestamp)."') ORDER BY `id` DESC";
        $result = mysql_query($query);
        if ($row = mysql_fetch_array_sqldecode($result, MYSQL_ASSOC))
        {
            return $row["id"];
        }
        return -1;
    }
    
    function MoveMessages($frombox,$tobox)
    {
        $query = "UPDATE tbl_messages SET `box` = '".SqlEncode($tobox)."' WHERE `box` = '".SqlEncode($frombox)."'";
        mysql_query($query);
    }
    
    function AddSentMessage($box,$fullname,$to,$cc,$bcc,$subject,$message,$hasattachments)
    {
        global $config_emaildomain;
        $boxid = BoxToID($box);
        if ($boxid==-1) return;
        $data = array();
        $data["box"] = $boxid;
        $data["from"] = $box."@".$config_emaildomain;
        $data["subject"] = $subject;
        $data["type"] = "html";
        $data["body"] = $message;
        $data["read"] = 1;
        $data["timestamp"] = time();
        $data["fromname"] = $fullname;
        $data["folder"] = -1;
        $data["to"] = $to;
        $data["cc"] = $cc;
        $data["bcc"] = $bcc;
        $data["hasattachments"] = 0;
        $data["searchdata"] = ExtractSearchData($data);
        $data["insearch"] = 0;
        $data["size"] = strlen($subject)+strlen($message);
        if ($hasattachments) $data["hasattachments"] = 1;
        InsertRecord("tbl_messages",$data);
        $orecord = GetOwnerByBox($box);if ($orecord!=null) IncrementQuota($orecord["name"],$data["size"]);
    }
    
    function GetUnreadMessagesCount($box,$folderid)
    {
        $boxid = BoxToID($box);
        if ($boxid==-1) return 0;
        if ($folderid==-3)
        {
            $query = "SELECT * FROM tbl_messages WHERE (`box` = '".SqlEncode($boxid)."') AND (`read` = '0') AND (`insearch` = '1')";
        }
        else
        {
            $query = "SELECT * FROM tbl_messages WHERE (`box` = '".SqlEncode($boxid)."') AND (`read` = '0') AND (`folder` = '".SqlEncode($folderid)."')";
        }
        $result = mysql_query($query);
        return mysql_num_rows($result);
    }
    
    function GetMessagesCount($box,$folderid)
    {
        $boxid = BoxToID($box);
        if ($boxid==-1) return 0;
        if ($folderid==-3)
        {
            $query = "SELECT * FROM tbl_messages WHERE (`box` = '".SqlEncode($boxid)."') AND (`insearch` = '1')";
        }
        else
        {
            $query = "SELECT * FROM tbl_messages WHERE (`box` = '".SqlEncode($boxid)."') AND (`folder` = '".SqlEncode($folderid)."')";
        }
        $result = mysql_query($query);
        return mysql_num_rows($result);
    }
    
    function GetTotalMessagesCount($box)
    {
        $boxid = BoxToID($box);
        if ($boxid==-1) return 0;
        $query = "SELECT * FROM tbl_messages WHERE (`box` = '".SqlEncode($boxid)."')";
        $result = mysql_query($query);
        return mysql_num_rows($result);
    }
    
    function GetMessages($box,$folderid,$currentpage)
    {
        global $config_perpage;
         $ret = array();
        $boxid = BoxToID($box);
        if ($boxid==-1) return $ret;
        if ($folderid==-3)
        {
            $query = "SELECT * FROM tbl_messages WHERE (`box` = '".SqlEncode($boxid)."') AND (`insearch` = '1') ORDER BY `timestamp` DESC LIMIT ".($config_perpage*$currentpage).",".$config_perpage;
        }
        else
        {
            $query = "SELECT * FROM tbl_messages WHERE (`box` = '".SqlEncode($boxid)."') AND (`folder` = '".SqlEncode($folderid)."') ORDER BY `timestamp` DESC LIMIT ".($config_perpage*$currentpage).",".$config_perpage;
        }
        ValidateThread();
        $result = mysql_query($query);
        ValidateThread();
        while($row = mysql_fetch_array_sqldecode($result, MYSQL_ASSOC))
        {
            $row["todisplay"] = "";
            if ($folderid==-1)
            {
                $todisplay = "";
                $to = $row["to"];
                $cc = $row["cc"];
                $bcc = $row["bcc"];
                $all = "$to,$cc,$bcc";
                $all = explode(",",$all);
                foreach($all as $tmp)
                {
                    $tmp = trim($tmp);
                    if ($tmp!="")
                    {
                        $name = ExtractRealEmailName($tmp);
                        $email = ExtractRealEmail($tmp);
                        if ($todisplay!="") $todisplay.=", ";
                        if ($name!="")
                        {
                            $todisplay.=$name;
                        }
                        else
                        {
                            $r = strpos($email,"@");
                            if ($r!==false) $email = substr($email,0,$r);
                            $todisplay.=$email;
                        }
    
                    }
                }
                $row["todisplay"] = $todisplay;
            }
            $ret[count($ret)] = $row;
        }
        $ret2 = array();
        for($i=count($ret)-1;$i>=0;$i--) $ret2[count($ret2)] = $ret[$i];
        return $ret2;
    }
    
    function GetMessagesById($boxid)
    {
         $ret = array();
        $query = "SELECT * FROM tbl_messages WHERE `box` = '".SqlEncode($boxid)."'";
        $result = mysql_query($query);
        while($row = mysql_fetch_array_sqldecode($result, MYSQL_ASSOC)) $ret[count($ret)] = $row;
        return $ret;
    }
    
    function SetRead($id)
    {
         $query = "UPDATE tbl_messages SET `read` = '1' WHERE `id` = '".$id."'";    
         mysql_query($query);
    }
    
    function SetTargeted($id,$targeted)
    {
         $query = "UPDATE tbl_messages SET `targeted` = '".SqlEncode($targeted)."' WHERE `id` = '".$id."'";
         mysql_query($query);
    }
    
    
    function GetMessage($box,$id)
    {
        if ($box=="") return null;
        if ($id=="") return null;
        $boxid = BoxToID($box);
        if ($boxid==-1) return null;
        $query = "SELECT * FROM tbl_messages WHERE `box` = '".SqlEncode($boxid)."' AND `id` = '".SqlEncode($id)."'";
        $result = mysql_query($query);
        if ($ret = mysql_fetch_array_sqldecode($result, MYSQL_ASSOC))
        {
             $ret["realfrom"] = $ret["from"];
             if ($ret["fromname"]!="") $ret["realfrom"] = $ret["fromname"]." <".$ret["from"].">";
             $ret["attachments"] = GetAttachments($ret["id"]);
             SetRead($id);
            if ($ret["type"]=="text")
            {
                $ret["bodyview"] = htmlspecialchars($ret["body"]);
                $ret["bodyview"] = ValidationCreateLinks($ret["bodyview"]);
                $ret["bodyview"] = ValidationRNToBR($ret["bodyview"]);
            }
            if ($ret["type"]=="html")
            {
                $ret["bodyview"] = ValidationAddTarget($ret["body"]);
                $ret["bodyview"] = ValidationRemoveBody($ret["bodyview"]);
            }
            return $ret;
        }
        return null;
    }
    
    function DeleteMessages($box)
    {
        $boxid = BoxToID($box);
        if ($boxid==-1) return;
        $messageids = array();
        $ar = GetMessagesById($boxid);
        foreach($ar as $tmp) $messageids[] = $tmp["id"];
        DeleteAttachmentByIds($messageids);
        $query = "DELETE FROM tbl_messages WHERE `box` = '".SqlEncode($boxid)."'";
        ValidateThread();
        mysql_query($query);
        ValidateThread();
    }
    
    function GetTotalSize($boxid,$ids)
    {
        $ret = 0;
        $qs = "";
        foreach($ids as $id)
        {
            if ($qs!="") $qs = $qs." OR ";
            $qs = $qs."`id` = '".SqlEncode($id)."'";
        }
        $query = "SELECT * FROM tbl_messages WHERE `box` = '".SqlEncode($boxid)."'";
        if ($qs!="") $query = $query." AND (".$qs.")";
        $result = mysql_query($query);
        $ar = array();
        while($row = mysql_fetch_array_sqldecode($result, MYSQL_ASSOC)) $ar[count($ar)] = $row;
        foreach($ar as $row) $ret+=$row["size"];
        return $ret;
    }
    
    function DeleteMessagesById($owner,$ids)
    {
        $row = GetOwnerRecord($owner);
        $box = $row["box"];
        $boxid = BoxToID($box);
        if ($boxid==-1) return;
        $totalsize = GetTotalSize($boxid,$ids);
        $qs = "";
        foreach($ids as $id)
        {
            if ($qs!="") $qs = $qs." OR ";
            $qs = $qs."`id` = '".SqlEncode($id)."'";
        }
        $query = "DELETE FROM tbl_messages WHERE `box` = '".SqlEncode($boxid)."'";
        if ($qs!="") $query = $query." AND (".$qs.")";
        mysql_query($query);
        IncrementQuota($owner,0-$totalsize);
    }
    
    function IsBoxFull($box,$newsize = 0)
    {
        global $config_boxlimit;
        global $config_quota;
        $record = GetOwnerByBox($box);
        if ($record==null) return false;
        if ($record["password"]!="")
        {
            if ($newsize==0) return false;
            return (($record["quota"]+$newsize)>($config_quota*1024*1024));
        }
        $boxid = BoxToID($box);
        if ($boxid==-1) return false;
        $query = "SELECT `box` FROM tbl_messages WHERE `box` = '".SqlEncode($boxid)."'";
        ValidateThread();
        $result = mysql_query($query);
        ValidateThread();
        return (mysql_num_rows($result)>=$config_boxlimit);
    }
    
    function MoveMessagesToFolder($owner,$folder,$ids)
    {
        $row = GetOwnerRecord($owner);
        $box = $row["box"];
        $boxid = BoxToID($box);
        if ($boxid==-1) return;
        $qs = "";
        foreach($ids as $id)
        {
            if ($qs!="") $qs = $qs." OR ";
            $qs = $qs."`id` = '".SqlEncode($id)."'";
        }
        $query = "UPDATE tbl_messages SET `folder` = '".$folder."' WHERE `box` = '".SqlEncode($boxid)."'";
        if ($qs!="") $query = $query." AND (".$qs.")";
        mysql_query($query);
    }
    
    function ProcessMessages()
    {
        $ismore = false;
         global $config_pop3_hostname;
         global $config_pop3_password;
         global $config_pop3_port;
         global $config_pop3_usetls;
         global $config_pop3_user;
         global $config_messagesizelimit;
         global $config_registeredmessagesizelimit;
         global $config_emaildomain;
        $pop3=new pop3_class;
        $pop3->hostname=$config_pop3_hostname;
        $pop3->port=$config_pop3_port;
        $pop3->tls=$config_pop3_usetls;
        $user=$config_pop3_user;
        $password=$config_pop3_password;
        $pop3->realm="";                        
        $pop3->workstation="";                  
        $apop=0;                                
        $pop3->authentication_mechanism="USER";
        $pop3->debug=0;
        $pop3->html_debug=1;
        $pop3->join_continuation_header_lines=1;
        ValidateThread();
        $todelete = array();
        $toadd = array();
        if(($pop3->Open())=="")
        {
             ValidateThread($pop3);
            if(($pop3->Login($user,$password,$apop))=="")
            {
                 ValidateThread($pop3);
                if(($pop3->Statistics($messages,$size))=="")
                {
                     ValidateThread($pop3);
                    if ($messages>0)
                    {
                         $sizes=$pop3->ListMessages("",0);
                         if(GetType($sizes)=="array")
                         {
                              ValidateThread($pop3);
                            $realcount = $messages;
                            if ($realcount>50)
                            {
                                $realcount = 50;
                                $ismore = true;
                            }
                            for($i=1;$i<=$realcount;$i++)
                            {
                                 $hm = -1;
                                 if ($sizes[$i]>($config_messagesizelimit*1024)) $hm = 0;
                                 //$ret["to"] = ExtractEmail(GetHeader($headers,"To"));
                                if(($pop3->RetrieveMessage($i,$headers,$body,0))=="")
                                {
                                    //DebugLine(implode("\r\n",$headers));
                                    $recs = implode(" ",GetHeaderCollection($headers,"Received"));
                                    //DebugLine("\r\n\r\n".$recs);
                                    $tmpto = ExtractEmailAddresses($recs,$config_emaildomain);
                                    //DebugLine("\r\n\r\n".$tmpto);
                                    $tmpbox = GetLocalEmail($tmpto);
                                    $tmprecord = GetOwnerByBox($tmpbox);
                                    if ($tmprecord!=null)
                                    {
                                        $sizelimit = $config_messagesizelimit;
                                        if ($tmprecord["password"]!="") $sizelimit = $config_registeredmessagesizelimit;
                                        if ($sizes[$i]<=($sizelimit*1024))
                                        {
                                            if(($pop3->RetrieveMessage($i,$headers,$body,-1))=="")
                                            {
                                                 $mess = ExtractMessage($headers,$body);
                                                 $mess["sentto"] = $tmpto;
                                                 $allowattachments = ($tmprecord["password"]!="") || (count($mess["attachments"])==0);
                                                 if (!$allowattachments) $mess["attachments"] = array();
                                                 $mess["size"] = strlen($mess["subject"])+strlen($mess["body"]);
                                                 foreach($mess["attachments"] as $attachment) $mess["size"] = $mess["size"] + strlen($attachment["stream"]);
                                                 $toadd[count($toadd)] = $mess;
                                                $todelete[count($todelete)] = $i;
                                            }
                                        }
                                        else
                                        {
                                            $body = array();
                                            $body[0] = "This message exceeded the size limit (".GetSizeDisplay($sizelimit*1024)."). The content was deleted.";
                                            $headers = SetHeader($headers,"Content-Type","text");
                                              $mess = ExtractMessage($headers,$body);
                                             $mess["attachments"] = array();
                                             $mess["size"] = strlen($mess["subject"])+strlen($mess["body"]);
                                             $toadd[count($toadd)] = $mess;
                                            $todelete[count($todelete)] = $i;
                                        }
                                    }
                    else
                    {
                        $todelete[count($todelete)] = $i;
                    }
                                 }
                            }
                        }
                    }
                    foreach($toadd as $amess)
                    {
                        $box = GetLocalEmail($amess["sentto"]);
                        if (!IsBoxFull($box,$amess["size"]))
                        {
                            $mid = AddMessage($amess);
                            if ($mid!=-1)
                            {
                                 foreach($amess["attachments"] as $attachment)
                                 {
                                    AddAttachment($mid,$attachment["filename"],$attachment["stream"]);
                                }
                            }
                        }
                    }
                    foreach($todelete as $tdi) $pop3->DeleteMessage($tdi);
                    $pop3->Close();
                }
            }
        }
        ValidateThread();
        return $ismore;
    }
    
    function GetMessagesInFolder($boxid,$folderid)
    {
        $ret = array();
        $query = "SELECT * FROM tbl_messages WHERE (`box` = '".SqlEncode($boxid)."') AND (`folder` = '".SqlEncode($folderid)."')";
        $result = mysql_query($query);
        while($row = mysql_fetch_array_sqldecode($result, MYSQL_ASSOC)) $ret[count($ret)] = $row;
        return $ret;
    }
    
    function DeleteMessagesInFolder($owner,$box,$folderid)
    {
        $boxid = BoxToID($box);
        if ($boxid==-1) return;
        $messageids = array();
        $ar = GetMessagesInFolder($boxid,$folderid);
        foreach($ar as $tmp) $messageids[] = $tmp["id"];
        $totalsize = 0;
        foreach($ar as $tmp) $totalsize += $tmp["size"];
        DeleteAttachmentByIds($messageids);
        $query = "DELETE FROM tbl_messages WHERE (`box` = '".SqlEncode($boxid)."') AND (`folder` = '".SqlEncode($folderid)."')";
        mysql_query($query);
        IncrementQuota($owner,0-$totalsize);
    }
    
    function MarkMessagesById($owner,$ids,$as)
    {
        $value = -1;
        if ($as=="read") $value = 1;
        if ($as=="unread") $value = 0;
        if ($value==-1) return;
        $row = GetOwnerRecord($owner);
        $box = $row["box"];
        $boxid = BoxToID($box);
        if ($boxid==-1) return;
        $qs = "";
        foreach($ids as $id)
        {
            if ($qs!="") $qs = $qs." OR ";
            $qs = $qs."`id` = '".SqlEncode($id)."'";
        }
        $query = "UPDATE tbl_messages SET `read` = '".$value."' WHERE `box` = '".SqlEncode($boxid)."'";
        if ($qs!="") $query = $query." AND (".$qs.")";
        mysql_query($query);
    }
    
    ?>
    
     
  2. squeaL

    squeaL Yeni Üye

    Kayıt:
    18 Aralık 2006
    Mesajlar:
    5
    Beğenilen Mesajlar:
    0
    yokmu bunu yapabilcek ???
     
  3. Kaplumb_Aga

    Kaplumb_Aga Üye

    Kayıt:
    29 Mayıs 2005
    Mesajlar:
    109
    Beğenilen Mesajlar:
    0
    mailden gelen metnin karakter seti ile mysql'deki karakter seti arasında uyumsuzluk var sanırım
    ikisini de aynı yaparsan sorun çözülür diye tahmin ediyorum.. mesela ikisi de utf-8 gibi...