#include <config.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include "protocol.h"
#include "xmalloc.h"
static char *imap_parsemechlist(const char *str, struct protocol_t *prot)
{
char *ret = xzmalloc(strlen(str)+1);
char *tmp;
int num = 0;
if (strstr(str, "SASL-IR")) {
prot->sasl_cmd.maxlen = INT_MAX;
}
while ((tmp = strstr(str, "AUTH="))) {
char *end = (tmp += 5);
while((*end != ' ') && (*end != '\0')) end++;
if (num++ > 0) strcat(ret, " ");
strlcat(ret, tmp, strlen(ret) + (end - tmp) + 1);
str = end + 1;
}
return ret;
}
static char *nntp_parsesuccess(char *str, const char **status)
{
char *success = NULL;
if (!strncmp(str, "283 ", 4)) {
success = str+4;
}
if (status) *status = NULL;
return success;
}
struct protocol_t protocol[] = {
{ "imap", "imap",
{ "C01 CAPABILITY", "C01 ", &imap_parsemechlist,
{ { " AUTH=", CAPA_AUTH },
{ " STARTTLS", CAPA_STARTTLS },
{ " IDLE", CAPA_IDLE },
{ " MUPDATE", CAPA_MUPDATE },
{ " MULTIAPPEND", CAPA_MULTIAPPEND },
{ NULL, 0 } } },
{ "S01 STARTTLS", "S01 OK", "S01 NO" },
{ "A01 AUTHENTICATE", 0, 0, "A01 OK", "A01 NO", "+ ", "*", NULL },
{ "N01 NOOP", "N01 OK" },
{ "Q01 LOGOUT", "Q01 " } },
{ "pop3", "pop",
{ "CAPA", ".", NULL,
{ { "SASL ", CAPA_AUTH },
{ "STLS", CAPA_STARTTLS },
{ NULL, 0 } } },
{ "STLS", "+OK", "-ERR" },
{ "AUTH", 255, 0, "+OK", "-ERR", "+ ", "*", NULL },
{ "NOOP", "+OK" },
{ "QUIT", "+OK" } },
{ "nntp", "nntp",
{ "CAPABILITIES", ".", NULL,
{ { "SASL ", CAPA_AUTH },
{ "STARTTLS", CAPA_STARTTLS },
{ NULL, 0 } } },
{ "STARTTLS", "382", "580" },
{ "AUTHINFO SASL", 512, 0, "28", "48", "383 ", "*", &nntp_parsesuccess },
{ "DATE", "111" },
{ "QUIT", "205" } },
{ "lmtp", "lmtp",
{ "LHLO murder", "250 ", NULL,
{ { "AUTH ", CAPA_AUTH },
{ "STARTTLS", CAPA_STARTTLS },
{ "PIPELINING", CAPA_PIPELINING },
{ "IGNOREQUOTA", CAPA_IGNOREQUOTA },
{ NULL, 0 } } },
{ "STARTTLS", "220", "454" },
{ "AUTH", 512, 0, "235", "5", "334 ", "*", NULL },
{ "NOOP", "250" },
{ "QUIT", "221" } },
{ "mupdate", "mupdate",
{ NULL, "* OK", NULL,
{ { "* AUTH ", CAPA_AUTH },
{ NULL, 0 } } },
{ "S01 STARTTLS", "S01 OK", "S01 NO" },
{ "A01 AUTHENTICATE", INT_MAX, 1, "A01 OK", "A01 NO", "", "*", NULL },
{ "N01 NOOP", "N01 OK" },
{ "Q01 LOGOUT", "Q01 " } }
};