gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 16:32:03 24 4
gpt4 key购买 nike

我使用 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);

最佳答案

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

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;
}

关于C - Libcurl - 如何搜索带有特殊字符 (ä,ö,ü) 的邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50310908/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com