curl / Mailing Lists / curl-library / Single Mail

curl-library

Re: Libcurl - How to search for Mails with special chars (ä,ö,ü)

From: Kyle Rogers <kyle30312_at_gmail.com>
Date: Thu, 7 Jun 2018 03:37:07 -0400

> On May 15, 2018, Unbekannt Unbekannt <xxchillerzz_at_googlemail.com> wrote:
>
> i use libcurl to search for mails in my mailbox. But i cannot search mails
> with mails that inlcudes special chars (ä,ö,ü) in the subject.
>

Here's code that works for me with libcurl 7.59.0:

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

Cheers,
-Kyle

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2018-06-07