1 /* imap.c --- Implement IMAP profile of SASL login.
2 * Copyright (C) 2002, 2003, 2004, 2005 Simon Josefsson
4 * This file is part of GNU SASL.
6 * GNU SASL is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * GNU SASL is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GNU SASL; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #define MAX_LINE_LENGTH BUFSIZ
38 imap_has_starttls (void)
43 if (!writeln (". CAPABILITY"))
49 has_tls
= strstr (in
, "STARTTLS") != NULL
;
62 if (!writeln (". STARTTLS"))
72 imap_select_mechanism (char **mechlist
)
76 if (args_info
.server_flag
)
78 if (!args_info
.quiet_given
)
79 fprintf (stderr
, _("Chose SASL mechanisms:\n"));
86 if (!writeln (". CAPABILITY"))
92 /* XXX parse IMAP capability line */
104 imap_authenticate (const char *mech
)
106 if (args_info
.server_flag
)
108 if (!args_info
.quiet_given
)
109 fprintf (stderr
, _("Using mechanism:\n"));
114 char input
[MAX_LINE_LENGTH
];
116 sprintf (input
, ". AUTHENTICATE %s", mech
);
117 if (!writeln (input
))
125 imap_step_send (const char *data
)
127 char input
[MAX_LINE_LENGTH
];
129 if (args_info
.server_flag
)
130 sprintf (input
, "+ %s", data
);
132 sprintf (input
, "%s", data
);
133 if (!writeln (input
))
140 imap_step_recv (char **data
)
149 if (p
[0] != '+' || p
[1] != ' ')
151 fprintf (stderr
, _("error: Server did not return expected SASL "
152 "data (it must begin with '+ '):\n%s\n"), p
);
156 memmove (&p
[0], &p
[2], strlen (p
) - 1);
158 if (p
[strlen (p
) - 1] == '\n')
159 p
[strlen (p
) - 1] = '\0';
160 if (p
[strlen (p
) - 1] == '\r')
161 p
[strlen (p
) - 1] = '\0';
167 imap_auth_finish (void)
182 if (!writeln (". LOGOUT"))
185 /* read "* BYE ..." */
191 /* read ". OK ..." */