Commit 7378e729 7378e72919f5eceaf0bfa89e5e2f0dd1c687a9b8 by Wojciech Polak

Fixed APOP handling.

1 parent 6dbd3ee3
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2003, 2005 Free Software Foundation, Inc. 2 Copyright (C) 1999,2000,2001,2003,2005,2007 Free Software Foundation, Inc.
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public 5 modify it under the terms of the GNU Lesser General Public
...@@ -190,6 +190,7 @@ struct _pop_data ...@@ -190,6 +190,7 @@ struct _pop_data
190 void *func; /* Indicate a command is in operation, busy. */ 190 void *func; /* Indicate a command is in operation, busy. */
191 size_t id; /* A second level of distincion, we maybe in the same function 191 size_t id; /* A second level of distincion, we maybe in the same function
192 but working on a different message. */ 192 but working on a different message. */
193 char *greeting_banner; /* A greeting banner */
193 unsigned long capa; /* Server capabilities */ 194 unsigned long capa; /* Server capabilities */
194 enum pop_state state; 195 enum pop_state state;
195 pop_message_t *pmessages; 196 pop_message_t *pmessages;
...@@ -388,6 +389,8 @@ pop_destroy (mu_mailbox_t mbox) ...@@ -388,6 +389,8 @@ pop_destroy (mu_mailbox_t mbox)
388 mpd->pmessages[i] = NULL; 389 mpd->pmessages[i] = NULL;
389 } 390 }
390 } 391 }
392 if (mpd->greeting_banner)
393 free (mpd->greeting_banner);
391 if (mpd->buffer) 394 if (mpd->buffer)
392 free (mpd->buffer); 395 free (mpd->buffer);
393 if (mpd->pmessages) 396 if (mpd->pmessages)
...@@ -417,7 +420,6 @@ pop_capa (mu_mailbox_t mbox) ...@@ -417,7 +420,6 @@ pop_capa (mu_mailbox_t mbox)
417 mpd->state = POP_CAPA_ACK; 420 mpd->state = POP_CAPA_ACK;
418 421
419 /* POP_CAPA_ACK */ 422 /* POP_CAPA_ACK */
420
421 status = pop_read_ack (mpd); 423 status = pop_read_ack (mpd);
422 CHECK_EAGAIN (mpd, status); 424 CHECK_EAGAIN (mpd, status);
423 MAILBOX_DEBUG0 (mbox, MU_DEBUG_PROT, mpd->buffer); 425 MAILBOX_DEBUG0 (mbox, MU_DEBUG_PROT, mpd->buffer);
...@@ -645,11 +647,17 @@ pop_stls (mu_mailbox_t mbox) ...@@ -645,11 +647,17 @@ pop_stls (mu_mailbox_t mbox)
645 647
646 status = pop_writeline (mpd, "STLS\r\n"); 648 status = pop_writeline (mpd, "STLS\r\n");
647 CHECK_ERROR (mpd, status); 649 CHECK_ERROR (mpd, status);
650 MAILBOX_DEBUG0 (mbox, MU_DEBUG_PROT, mpd->buffer);
651
648 status = pop_write (mpd); 652 status = pop_write (mpd);
649 CHECK_EAGAIN (mpd, status); 653 CHECK_EAGAIN (mpd, status);
654 mpd->state = POP_STLS_ACK;
655
656 /* POP_STLS_ACK */
650 status = pop_read_ack (mpd); 657 status = pop_read_ack (mpd);
651 CHECK_ERROR (mpd, status); 658 CHECK_ERROR (mpd, status);
652 MAILBOX_DEBUG0 (mbox, MU_DEBUG_PROT, mpd->buffer); 659 MAILBOX_DEBUG0 (mbox, MU_DEBUG_PROT, mpd->buffer);
660
653 if (strncasecmp (mpd->buffer, "+OK", 3) != 0) 661 if (strncasecmp (mpd->buffer, "+OK", 3) != 0)
654 return -1; 662 return -1;
655 663
...@@ -674,7 +682,7 @@ pop_open (mu_mailbox_t mbox, int flags) ...@@ -674,7 +682,7 @@ pop_open (mu_mailbox_t mbox, int flags)
674 int status; 682 int status;
675 char *host; 683 char *host;
676 size_t hostlen = 0; 684 size_t hostlen = 0;
677 long port = 110; 685 long port = MU_POP_PORT;
678 686
679 /* Sanity checks. */ 687 /* Sanity checks. */
680 if (mpd == NULL) 688 if (mpd == NULL)
...@@ -749,7 +757,7 @@ pop_open (mu_mailbox_t mbox, int flags) ...@@ -749,7 +757,7 @@ pop_open (mu_mailbox_t mbox, int flags)
749 757
750 case POP_GREETINGS: 758 case POP_GREETINGS:
751 { 759 {
752 /* Swallow the greetings. */ 760 int gblen = 0;
753 status = pop_read_ack (mpd); 761 status = pop_read_ack (mpd);
754 CHECK_EAGAIN (mpd, status); 762 CHECK_EAGAIN (mpd, status);
755 MAILBOX_DEBUG0 (mbox, MU_DEBUG_PROT, mpd->buffer); 763 MAILBOX_DEBUG0 (mbox, MU_DEBUG_PROT, mpd->buffer);
...@@ -757,6 +765,13 @@ pop_open (mu_mailbox_t mbox, int flags) ...@@ -757,6 +765,13 @@ pop_open (mu_mailbox_t mbox, int flags)
757 { 765 {
758 CHECK_ERROR_CLOSE (mbox, mpd, EACCES); 766 CHECK_ERROR_CLOSE (mbox, mpd, EACCES);
759 } 767 }
768 gblen = strlen (mpd->buffer);
769 mpd->greeting_banner = calloc (gblen, 1);
770 if (mpd->greeting_banner == NULL)
771 {
772 CHECK_ERROR (mpd, ENOMEM);
773 }
774 memcpy (mpd->greeting_banner, mpd->buffer, gblen);
760 mpd->state = POP_CAPA; 775 mpd->state = POP_CAPA;
761 } 776 }
762 777
...@@ -869,6 +884,9 @@ pop_close (mu_mailbox_t mbox) ...@@ -869,6 +884,9 @@ pop_close (mu_mailbox_t mbox)
869 } 884 }
870 } 885 }
871 /* And clear any residue. */ 886 /* And clear any residue. */
887 if (mpd->greeting_banner)
888 free (mpd->greeting_banner);
889 mpd->greeting_banner = NULL;
872 if (mpd->pmessages) 890 if (mpd->pmessages)
873 free (mpd->pmessages); 891 free (mpd->pmessages);
874 mpd->pmessages = NULL; 892 mpd->pmessages = NULL;
...@@ -2084,11 +2102,11 @@ pop_get_timestamp (pop_data_t mpd) ...@@ -2084,11 +2102,11 @@ pop_get_timestamp (pop_data_t mpd)
2084 char *timestamp = NULL; 2102 char *timestamp = NULL;
2085 size_t len; 2103 size_t len;
2086 2104
2087 len = strlen (mpd->buffer); 2105 len = strlen (mpd->greeting_banner);
2088 right = memchr (mpd->buffer, '<', len); 2106 right = memchr (mpd->greeting_banner, '<', len);
2089 if (right) 2107 if (right)
2090 { 2108 {
2091 len = len - (right - mpd->buffer); 2109 len = len - (right - mpd->greeting_banner);
2092 left = memchr (right, '>', len); 2110 left = memchr (right, '>', len);
2093 if (left) 2111 if (left)
2094 { 2112 {
......