2104
2107
imapx_command_start (is, ic);
2112
/* Using custom commands to connect to IMAP servers is not supported on Win32 */
2115
connect_to_server_process (CamelIMAPXServer *is, const gchar *cmd, CamelException *ex)
2117
CamelIMAPXCommand *ic;
2118
CamelStream *cmd_stream;
2123
gchar *child_env[7];
2124
guchar *buffer = NULL;
2127
/* Put full details in the environment, in case the connection
2128
program needs them */
2129
buf = camel_url_to_string(is->url, 0);
2130
child_env[i++] = g_strdup_printf("URL=%s", buf);
2133
child_env[i++] = g_strdup_printf("URLHOST=%s", is->url->host);
2135
child_env[i++] = g_strdup_printf("URLPORT=%d", is->url->port);
2137
child_env[i++] = g_strdup_printf("URLUSER=%s", is->url->user);
2138
if (is->url->passwd)
2139
child_env[i++] = g_strdup_printf("URLPASSWD=%s", is->url->passwd);
2141
child_env[i++] = g_strdup_printf("URLPATH=%s", is->url->path);
2142
child_env[i] = NULL;
2144
/* Now do %h, %u, etc. substitution in cmd */
2145
buf = cmd_copy = g_strdup(cmd);
2147
full_cmd = g_strdup("");
2155
pc = strchr(buf, '%');
2158
tmp = g_strdup_printf("%s%s", full_cmd, buf);
2170
var = is->url->host;
2173
var = is->url->user;
2177
/* If there wasn't a valid %-code, with an actual
2178
variable to insert, pretend we didn't see the % */
2179
pc = strchr(pc + 1, '%');
2182
tmp = g_strdup_printf("%s%.*s%s", full_cmd, len, buf, var);
2190
cmd_stream = camel_stream_process_new ();
2192
ret = camel_stream_process_connect (CAMEL_STREAM_PROCESS(cmd_stream),
2193
full_cmd, (const gchar **)child_env);
2196
g_free(child_env[--i]);
2200
camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL,
2201
_("Connection cancelled"));
2203
camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
2204
_("Could not connect with command \"%s\": %s"),
2205
full_cmd, g_strerror (errno));
2207
camel_object_unref (cmd_stream);
2213
is->stream = (CamelIMAPXStream *) camel_imapx_stream_new(cmd_stream);
2214
camel_object_unref(cmd_stream);
2215
is->is_process_stream = TRUE;
2217
camel_imapx_stream_gets (is->stream, &buffer, &len);
2218
e(printf("Got greeting '%.*s'\n", len, buffer));
2221
camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM,
2222
"No response from server.\n");
2224
} else if (!strncmp((gchar *)buffer, "* PREAUTH", 9)) {
2225
is->state = IMAPX_AUTHENTICATED;
2226
} else if (strncmp((gchar *)buffer, "* OK", 4)) {
2227
camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM,
2228
"Unrecognised greeting from server: %.*s\n",
2233
ic = camel_imapx_command_new("CAPABILITY", NULL, "CAPABILITY");
2234
imapx_command_run(is, ic);
2236
if (camel_exception_is_set (ic->ex) || ic->status->result != IMAPX_OK) {
2237
if (!camel_exception_is_set (ic->ex))
2238
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, "%s", ic->status->text);
2240
camel_exception_xfer (ex, ic->ex);
2242
camel_imapx_command_free(ic);
2245
camel_imapx_command_free(ic);
2249
#endif /* G_OS_WIN32 */
2108
2252
imapx_connect_to_server (CamelIMAPXServer *is, CamelException *ex)
2282
2435
if (camel_exception_is_set (ex))
2283
2436
goto exception;
2285
if (service->url->passwd == NULL) {
2438
if (is->state == IMAPX_AUTHENTICATED)
2441
if (!authtype && service->url->authmech) {
2442
if (is->cinfo && !g_hash_table_lookup (is->cinfo->auth_types, service->url->authmech)) {
2443
camel_exception_setv (
2444
ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
2445
_("IMAP server %s does not support requested "
2446
"authentication type %s"),
2448
service->url->authmech);
2452
authtype = camel_sasl_authtype (service->url->authmech);
2454
camel_exception_setv (
2455
ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
2456
_("No support for authentication type %s"),
2457
service->url->authmech);
2462
if (service->url->passwd == NULL && (!authtype || authtype->need_password)) {
2286
2463
gchar *base_prompt;
2287
2464
gchar *full_prompt;
2314
if (service->url->authmech
2315
&& (sasl = camel_sasl_new("imap", service->url->authmech, NULL))) {
2316
ic = camel_imapx_command_new("AUTHENTICATE", NULL, "AUTHENTICATE %A", sasl);
2491
if (authtype && (sasl = camel_sasl_new ("imap", authtype->authproto, service))) {
2492
ic = camel_imapx_command_new ("AUTHENTICATE", NULL, "AUTHENTICATE %A", sasl);
2317
2493
camel_object_unref(sasl);
2319
2495
ic = camel_imapx_command_new("LOGIN", NULL, "LOGIN %s %s", service->url->user, service->url->passwd);
2427
2603
job->u.get_message.body_len = -1;
2428
2604
} else if (job->u.get_message.use_multi_fetch) {
2430
if (!failed && job->u.get_message.fetch_offset <= job->u.get_message.size) {
2605
gsize really_fetched = CAMEL_SEEKABLE_STREAM(job->u.get_message.stream)->position;
2606
/* Don't automatically stop when we reach the reported message
2607
size -- some crappy servers (like Microsoft Exchange) have
2608
a tendency to lie about it. Keep going (one request at a
2609
time) until the data actually stop coming. */
2610
if (job->u.get_message.fetch_offset < job->u.get_message.size ||
2611
job->u.get_message.fetch_offset == really_fetched) {
2431
2612
camel_imapx_command_free (ic);
2433
2614
camel_operation_progress (job->op, (job->u.get_message.fetch_offset *100)/job->u.get_message.size);
3633
3812
cancel_all_jobs (CamelIMAPXServer *is, CamelException *ex)
3635
CamelIMAPXCommand *cw, *cn;
3814
CamelIMAPXCommand **cw, *ic;
3638
3817
while (i < 2) {
3639
3818
QUEUE_LOCK(is);
3641
cw = (CamelIMAPXCommand *) is->queue.head;
3820
cw = (CamelIMAPXCommand **) &is->queue.head;
3643
cw = (CamelIMAPXCommand *) is->active.head;
3822
cw = (CamelIMAPXCommand **) &is->active.head;
3824
while ((*cw)->next) {
3826
camel_dlist_remove ((CamelDListNode *)ic);
3829
camel_exception_set (ic->ex, ex->id, ex->desc);
3830
ic->complete (is, ic);
3646
3834
QUEUE_UNLOCK(is);
3650
camel_dlist_remove ((CamelDListNode *)cw);
3653
camel_exception_set (cw->ex, ex->id, ex->desc);
3655
cw->complete (is, cw);
3726
if (!is->is_ssl_stream) {
3898
if (is->is_process_stream) {
3899
GPollFD fds[2] = { {0, 0, 0}, {0, 0, 0} };
3902
fds[0].fd = ((CamelStreamProcess *)is->stream->source)->sockfd;
3903
fds[0].events = G_IO_IN;
3904
fds[1].fd = camel_operation_cancel_fd (op);
3905
fds[1].events = G_IO_IN;
3906
res = g_poll(fds, 2, 1000*30);
3908
g_usleep(1) /* ?? */ ;
3911
else if (fds[0].revents & G_IO_IN) {
3912
parse_contents (is, &ex);
3913
} else if (fds[1].revents & G_IO_IN)
3918
if (!is->is_ssl_stream && !is->is_process_stream) {
3727
3919
GPollFD fds[2] = { {0, 0, 0}, {0, 0, 0} };