$Log$
+Revision 1.446 2000/01/17 17:09:23 ajc
+* Implemented LIST and STAT commands in the pop3 server
+
Revision 1.445 2000/01/17 05:38:14 ajc
* citserver.c: cleanup hook functions are now run under the proper context,
even when initiated by the housekeeper thread
Fri Jul 10 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
* Initial CVS import
-
-/* $Id$ */
+/* $Id$
+ *
+ * An implementation of Post Office Protocol version 3 (RFC 1939).
+ *
+ * Copyright (C) 1998-2000 by Art Cancro and others.
+ * This code is released under the terms of the GNU General Public License.
+ */
#include "sysdep.h"
#include <stdlib.h>
* list available msgs
*/
void pop3_list(char *argbuf) {
- cprintf("-ERR oops, not finished\r\n");
+ int i;
+ int which_one;
+
+ which_one = atoi(argbuf);
+
+ /* "list one" mode */
+ if (which_one > 0) {
+ if (which_one > POP3->num_msgs) {
+ cprintf("-ERR no such message, only %d are here\r\n",
+ POP3->num_msgs);
+ return;
+ }
+ else if (POP3->msgs[which_one-1].deleted) {
+ cprintf("-ERR Sorry, you deleted that message.\r\n");
+ return;
+ }
+ else {
+ cprintf("+OK %d %d\n",
+ which_one,
+ POP3->msgs[which_one-1].rfc822_length
+ );
+ return;
+ }
+ }
+
+ /* "list all" (scan listing) mode */
+ else {
+ cprintf("+OK Here's your mail:\r\n");
+ if (POP3->num_msgs > 0) for (i=0; i<POP3->num_msgs; ++i) {
+ if (! POP3->msgs[i].deleted) {
+ cprintf("%d %d\r\n",
+ i+1,
+ POP3->msgs[i].rfc822_length);
+ }
+ }
+ cprintf(".\r\n");
+ }
}
+/*
+ * STAT (tally up the total message count and byte count) command
+ */
+void pop3_stat(char *argbuf) {
+ int total_msgs = 0;
+ size_t total_octets = 0;
+ int i;
+
+ if (POP3->num_msgs > 0) for (i=0; i<POP3->num_msgs; ++i) {
+ if (! POP3->msgs[i].deleted) {
+ ++total_msgs;
+ total_octets += POP3->msgs[i].rfc822_length;
+ }
+ }
+
+ cprintf("+OK %d %d\n", total_msgs, total_octets);
+}
+
/*
pop3_list(&cmdbuf[5]);
}
+ else if (!strncasecmp(cmdbuf, "STAT", 4)) {
+ pop3_stat(&cmdbuf[5]);
+ }
+
else {
cprintf("500 I'm afraid I can't do that, Dave.\r\n");
}