1 /* imap.c --- Implement IMAP profile of SASL login.
2 * Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Simon Josefsson
4 * This file is part of GNU SASL.
6 * This program 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 3 of the License, or
9 * (at your option) any later version.
11 * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
23 #define MAX_LINE_LENGTH BUFSIZ
37 imap_has_starttls (void)
42 if (!writeln (". CAPABILITY"))
48 has_tls
= strstr (in
, "STARTTLS") != NULL
;
61 if (!writeln (". STARTTLS"))
71 imap_select_mechanism (char **mechlist
)
75 if (args_info
.server_flag
)
77 if (!args_info
.quiet_given
)
78 fprintf (stderr
, _("Chose SASL mechanisms:\n"));
85 if (!writeln (". CAPABILITY"))
91 /* XXX parse IMAP capability line */
103 imap_authenticate (const char *mech
)
105 if (args_info
.server_flag
)
107 if (!args_info
.quiet_given
)
108 fprintf (stderr
, _("Using mechanism:\n"));
113 char input
[MAX_LINE_LENGTH
];
115 sprintf (input
, ". AUTHENTICATE %s", mech
);
116 if (!writeln (input
))
124 imap_step_send (const char *data
)
126 char input
[MAX_LINE_LENGTH
];
128 if (args_info
.server_flag
)
129 sprintf (input
, "+ %s", data
);
131 sprintf (input
, "%s", data
);
132 if (!writeln (input
))
139 imap_step_recv (char **data
)
148 if (!args_info
.server_flag
)
150 if (p
[0] != '+' || p
[1] != ' ')
152 fprintf (stderr
, _("error: Server did not return expected SASL "
153 "data (it must begin with '+ '):\n%s\n"), p
);
157 memmove (&p
[0], &p
[2], strlen (p
) - 1);
160 if (p
[strlen (p
) - 1] == '\n')
161 p
[strlen (p
) - 1] = '\0';
162 if (p
[strlen (p
) - 1] == '\r')
163 p
[strlen (p
) - 1] = '\0';
169 imap_auth_finish (void)
184 if (!writeln (". LOGOUT"))
187 /* read "* BYE ..." */
193 /* read ". OK ..." */