原来在论坛里发过一次帖子,看了别人的一些代码,实现了部分功能,寻求高手帮助调试一下其他几个邮箱的
想实现类似开心网的功能:可以通过网页登录126,163,sina,登录后,可以导出好友邮箱地址
也希望高手能指点下QQ的好友能否导出?
在csdn上找了一些代码,但是总是有些错误,原来没怎么搞过php,所以还是决定请高手帮助下,有偿帮助也可以参阅的帖子:http://topic.csdn.net/u/20101007/23/90d1bd3d-9b28-4710-ae1d-f7e795d094b3.html

解决方案 »

  1.   

    126部分的代码:
    <?php 
    /** 
    * @file class.126http.php 
    * 获得126邮箱通讯录列表 
    * @author jvones<[email protected]> http://www.jvones.com/blog 
    * @date 2009-09-26 
    **/ 
    class http126 

    private function login($username, $password) 

    //第一步:初步登陆 
    $cookies = array(); 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch, CURLOPT_URL, "https://reg.163.com/logins.jsp?type=1&product=mail126&url=http://entry.mail.126.com/cgi/ntesdoor?hid%3D10010102%26lightweight%3D1%26verifycookie%3D1%26language%3D0%26style%3D-1"); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".$username."@126.com&password=".$password); 
    curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR); 
    curl_setopt($ch,CURLOPT_HEADER,1); 
    curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $str = curl_exec($ch); 
    file_put_contents('./126result.txt', $str); 
    curl_close($ch); 
    //获取redirect_url跳转地址,可以从126result.txt中查看,通过正则在$str返回流中匹配该地址 
    preg_match("/replace\(\"(.*?)\"\)\;/", $str, $mtitle); 
    $_url1 = $mtitle[1]; 
    file_put_contents('./126resulturl.txt', $redirect_url); 
    //第二步:再次跳转到到上面$_url1 
    $ch = curl_init($_url1); 
    curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch,CURLOPT_COOKIEFILE,COOKIEJAR); 
    curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR); 
    curl_setopt($ch,CURLOPT_HEADER,1); 
    $str2 = curl_exec($ch); 
    curl_close($ch); 
    if (strpos($contents, "安全退出") !== false) 

    return 0; 

    return 1; 

    /** 
    * 获取邮箱通讯录-地址 
    * @param $user 
    * @param $password 
    * @param $result 
    * @return array 
    */ 
    public function getAddressList($username, $password) 

    if (!$this->login($username, $password)) 

    return 0; 

    $header = $this->_getheader($username); 
    if (!$header['sid']) 

    return 0; 

    //测试找出sid(很重要)和host 
    file_put_contents('./host.txt',"host"); 
    file_put_contents('./sid.txt',"h_sid"); 
    //开始进入模拟抓取 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "http://".$header['host']."/a/s?sid=".$header['sid']."&func=global:sequential"); 
    curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/xml")); 
    $str = "<?xml version=\"1.0\"?><object><array name=\"items\"><object><string name=\"func\">pab:searchContacts</string><object name=\"var\"><array name=\"order\"><object><string name=\"field\">FN</string><boolean name=\"ignoreCase\">true</boolean></object></array></object></object><object><string name=\"func\">user:getSignatures</string></object><object><string name=\"func\">pab:getAllGroups</string></object></array></object>"; 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $str); 
    curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT); 
    ob_start(); 
    curl_exec($ch); 
    $contents = ob_get_contents(); 
    ob_end_clean(); 
    curl_close($ch); 
    //get mail list from the page information username && emailaddress 
    preg_match_all("/<string\s*name=\"EMAIL;PREF\">(.*)<\/string>/Umsi",$contents,$mails); 
    preg_match_all("/<string\s*name=\"FN\">(.*)<\/string>/Umsi",$contents,$names); 
    $users = array(); 
    foreach($names[1] as $k=>$user) 

    //$user = iconv($user,'utf-8','gb2312'); 
    $users[$mails[1][$k]] = $user; 

    if (!$users) 

    return '您的邮箱中尚未有联系人'; 

    return $users; 

    /** 
    * Get Header info 
    */ 
    private function _getheader($username) 

    $ch = curl_init();curl_setopt($ch, CURLOPT_URL, "http://entry.mail.126.com/cgi/ntesdoor?hid=10010102&lightweight=1&verifycookie=1&language=0&style=-1&username=".$username."@126.com"); 
    curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR); //当前使用的cookie 
    curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR); //服务器返回的新cookie 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_HEADER, true); 
    curl_setopt($ch, CURLOPT_NOBODY, true); 
    $content=curl_exec($ch); 
    preg_match_all('/Location:\s*(.*?)\r\n/i',$content,$regs); 
    $refer = $regs[1][0]; 
    preg_match_all('/http\:\/\/(.*?)\//i',$refer,$regs); 
    $host = $regs[1][0]; 
    preg_match_all("/sid=(.*)/i",$refer,$regs); 
    $sid = $regs[1][0]; 
    curl_close($ch); 
    return array('sid'=>$sid,'refer'=>$refer,'host'=>$host); 


    ?>
    <?php 
    import_request_variables("p","p_");//$email=$p_myuserid;
    //$password=$p_myuserpass;$email="[email protected]";
    $password="xxx";$m126 = new http126;$res = $m126->getAddressList($email,$password);echo $res;
    ?>
      

  2.   


    http://download.csdn.net/down/3254454/minxiangyun这是163的
    CURL技术说白了就是模拟浏览器的动作实现页面抓取或表单提交,通过此技术可以实现许多有去的功能。
    代码如下:<?php
    error_reporting(0);
    //邮箱用户名(不带@163.com后缀的)
    $user = 'papatata_test';
    //邮箱密码
    $pass = '000000';
    //目标邮箱
    //$mail_addr = [email protected]';
    //登陆
    $url = 'http://reg.163.com/logins.jsp?type=1&url=http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight%3D1%26verifycookie%3D1%26language%3D-1%26style%3D-1';
    $ch = curl_init($url);
    //创建一个用于存放cookie信息的临时文件
    $cookie = tempnam('.','~');
    $referer_login = 'http://mail.163.com';
    //返回结果存放在变量中,而不是默认的直接输出
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_REFERER, $referer_login);
    $fields_post = array(
    'username'=> $user,
    'password'=> $pass,
    'verifycookie'=>1,
    'style'=>-1,
    'product'=> 'mail163',
    'selType'=>-1,
    'secure'=>'on'
    );
    $headers_login = array(
    'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0',
    'Referer' => 'http://www.163.com'
    );
    $fields_string = '';
    foreach($fields_post as $key => $value)
    {
    $fields_string .= $key . '=' . $value . '&';
    }
    $fields_string = rtrim($fields_string , '&');
    curl_setopt($ch, CURLOPT_COOKIESESSION, true);
    //关闭连接时,将服务器端返回的cookie保存在以下文件中
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_login);
    curl_setopt($ch, CURLOPT_POST, count($fields));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
    $result= curl_exec($ch);
    curl_close($ch);
    //跳转
    $url='http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight=1&verifycookie=1&language=-1&style=-1&username=loki_wuxi';
    $ch = curl_init($url);
    $headers = array(
    'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0'
    );
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    //将之前保存的cookie信息,一起发送到服务器端
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
    $result = curl_exec($ch);
    curl_close($ch);
    //取得sid
    preg_match('/sid=[^\"].*/', $result, $location);
    $sid = substr($location[0], 4, -1);
    //file_put_contents('./result.txt', $sid);
    //通讯录地址
    $url='http://g4a30.mail.163.com/jy3/address/addrlist.jsp?sid='.$sid.'&gid=all';
    $ch = curl_init($url);
    $headers = array(
    'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0'
    );
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
    $result = curl_exec($ch);
    curl_close($ch);
    //file_put_contents('./result.txt', $result);
    unlink($cookie);
    //开始抓取内容
    preg_match_all('/<td class="Ibx_Td_addrName"><a[^>]*>(.*?)<\/a><\/td><td class="Ibx_Td_addrEmail"><a[^>]*>(.*?)<\/a><\/td>/i', $result,$infos,PREG_SET_ORDER);
    //1:姓名2:邮箱
    print_r($infos);
    ?> 
      

  3.   

    十分感谢 sibang!请问您有个126的吗?
      

  4.   

    你试试这个
    http://download.csdn.net/down/3254446/minxiangyun
      

  5.   

    你试试这个
    http://wenwen.soso.com/z/q286589102.htm
      

  6.   

    还有这个
    http://www.jb51.net/article/20327.htm
    网上太多了,建议你多利用搜索引擎
      

  7.   

       你这个代码现在已经不可用了,看看第44行$fields。上下文里根本没有这个变量。哪冒泡出来的$fields?而且还有其他未知的错误!
      

  8.   

    <?php
    /** 
    * @file class.163http.php
    * 163邮箱登陆获取类  the class to get 163 email 
    * @author jvones<[email protected]>
    * @date 2009-09-26
    **///define("COOKIEJAR1", tempnam("./assets/tmp", "c1_"));
    //define("COOKIEJAR2", tempnam("./assets/tmp", "c2_"));
    //define("COOKIEJAR3", tempnam("./assets/tmp", "c3_"));
    //$e163=new http163();
    //$elist = $e163->getAddressList('[email protected]', 'xxxx');
    //var_dump($elist);
        
    class http163
    {
      /**
        * @desc: login in the 163 mail box
        * @param string $username
        * @param string $password
        * @return int  //the login status
        */
        public function login($username, $password)
        {
            $ch = curl_init();
           
            curl_setopt($ch, CURLOPT_URL, "http://reg.163.com/logins.jsp");
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".$username."&password=".$password."&type=1");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  //文件流形式返回
            curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR1);
            curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
           
            ob_start();
            curl_exec($ch);
            $contents = ob_get_contents();
            ob_end_clean();
            curl_close($ch);        if (strpos($contents, "安全退出") !== false)
            {
                return 0;
            }
           
            return 1;
        }    /**
        * @desc: get address list from mail box
        * @param string $username
        * @param string $password
        * @return array  //the address list
        */
        public function getAddressList($username, $password)
        {
            if (!$this->login($username, $password))
            {
                return 0;
            }        $header = $this->_getheader($username);

            if (!$header['sid'])
            {
                return 0;
            }
           
            //get the address list page information
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, "http://".$header['host']."/a/s?sid=".$header['sid']."&func=global:sequential");
            curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR2);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Language: zh-cn','Connection: Keep-Alive','Content-Type: application/xml; charset=UTF-8'));        $str = "<?xml version=\"1.0\"?><object><array name=\"items\"><object><string name=\"func\">pab:searchContacts</string>" .
                   "<object name=\"var\"><array name=\"order\"><object><string name=\"field\">FN</string><boolean name=\"ignoreCase\">true</boolean></object>" .
                  "</array></object></object><object><string name=\"func\">user:getSignatures</string></object>" .
                   "<object><string name=\"func\">pab:getAllGroups</string></object></array></object>";        curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
            curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
            ob_start();
            curl_exec($ch);
            $contents = ob_get_contents();
    //file_put_contents('./result.txt', $contents);
            ob_end_clean();
            curl_close($ch);
           
            //get mail list from the page information only emailaddress
            /*
            $pattern = "/([\\w_-])+@([\\w])+([\\w.]+)/";
            if (preg_match_all($pattern, $contents, $tmpres, PREG_PATTERN_ORDER))
            {
                $users = array_unique($tmpres[0]);
            }
         */
            
            //get mail list from the page information username && emailaddress
            preg_match_all("/<string\s*name=\"EMAIL;PREF\">(.*)<\/string>/Umsi",$contents,$mails);
            preg_match_all("/<string\s*name=\"FN\">(.*)<\/string>/Umsi",$contents,$names);
            $users = array();
            foreach($names[1] as $k=>$user)
            {
                //$user = iconv($user,'utf-8','gb2312');
                $users[$user] = $mails[1][$k];
            }
            if (empty($users))
            {
                return '您的邮箱中尚未有联系人';
            }else
            {
                return $users;
            }
        } /**
        * get cookie
        */
        public function _getheader($username)
        {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight=1&verifycookie=1&language=-1&style=-1&username=".$username);
    curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR1);  //当前使用的cookie
    curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR2);   //服务器返回的新cookie
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_NOBODY, true);
    $content=curl_exec($ch);

    preg_match_all('/Location:\s*(.*?)\r\n/i',$content,$regs);
            $refer = $regs[1][0];
            preg_match_all('/http\:\/\/(.*?)\//i',$refer,$regs);
            $host = $regs[1][0];
            preg_match_all("/sid=(.*)/i",$refer,$regs);
            $sid = $regs[1][0];

    curl_close($ch);
    return array('sid'=>$sid,'refer'=>$refer,'host'=>$host);
        }}
    ?>  
      

  9.   

    <?php
    /** 
    * @file class.126http.php
    * 获得126邮箱通讯录列表
    * @author jvones<[email protected]> http://www.jvones.com/blog
    * @date 2009-09-26
    **/
    //define("COOKIEJAR", tempnam("./assets/tmp", "c1_"));
    //$e163=new http126();
    //$elist = $e163->getAddressList('[email protected]', 'xxxxxx');
    //var_dump($elist);
    class http126
    { private function login($username, $password)
    {
    //第一步:初步登陆
    $cookies = array();
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    curl_setopt($ch, CURLOPT_URL, "https://reg.163.com/logins.jsp?type=1&product=mail126&url=http://entry.mail.126.com/cgi/ntesdoor?hid%3D10010102%26lightweight%3D1%26verifycookie%3D1%26language%3D0%26style%3D-1");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".$username."&password=".$password);

    curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
    curl_setopt($ch,CURLOPT_HEADER,1);
    curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $str = curl_exec($ch);
    //file_put_contents('./tmp/126result.txt', $str);
    curl_close($ch);

    //获取redirect_url跳转地址,可以从126result.txt中查看,通过正则在$str返回流中匹配该地址
    preg_match("/replace\(\"(.*?)\"\)\;/", $str, $mtitle);
    $_url1 = $mtitle[1];

    //file_put_contents('./126resulturl.txt', $redirect_url);
    //第二步:再次跳转到到上面$_url1
    $ch = curl_init($_url1);

    curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch,CURLOPT_COOKIEFILE,COOKIEJAR);
    curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
    curl_setopt($ch,CURLOPT_HEADER,1);
    $str2 = curl_exec($ch);
    curl_close($ch);
    if (strpos($str2, "安全退出") !== false)
    {
    return 0;
    }
    return 1;
    }

    /**
     * 获取邮箱通讯录-地址
     * @param $user
     * @param $password
     * @param $result
     * @return array
     */
    public function getAddressList($username, $password)
    {
    if (!$this->login($username, $password))
    {
    return 0;
    }
        
    $header = $this->_getheader($username);
    if (!$header['sid'])
            {
                return 0;
            }
            
            //测试找出sid(很重要)和host
            //file_put_contents('./host.txt', $header['host']);
            //file_put_contents('./sid.txt', $header['sid']);
            
    //开始进入模拟抓取
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://".$header['host']."/a/s?sid=".$header['sid']."&func=global:sequential");
    curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/xml"));
    $str = "<?xml version=\"1.0\"?><object><array name=\"items\"><object><string name=\"func\">pab:searchContacts</string><object name=\"var\"><array name=\"order\"><object><string name=\"field\">FN</string><boolean name=\"ignoreCase\">true</boolean></object></array></object></object><object><string name=\"func\">user:getSignatures</string></object><object><string name=\"func\">pab:getAllGroups</string></object></array></object>";
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
    curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
    ob_start();
    curl_exec($ch);
    $contents = ob_get_contents(); ob_end_clean();
    curl_close($ch);

            //get mail list from the page information username && emailaddress
            preg_match_all("/<string\s*name=\"EMAIL;PREF\">(.*)<\/string>/Umsi",$contents,$mails);
            preg_match_all("/<string\s*name=\"FN\">(.*)<\/string>/Umsi",$contents,$names);
            $users = array();
            foreach($names[1] as $k=>$user)
            {
                //$user = iconv($user,'utf-8','gb2312');
                $users[$user] = $mails[1][$k];
            }
            if (!$users)
            {
                return '您的邮箱中尚未有联系人';
            }      
            
            return $users;
    }

    /**
        * Get Header info
        */
        private function _getheader($username)
        {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://entry.mail.126.com/cgi/ntesdoor?hid=10010102&lightweight=1&verifycookie=1&language=0&style=-1&username=".$username."@126.com");
    curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);  //当前使用的cookie
    curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);   //服务器返回的新cookie
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_NOBODY, true);
    $content=curl_exec($ch);

    preg_match_all('/Location:\s*(.*?)\r\n/i',$content,$regs);
            $refer = $regs[1][0];
            preg_match_all('/http\:\/\/(.*?)\//i',$refer,$regs);
            $host = $regs[1][0];
            preg_match_all("/sid=(.*)/i",$refer,$regs);
            $sid = $regs[1][0];

    curl_close($ch);
    return array('sid'=>$sid,'refer'=>$refer,'host'=>$host);
        }
    }?>
      

  10.   

    谢谢 shen920! 这个126的可以使用
      

  11.   

    <?php
    /** 
    * @file class.sinaHttp.php
    * 获得sina邮箱通讯录列表
    * @author jvones<[email protected]>
    * @date 2009-09-26
    **/
    //define("COOKIEJAR", tempnam("./assets/tmp", "s1_"));
    //$e163=new sinaHttp();
    //$elist = $e163->getAddressList('[email protected]', 'xxxx');
    //var_dump($elist);
    class sinaHttp
    { public $host = ""; function checklogin( $user, $password )
    {
    if ( empty( $user ) || empty( $password ) )
    {
    return 0;
    }
    $ch = curl_init( );
    curl_setopt( $ch, CURLOPT_REFERER, "http://mail.sina.com.cn/index.html" );
    curl_setopt( $ch, CURLOPT_HEADER, true );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch, CURLOPT_USERAGENT, USERAGENT );
    curl_setopt( $ch, CURLOPT_TIMEOUT, TIMEOUT );
    curl_setopt( $ch, CURLOPT_URL, "http://mail.sina.com.cn/cgi-bin/login.cgi" );
    curl_setopt( $ch, CURLOPT_POST, true );
    curl_setopt( $ch, CURLOPT_POSTFIELDS, "&logintype=uid&u=".urlencode( $user )."&psw=".$password );
    $contents = curl_exec( $ch );
    curl_close( $ch );
    if ( !preg_match( "/Location: (.*)\\?sid=(.*)\n/", $contents, $matches ) )
    {
    return 0;
    }
    $this->host = $matches[1];
    //$this->host = "http://m0.mail.sina.com.cn";
    return 1;
    } public function getAddressList( $user, $password)
    {
    if ( !$this->checklogin( $user, $password ) )
    {
    return 0;
    }
    $ch = curl_init( );
    curl_setopt( $ch, CURLOPT_HEADER, true );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
    curl_setopt( $ch, CURLOPT_USERAGENT, USERAGENT );
    curl_setopt( $ch, CURLOPT_COOKIEJAR, COOKIEJAR );
    curl_setopt( $ch, CURLOPT_TIMEOUT, TIMEOUT );
    curl_setopt( $ch, CURLOPT_URL, "http://mail.sina.com.cn/cgi-bin/login.cgi" );
    curl_setopt( $ch, CURLOPT_POST, true );
    curl_setopt( $ch, CURLOPT_POSTFIELDS, "&logintype=uid&u=".urlencode( $user )."&psw=".$password );
    curl_exec( $ch );
    curl_close( $ch );
    $cookies = array( );
    $bRet = $this->_readcookies( COOKIEJAR, $cookies );
    if ( !$bRet && !$cookies['SWEBAPPSESSID'] )
    {
    return 0;
    }
    $ch = curl_init( );
    curl_setopt( $ch, CURLOPT_COOKIEFILE, COOKIEJAR );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch, CURLOPT_TIMEOUT, TIMEOUT );
    curl_setopt( $ch, CURLOPT_URL, $this->host."/classic/addr_member.php" );
    curl_setopt( $ch, CURLOPT_POST, true );
    curl_setopt( $ch, CURLOPT_POSTFIELDS, "&act=list&sort_item=letter&sort_type=desc" );
    $content = curl_exec( $ch );
    curl_close( $ch );
    $res = $this->_parsedata( $content);
    if ( !$res )
    {
    return '没有联系人';//没有联系人
    }
    return $res;
    } public function _parsedata( $content)
    {
    $ar = array( );
    if ( !$content )
    {
    return 0;
    }
    $data = json_decode( $content);
    unset( $content );
    foreach ( $data->data->contact as $value )
    {
    if ( preg_match_all( "/[a-z0-9_\\.\\-]+@[a-z0-9\\-]+\\.[a-z]{2,6}/i", $value->email, $matches ) )
    {
    $emails = array_unique( $matches[0] );
    unset( $matches );
    foreach ( $emails as $email )
    {
    $ar[$value->name] = $email;
    }
    }
    }
    return $ar;
    }

    public function _readcookies( $file, &$result )
    {
    $fp = fopen( $file, "r" );
    while ( !feof( $fp ) )
    {
    $buffer = fgets( $fp, 4096 );
    $tmp = explode( "\t", $buffer );
    $result[trim( $tmp[5] )] = trim( $tmp[6] );
    }
    return 1;
    }
    }?>