| |
1 /* |
| |
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
| |
3 * |
| |
4 * Copyright 2026 Olaf Wintermann. All rights reserved. |
| |
5 * |
| |
6 * Redistribution and use in source and binary forms, with or without |
| |
7 * modification, are permitted provided that the following conditions are met: |
| |
8 * |
| |
9 * 1. Redistributions of source code must retain the above copyright |
| |
10 * notice, this list of conditions and the following disclaimer. |
| |
11 * |
| |
12 * 2. Redistributions in binary form must reproduce the above copyright |
| |
13 * notice, this list of conditions and the following disclaimer in the |
| |
14 * documentation and/or other materials provided with the distribution. |
| |
15 * |
| |
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| |
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| |
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| |
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| |
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| |
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| |
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| |
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| |
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| |
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| |
26 * POSSIBILITY OF SUCH DAMAGE. |
| |
27 */ |
| |
28 |
| |
29 #include "jmmail.h" |
| |
30 |
| |
31 #include <assert.h> |
| |
32 #include <stdio.h> |
| |
33 #include <stdlib.h> |
| |
34 #include <string.h> |
| |
35 #include <stdbool.h> |
| |
36 #include <errno.h> |
| |
37 #include <time.h> |
| |
38 #include <sys/types.h> |
| |
39 #ifndef _WIN32 |
| |
40 #include <sys/wait.h> |
| |
41 #include <unistd.h> |
| |
42 #endif |
| |
43 #include <cx/string.h> |
| |
44 #include <cx/printf.h> |
| |
45 #include <cx/hash_map.h> |
| |
46 #include <cx/linked_list.h> |
| |
47 #include <cx/streams.h> |
| |
48 |
| |
49 int jmap_main(int argc, char **argv); |
| |
50 |
| |
51 #ifdef _WIN32 |
| |
52 |
| |
53 #define strcasecmp _stricmp |
| |
54 |
| |
55 static char* wchar2utf8(const wchar_t *wstr, size_t wlen) { |
| |
56 size_t maxlen = wlen * 4; |
| |
57 char *ret = malloc(maxlen + 1); |
| |
58 int ret_len = WideCharToMultiByte( |
| |
59 CP_UTF8, |
| |
60 0, |
| |
61 wstr, |
| |
62 wlen, |
| |
63 ret, |
| |
64 maxlen, |
| |
65 NULL, |
| |
66 NULL); |
| |
67 ret[ret_len] = 0; |
| |
68 return ret; |
| |
69 } |
| |
70 |
| |
71 int wmain(int argc, wchar_t **argv) { |
| |
72 char **argv_utf8 = calloc(argc, sizeof(char*)); |
| |
73 for(int i=0;i<argc;i++) { |
| |
74 argv_utf8[i] = wchar2utf8(argv[i], wcslen(argv[i])); |
| |
75 } |
| |
76 |
| |
77 int ret = jmap_main(argc, argv_utf8); |
| |
78 |
| |
79 |
| |
80 for(int i=0;i<argc;i++) { |
| |
81 free(argv_utf8[i]); |
| |
82 } |
| |
83 free(argv_utf8); |
| |
84 |
| |
85 return ret; |
| |
86 } |
| |
87 #else |
| |
88 int main(int argc, char **argv) { |
| |
89 return jmap_main(argc, argv); |
| |
90 } |
| |
91 #endif |
| |
92 |
| |
93 |
| |
94 int jmap_main(int argc, char **argv) { |
| |
95 if(argc < 4) { |
| |
96 fprintf(stderr, "Missing args\n"); |
| |
97 //print_usage(argv[0]); |
| |
98 return -1; |
| |
99 } |
| |
100 |
| |
101 putenv("LC_TIME=C"); |
| |
102 |
| |
103 const char *session_url = argv[1]; |
| |
104 const char *user = argv[2]; |
| |
105 const char *password = argv[3]; |
| |
106 |
| |
107 JMAPSession *sn = jmap_session_new_with_user(session_url, user, password); |
| |
108 |
| |
109 |
| |
110 return 0; |
| |
111 } |