2 * Copyright (c) 1989 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
8 RCSID("$Id: pop_get_command.c,v 1.15 1999/09/16 20:38:49 assar Exp $");
11 * get_command: Extract the command from an input line form a POP client
14 static state_table states[] = {
15 {auth1, "user", 1, 1, pop_user, {auth1, auth2}},
16 {auth2, "pass", 1, 99, pop_pass, {auth1, trans}},
18 {auth2, "rpop", 1, 1, pop_rpop, {auth1, trans}},
20 {auth1, "quit", 0, 0, pop_quit, {halt, halt}},
21 {auth2, "quit", 0, 0, pop_quit, {halt, halt}},
22 {trans, "stat", 0, 0, pop_stat, {trans, trans}},
23 {trans, "list", 0, 1, pop_list, {trans, trans}},
24 {trans, "retr", 1, 1, pop_send, {trans, trans}},
25 {trans, "dele", 1, 1, pop_dele, {trans, trans}},
26 {trans, "noop", 0, 0, NULL, {trans, trans}},
27 {trans, "rset", 0, 0, pop_rset, {trans, trans}},
28 {trans, "top", 2, 2, pop_send, {trans, trans}},
29 {trans, "last", 0, 0, pop_last, {trans, trans}},
30 {trans, "quit", 0, 0, pop_updt, {halt, halt}},
31 {trans, "help", 0, 0, pop_help, {trans, trans}},
33 {trans, "uidl", 0, 1, pop_uidl, {trans, trans}},
36 {trans, "xover", 0, 0, pop_xover, {trans, trans}},
39 {trans, "xdele", 1, 2, pop_xdele, {trans, trans}},
41 {(state) 0, NULL, 0, 0, NULL, {halt, halt}},
45 pop_get_command(POP *p, char *mp)
48 char buf[MAXMSGLINELEN];
50 /* Save a copy of the original client line */
52 if(p->debug) strlcpy (buf, mp, sizeof(buf));
55 /* Parse the message into the parameter array */
56 if ((p->parm_count = pop_parse(p,mp)) < 0) return(NULL);
58 /* Do not log cleartext passwords */
61 if(strcmp(p->pop_command,"pass") == 0)
62 pop_log(p,POP_DEBUG,"Received: \"%s xxxxxxxxx\"",p->pop_command);
64 /* Remove trailing <LF> */
65 buf[strlen(buf)-2] = '\0';
66 pop_log(p,POP_DEBUG,"Received: \"%s\"",buf);
71 /* Search for the POP command in the command/state table */
72 for (s = states; s->command; s++) {
74 /* Is this a valid command for the current operating state? */
75 if (strcmp(s->command,p->pop_command) == 0
76 && s->ValidCurrentState == p->CurrentState) {
78 /* Were too few parameters passed to the command? */
79 if (p->parm_count < s->min_parms) {
80 pop_msg(p,POP_FAILURE,
81 "Too few arguments for the %s command.",
86 /* Were too many parameters passed to the command? */
87 if (p->parm_count > s->max_parms) {
88 pop_msg(p,POP_FAILURE,
89 "Too many arguments for the %s command.",
94 /* Return a pointer to the entry for this command in
95 the command/state table */
99 /* The client command was not located in the command/state table */
100 pop_msg(p,POP_FAILURE,
101 "Unknown command: \"%s\".",p->pop_command);
110 pop_msg(p, POP_SUCCESS, "help");
112 for (s = states; s->command; s++) {
113 fprintf (p->output, "%s\r\n", s->command);
115 fprintf (p->output, ".\r\n");