【问题标题】:How to read messages off an IMAP server with libcurl and C:如何使用 libcurl 和 C 从 IMAP 服务器读取消息:
【发布时间】:2014-02-13 05:46:06
【问题描述】:

我正在尝试使用 libcurl 从 IMAP 服务器检索消息。这是我从在线示例中使用的代码:

#include <stdio.h>
#include <curl/curl.h>

int main(void){
   CURL *curl;
   CURLcode res = CURLE_OK;

   curl = curl_easy_init();
   if(curl) { 
     curl_easy_setopt(curl, CURLOPT_USERNAME, "user");
     curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret");
     curl_easy_setopt(curl, CURLOPT_URL, "imaps://imap.example.com/INBOX/;UID=1");
     curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
     curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
     curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
     res = curl_easy_perform(curl);
     if(res != CURLE_OK)
       fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
     curl_easy_cleanup(curl);
   }
return (int)res;

}

不幸的是,这不起作用。我得到以下输出:

C SELECT INBOX/;UID=1 &lt; C NO Mailbox doesn't exist: INBOX.;UID=1 * Select failed

如果我只输入curl_easy_setopt(curl, CURLOPT_URL, "imaps://imap.example.com/INBOX); 而不是curl_easy_setopt(curl, CURLOPT_URL, "imaps://imap.example.com/INBOX/;UID=1");,那么我实际上得到了关于收件箱的有用输出,就像我应该做的那样,没有错误。

我在 ubuntu 上使用 gcc 进行编译。

【问题讨论】:

    标签: ubuntu gcc curl imap libcurl


    【解决方案1】:

    只为那些经过这么长时间阅读本文的人

    如果我输入 Google Mail 帐户,代码将为我运行。像这样:

     curl_easy_setopt(curl, CURLOPT_URL, "imaps://imap.gmail.com:993/INBOX/;UID=1");
    

    (在 ubuntu 中使用 gcc 编译)

    【讨论】:

    • curl 网站上的示例使用“imap://...” - 你的有“imaps://” - 在这里拯救了我的灵魂,经过更多时间:) thx
    【解决方案2】:

    不要在 URL 后面加上斜杠,即使用imaps://imap.example.com/INBOX;UID=1

    【讨论】:

    • 仍然给出相同的消息:C NO 邮箱不存在:INBOX;UID=1
    • 协议跟踪是什么样子的?
    猜你喜欢
    • 1970-01-01
    • 2015-09-21
    • 2015-05-15
    • 2011-05-09
    • 2020-02-20
    • 2012-08-03
    • 2014-05-16
    • 2016-03-18
    • 2022-07-03
    相关资源
    最近更新 更多