Fri, 10 Jul 2026 17:56:21 +0200
add jmap_mailbox_get_list
/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 2026 Olaf Wintermann. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include "jmap_methods.h" CxBuffer* jm_mailbox_get_request(cxstring account_id) { CxBuffer *buf = cxBufferCreate(NULL, NULL, 512, CX_BUFFER_AUTO_EXTEND | CX_BUFFER_FREE_CONTENTS); cxBufferPutString(buf, "{\"using\":[" "\"urn:ietf:params:jmap:core\"," "\"urn:ietf:params:jmap:mail\"" "],\"methodCalls\":[" "[\"Mailbox/get\"," "{\"accountId\":\""); cxBufferPutString(buf, account_id); cxBufferPutString(buf, "\",\"ids\":null}," "\"0\"" "]" "]}"); return buf; } CxJsonValue* jm_do_api_request(JMAPSession *sn, CxBuffer *request) { curl_easy_setopt(sn->handle, CURLOPT_URL, sn->apiUrl); curl_easy_setopt(sn->handle, CURLOPT_POST, 1L); //curl_easy_setopt(sn->handle, CURLOPT_READFUNCTION, cxBufferRead); //curl_easy_setopt(sn->handle, CURLOPT_SEEKFUNCTION, cxBufferSeek); //curl_easy_setopt(sn->handle, CURLOPT_READDATA, request); //curl_easy_setopt(sn->handle, CURLOPT_SEEKDATA, request); //curl_easy_setopt(sn->handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)request->size); curl_easy_setopt(sn->handle, CURLOPT_POSTFIELDSIZE, request->size); curl_easy_setopt(sn->handle, CURLOPT_POSTFIELDS, request->space); CxBuffer *response = cxBufferCreate(NULL, NULL, 4096, CX_BUFFER_AUTO_EXTEND | CX_BUFFER_FREE_CONTENTS); curl_easy_setopt(sn->handle, CURLOPT_WRITEFUNCTION, cxBufferWrite); curl_easy_setopt(sn->handle, CURLOPT_WRITEDATA, response); struct curl_slist *headers = NULL; headers = curl_slist_append(headers, "Content-Type: application/json"); headers = curl_slist_append(headers, "Accept: */*"); curl_easy_setopt(sn->handle, CURLOPT_HTTPHEADER, headers); CURLcode ret = curl_easy_perform(sn->handle); curl_slist_free_all(headers); long http_status; curl_easy_getinfo(sn->handle, CURLINFO_RESPONSE_CODE, &http_status); CxJsonValue *json = NULL; if(ret == CURLE_OK) { if(http_status >= 200 && http_status <= 299) { (void)cx_json_from_string(sn->mp->allocator, cx_strn(response->space, response->size), &json); } } cxBufferFree(response); return json; }