C-Libcurl-如何搜索带有特殊字符(ä;、ö;、ü;)的邮件

C-Libcurl-如何搜索带有特殊字符(ä;、ö;、ü;)的邮件,c,search,special-characters,imap,libcurl,C,Search,Special Characters,Imap,Libcurl,我使用libcurl在邮箱中搜索邮件。 但我无法搜索包含主题中特殊字符(ä,ö,ü)的邮件 int main(void) { CURL *curl; CURLcode res = CURLE_OK; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_USERNAME, "myuser"); curl_easy_setopt(curl, CURLOPT_PASSWORD, "myp

我使用libcurl在邮箱中搜索邮件。 但我无法搜索包含主题中特殊字符(ä,ö,ü)的邮件

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

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_USERNAME, "myuser");
    curl_easy_setopt(curl, CURLOPT_PASSWORD, "mypassword");

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

    curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "SEARCH SUBJECT Spülmaschine");

    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;
}
找不到邮件

我找了一会儿,但找不到提普

有人有什么想法吗

编辑://以下任何一种尝试都不起作用:

curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "SEARCH CHARSET UTF-8 SUBJECT \x53\x70\xc3\xbc\x6c\x6d\x61\x73\x63\x68\x69\x6e\x65");


//try it with UTF-7
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "SEARCH SUBJECT Sp+APw-lmaschine");


sprintf(strSearchString, "SEARCH CHARSET UTF-8 SUBJECT {%i}\r\n\x53\x70\xc3\xbc\x6c\x6d\x61\x73\x63\x68\x69\x6e\x65", strlen("\x53\x70\xc3\xbc\x6c\x6d\x61\x73\x63\x68\x69\x6e\x65"));
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, strSearchString);

虽然从技术上讲,包含8位字符的协议是不允许的,但请尝试搜索字符集UTF-8主题“spülmaschine”,并确保您确实发送了UTF-8,而不是其他编码。这将在许多服务器上工作。我不知道您是否可以让libcurl使用IMAP文本以正确的方式执行它


注意:有些服务器软件不太支持搜索。请记住,您始终可以使用诸如
socat
或python的
imaplib
之类的工具,这些工具使您能够以相当低的级别访问协议进行实验。

经过很长时间,我找到了一个解决方案:

int main(void) {
    CURL *curl;
    CURLcode res = CURLE_OK;
    curl = curl_easy_init();
    if (curl) {
        curl_easy_setopt(curl, CURLOPT_USERNAME, "myuser");
        curl_easy_setopt(curl, CURLOPT_PASSWORD, "mypass");
        curl_easy_setopt(curl, CURLOPT_URL, "imaps://imap.gmail.com:993");

        // see RFC6855 IMAP Support for UTF-8
        // imap.gmail.com states UTF8=ACCEPT in CAPABILITY response,
        // so enable it to use UTF-8 in quoted strings.
        // Must come after AUTHENTICATE and before SELECT.
        curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "ENABLE UTF8=ACCEPT");
        res = curl_easy_perform(curl);
        if (res != CURLE_OK)
            fprintf(stderr, "curl_easy_perform() failed: %s\n",
                    curl_easy_strerror(res));

        // SELECT INBOX broken out from URL
        if (res == CURLE_OK) {
            curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "SELECT INBOX");
            res = curl_easy_perform(curl);
            if (res != CURLE_OK)
                fprintf(stderr, "curl_easy_perform() failed: %s\n",
                        curl_easy_strerror(res));
        }

        if (res == CURLE_OK) {
            // U+00FC LATIN SMALL LETTER U WITH DIAERESIS is \xC3\xBC in UTF-8
            curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "SEARCH
SUBJECT \"Sp\xC3\xBClmaschine\"");
            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;
}

这是行不通的。curl\u easy\u setopt(curl,CURLOPT\u CUSTOMREQUEST,“搜索字符集UTF-8\”\x53\x70\xc3\xbc\x6c\x6d\x61\x73\x63\x68\x69\x6e\x65\”;curl\u easy\u perform()返回“CURLE\u QUOTE\u ERROR”curl的imap模块似乎没有很好的错误处理能力。有没有办法让它打印协议跟踪?Libcurl发送“SEARCH SUBJECT Sp.lmaschine”。服务器的响应是“BAD无法解析命令”,这表明您需要以文本形式发送8位数据。