aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--imap.c146
1 files changed, 77 insertions, 69 deletions
diff --git a/imap.c b/imap.c
index b7dae1af..1f62f696 100644
--- a/imap.c
+++ b/imap.c
@@ -65,82 +65,90 @@ static int imap_ok(int sock, char *argbuf)
if (islower((unsigned char)*cp))
*cp = toupper((unsigned char)*cp);
- /* interpret untagged status responses */
- if (strstr(buf, "* CAPABILITY"))
- {
- strlcpy(capabilities, buf + 12, sizeof(capabilities));
- }
- else if (strstr(buf, "EXISTS"))
- {
- count = atoi(buf+2);
- /*
- * Don't trust the message count passed by the server.
- * Without this check, it might be possible to do a
- * DNS-spoofing attack that would pass back a ridiculous
- * count, and allocate a malloc area that would overlap
- * a portion of the stack.
- */
- if (count > INT_MAX/sizeof(int))
- {
- report(stderr, GT_("bogus message count!"));
- return(PS_PROTOCOL);
+ /* interpret untagged status responses
+ * First check if we really have an untagged response, starting
+ * with "*" SPACE. Then, for each individual check, use a BLANK
+ * before the word to avoid confusion with the \Recent flag or
+ * similar */
+ if (buf[0] == '*' && buf[1] == ' ') {
+ if (strstr(buf, " CAPABILITY")) {
+ strlcpy(capabilities, buf + 12, sizeof(capabilities));
}
-
- /*
- * Nasty kluge to handle RFC2177 IDLE. If we know we're idling
- * we can't wait for the tag matching the IDLE; we have to tell the
- * server the IDLE is finished by shipping back a DONE when we
- * see an EXISTS. Only after that will a tagged response be
- * shipped. The idling flag also gets cleared on a timeout.
- */
- if (stage == STAGE_IDLE)
+ else if (strstr(buf, " EXISTS"))
{
- /* If IDLE isn't supported, we were only sending NOOPs anyway. */
- if (has_idle)
+ count = atoi(buf+2);
+ /*
+ * Don't trust the message count passed by the server.
+ * Without this check, it might be possible to do a
+ * DNS-spoofing attack that would pass back a ridiculous
+ * count, and allocate a malloc area that would overlap
+ * a portion of the stack.
+ */
+ if (count > INT_MAX/sizeof(int))
{
- /* we do our own write and report here to disable tagging */
- SockWrite(sock, "DONE\r\n", 6);
- if (outlevel >= O_MONITOR)
- report(stdout, "IMAP> DONE\n");
+ report(stderr, GT_("bogus message count!"));
+ return(PS_PROTOCOL);
}
- mytimeout = saved_timeout;
- stage = STAGE_FETCH;
+ /*
+ * Nasty kluge to handle RFC2177 IDLE. If we know we're idling
+ * we can't wait for the tag matching the IDLE; we have to tell the
+ * server the IDLE is finished by shipping back a DONE when we
+ * see an EXISTS. Only after that will a tagged response be
+ * shipped. The idling flag also gets cleared on a timeout.
+ */
+ if (stage == STAGE_IDLE)
+ {
+ /* If IDLE isn't supported, we were only sending NOOPs anyway. */
+ if (has_idle)
+ {
+ /* we do our own write and report here to disable tagging */
+ SockWrite(sock, "DONE\r\n", 6);
+ if (outlevel >= O_MONITOR)
+ report(stdout, "IMAP> DONE\n");
+ }
+
+ mytimeout = saved_timeout;
+ stage = STAGE_FETCH;
+ }
+ }
+ else if (strstr(buf, " RECENT"))
+ {
+ recentcount_ok = 1;
+ recentcount = atoi(buf+2);
+ }
+ else if (strstr(buf, " EXPUNGE"))
+ {
+ /* the response "* 10 EXPUNGE" means that the currently
+ * tenth (i.e. only one) message has been deleted */
+ if (atoi(buf+2) > 0)
+ count--;
+ if (count < 0)
+ count = 0;
+ }
+ else if (strstr(buf, " PREAUTH"))
+ {
+ preauth = TRUE;
+ }
+ /*
+ * The server may decide to make the mailbox read-only,
+ * which causes fetchmail to go into a endless loop
+ * fetching the same message over and over again.
+ *
+ * However, for check_only, we use EXAMINE which will
+ * mark the mailbox read-only as per the RFC.
+ *
+ * This checks for the condition and aborts if
+ * the mailbox is read-only.
+ *
+ * See RFC 2060 section 6.3.1 (SELECT).
+ * See RFC 2060 section 6.3.2 (EXAMINE).
+ */
+ else if (!check_only && strstr(buf, "[READ-ONLY]"))
+ {
+ return(PS_LOCKBUSY);
}
}
- /* a space is required to avoid confusion with the \Recent flag */
- else if (strstr(buf, " RECENT"))
- {
- recentcount_ok = 1;
- recentcount = atoi(buf+2);
- }
- else if (strstr(buf, "EXPUNGE") && !strstr(buf, "OK"))
- {
- /* the response "* 10 EXPUNGE" means that the currently
- * tenth (i.e. only one) message has been deleted */
- if (atoi(buf+2) > 0)
- count--;
- if (count < 0)
- count = 0;
- }
- else if (strstr(buf, "PREAUTH"))
- preauth = TRUE;
- /*
- * The server may decide to make the mailbox read-only,
- * which causes fetchmail to go into a endless loop
- * fetching the same message over and over again.
- *
- * However, for check_only, we use EXAMINE which will
- * mark the mailbox read-only as per the RFC.
- *
- * This checks for the condition and aborts if
- * the mailbox is read-only.
- *
- * See RFC 2060 section 6.3.1 (SELECT).
- * See RFC 2060 section 6.3.2 (EXAMINE).
- */
- else if (!check_only && strstr(buf, "[READ-ONLY]"))
- return(PS_LOCKBUSY);
} while
(tag[0] != '\0' && strncmp(buf, tag, strlen(tag)));
#n331'>331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563