Commit 764f66c0 764f66c05a7a261bfaff6c1f120f8adc85e239d0 by Alain Magloire

New file to deal with STLS.

1 parent e7e57682
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include "../md5.h"
23 #include <stdio.h>
24 #include <string.h>
25 #include <errno.h>
26
27 #include <mailutils/sys/pop3.h>
28 #include <mailutils/tls.h>
29
30 /*
31 * STLS
32 * We have to assume that the caller check the CAPA and TLS was supported.
33 */
34 int
35 mu_pop3_stls (mu_pop3_t pop3)
36 {
37 #ifdef WITH_TLS
38 int status;
39
40 /* Sanity checks. */
41 if (pop3 == NULL)
42 {
43 return EINVAL;
44 }
45
46 switch (pop3->state)
47 {
48 case MU_POP3_NO_STATE:
49 status = mu_pop3_writeline (pop3, "STLS\r\n");
50 MU_POP3_CHECK_ERROR (pop3, status);
51 mu_pop3_debug_cmd (pop3);
52 pop3->state = MU_POP3_STLS;
53
54 case MU_POP3_STLS:
55 status = mu_pop3_send (pop3);
56 MU_POP3_CHECK_EAGAIN (pop3, status);
57 pop3->acknowledge = 0;
58 pop3->state = MU_POP3_STLS_ACK;
59
60 case MU_POP3_STLS_ACK:
61 {
62 stream_t tls_stream;
63 status = mu_pop3_response (pop3, NULL, 0, NULL);
64 MU_POP3_CHECK_EAGAIN (pop3, status);
65 mu_pop3_debug_ack (pop3);
66 MU_POP3_CHECK_OK (pop3);
67 status = tls_stream_create_client_from_tcp (&tls_stream, pop3->carrier, 0);
68 MU_POP3_CHECK_ERROR (pop3, status);
69 pop3->carrier = tls_stream;
70 pop3->state = MU_POP3_STLS_CONNECT;
71 break;
72 }
73
74 case MU_POP3_STLS_CONNECT:
75 status = stream_open (pop3->carrier);
76 MU_POP3_CHECK_EAGAIN (pop3, status);
77 pop3->state = MU_POP3_NO_STATE;
78 break;
79
80 /* They must deal with the error first by reopening. */
81 case MU_POP3_ERROR:
82 status = ECANCELED;
83 break;
84
85 /* No case in the switch another operation was in progress. */
86 default:
87 status = EINPROGRESS;
88 }
89
90 return status;
91 #else
92 (void)pop3;
93 return ENOTSUP;
94 #endif
95 }