2011-01-05 136 views
0

有谁知道如何格式化卷曲,所以我可以访问我的Gmail并检查是否有一些新的邮件?cURLing Gmail帐户

P.S.对不起,我忘了提到一件大事 - 我使用的是PHP,而不是控制台! :(对不起

回答

3

here

curl -u username --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'print "\t" if /<name>/; print "$2\n" if /<(title|name)>(.*)<\/\1>/;' 

就尝试过了,它的工作对我很难为情是真棒

更新:。这使用Gmail's atom feed for unread messages其中使用SSL/HTTPS和HTTP验证。所以没有必要的OAuth

+0

好点,我同意这是一个很好的解决方案。我发现我必须做-k来关闭证书验证。我立场纠正。 – kvista 2011-01-06 00:09:48

+0

你能得到这个主题吗?不只是未读电子邮件的标题? – shreddish 2015-12-16 19:55:03

0

我拿我以前的回答,上面的一个班轮确实工作,虽然你可能需要指定-k为了关闭证书验证

2

您可以使用此功能

function check_email($username, $password) 
{ 
    //url to connect to 
    $url = "https://mail.google.com/mail/feed/atom"; 
    // sendRequest 
    $curl = curl_init(); 
    curl_setopt($curl, CURLOPT_URL, $url); 
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($curl, CURLOPT_USERPWD, $username . ":" . $password); 
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
    curl_setopt($curl, CURLOPT_ENCODING, ""); 
    $curlData = curl_exec($curl); 
    curl_close($curl); 

    //returning retrieved feed 
    return $curlData; 
} 

然后你就可以通过从XML提取值恢复您的数据卷曲你的Gmail的RSS源/ XML ..

$em = "[email protected]"; 
$pw = "yourpassword"; 
$feed = check_email($em, $pw); 
    $x = new SimpleXmlElement($feed); 
    echo "<ul>"; 
     foreach($x->entry as $msg){ 
      $href = $msg->link->attributes()->href; 
      $qmark = strpos($href,"?")+1; 
      $qstring = substr($href,$qmark); 

      echo "<li><a href=\"step2.php?".$qstring."\">".$msg->title."</a><br />".$msg->summary."</li>"; 
     } 
    echo "</ul>"; 

或者仅通过查看饲料,这取决于你想用它做什么..

$em = "[email protected]"; 
$pw = "yourpassword"; 
$feed = check_email($em, $pw); 
echo $feed;