(_pop_data): Added new variable pops.
(_mailbox_pop_and_pops_init): New function. (_mailbox_pops_init): Likewise. (_mailbox_pop_init): Call _mailbox_pop_and_pops_init. (pop_open): Handle POPS connection.
Showing
1 changed file
with
41 additions
and
6 deletions
... | @@ -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 | int pops; /* POPS or POP? */ | ||
193 | char *greeting_banner; /* A greeting banner */ | 194 | char *greeting_banner; /* A greeting banner */ |
194 | unsigned long capa; /* Server capabilities */ | 195 | unsigned long capa; /* Server capabilities */ |
195 | enum pop_state state; | 196 | enum pop_state state; |
... | @@ -321,8 +322,8 @@ while (0) | ... | @@ -321,8 +322,8 @@ while (0) |
321 | 322 | ||
322 | 323 | ||
323 | /* Allocate mu_mailbox_t, allocate pop internal structures. */ | 324 | /* Allocate mu_mailbox_t, allocate pop internal structures. */ |
324 | int | 325 | static int |
325 | _mailbox_pop_init (mu_mailbox_t mbox) | 326 | _mailbox_pop_and_pops_init (mu_mailbox_t mbox, int pops) |
326 | { | 327 | { |
327 | pop_data_t mpd; | 328 | pop_data_t mpd; |
328 | int status = 0; | 329 | int status = 0; |
... | @@ -333,8 +334,8 @@ _mailbox_pop_init (mu_mailbox_t mbox) | ... | @@ -333,8 +334,8 @@ _mailbox_pop_init (mu_mailbox_t mbox) |
333 | return ENOMEM; | 334 | return ENOMEM; |
334 | 335 | ||
335 | mpd->mbox = mbox; /* Back pointer. */ | 336 | mpd->mbox = mbox; /* Back pointer. */ |
336 | |||
337 | mpd->state = POP_NO_STATE; /* Init with no state. */ | 337 | mpd->state = POP_NO_STATE; /* Init with no state. */ |
338 | mpd->pops = pops; | ||
338 | 339 | ||
339 | /* Initialize the structure. */ | 340 | /* Initialize the structure. */ |
340 | mbox->_destroy = pop_destroy; | 341 | mbox->_destroy = pop_destroy; |
... | @@ -367,6 +368,18 @@ _mailbox_pop_init (mu_mailbox_t mbox) | ... | @@ -367,6 +368,18 @@ _mailbox_pop_init (mu_mailbox_t mbox) |
367 | return status; | 368 | return status; |
368 | } | 369 | } |
369 | 370 | ||
371 | int | ||
372 | _mailbox_pop_init (mu_mailbox_t mbox) | ||
373 | { | ||
374 | return _mailbox_pop_and_pops_init (mbox, 0); | ||
375 | } | ||
376 | |||
377 | int | ||
378 | _mailbox_pops_init (mu_mailbox_t mbox) | ||
379 | { | ||
380 | return _mailbox_pop_and_pops_init (mbox, 1); | ||
381 | } | ||
382 | |||
370 | /* Cleaning up all the ressources associate with a pop mailbox. */ | 383 | /* Cleaning up all the ressources associate with a pop mailbox. */ |
371 | static void | 384 | static void |
372 | pop_destroy (mu_mailbox_t mbox) | 385 | pop_destroy (mu_mailbox_t mbox) |
... | @@ -708,7 +721,7 @@ pop_open (mu_mailbox_t mbox, int flags) | ... | @@ -708,7 +721,7 @@ pop_open (mu_mailbox_t mbox, int flags) |
708 | pop_data_t mpd = mbox->data; | 721 | pop_data_t mpd = mbox->data; |
709 | int status; | 722 | int status; |
710 | const char *host; | 723 | const char *host; |
711 | long port = MU_POP_PORT; | 724 | long port = mpd->pops ? MU_POPS_PORT : MU_POP_PORT; |
712 | 725 | ||
713 | /* Sanity checks. */ | 726 | /* Sanity checks. */ |
714 | if (mpd == NULL) | 727 | if (mpd == NULL) |
... | @@ -751,7 +764,28 @@ pop_open (mu_mailbox_t mbox, int flags) | ... | @@ -751,7 +764,28 @@ pop_open (mu_mailbox_t mbox, int flags) |
751 | if (mbox->stream == NULL) | 764 | if (mbox->stream == NULL) |
752 | { | 765 | { |
753 | status = mu_tcp_stream_create (&mbox->stream, host, port, mbox->flags); | 766 | status = mu_tcp_stream_create (&mbox->stream, host, port, mbox->flags); |
754 | CHECK_ERROR(mpd, status); | 767 | CHECK_ERROR (mpd, status); |
768 | |||
769 | #ifdef WITH_TLS | ||
770 | if (mpd->pops) | ||
771 | { | ||
772 | mu_stream_t newstr; | ||
773 | |||
774 | status = mu_stream_open (mbox->stream); | ||
775 | CHECK_EAGAIN (mpd, status); | ||
776 | CHECK_ERROR_CLOSE (mbox, mpd, status); | ||
777 | |||
778 | status = mu_tls_stream_create_client_from_tcp (&newstr, mbox->stream, 0); | ||
779 | if (status != 0) | ||
780 | { | ||
781 | mu_error ("pop_open: mu_tls_stream_create_client_from_tcp: %s", | ||
782 | mu_strerror (status)); | ||
783 | return status; | ||
784 | } | ||
785 | mbox->stream = newstr; | ||
786 | } | ||
787 | #endif /* WITH_TLS */ | ||
788 | |||
755 | /* Using the awkward mu_stream_t buffering. */ | 789 | /* Using the awkward mu_stream_t buffering. */ |
756 | mu_stream_setbufsiz (mbox->stream, BUFSIZ); | 790 | mu_stream_setbufsiz (mbox->stream, BUFSIZ); |
757 | } | 791 | } |
... | @@ -806,6 +840,7 @@ pop_open (mu_mailbox_t mbox, int flags) | ... | @@ -806,6 +840,7 @@ pop_open (mu_mailbox_t mbox, int flags) |
806 | 840 | ||
807 | case POP_STLS: | 841 | case POP_STLS: |
808 | case POP_STLS_ACK: | 842 | case POP_STLS_ACK: |
843 | if (!mpd->pops) | ||
809 | pop_stls (mbox); | 844 | pop_stls (mbox); |
810 | mpd->state = POP_AUTH; | 845 | mpd->state = POP_AUTH; |
811 | 846 | ||
... | @@ -887,7 +922,7 @@ pop_close (mu_mailbox_t mbox) | ... | @@ -887,7 +922,7 @@ pop_close (mu_mailbox_t mbox) |
887 | 922 | ||
888 | default: | 923 | default: |
889 | /* | 924 | /* |
890 | mu_error ("pop_close unknow state"); | 925 | mu_error ("pop_close unknown state"); |
891 | */ | 926 | */ |
892 | break; | 927 | break; |
893 | } /* UPDATE state. */ | 928 | } /* UPDATE state. */ | ... | ... |
-
Please register or sign in to post a comment