]> code.citadel.org Git - citadel.git/commitdiff
* Implemented LIST and STAT commands in the pop3 server
authorArt Cancro <ajc@citadel.org>
Mon, 17 Jan 2000 17:09:24 +0000 (17:09 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 17 Jan 2000 17:09:24 +0000 (17:09 +0000)
citadel/ChangeLog
citadel/serv_pop3.c

index f6f3728c6f118c1dd0f9590282759060be5a54b2..15edf37b4d46f8adbddc5ae7e709393bf58ada15 100644 (file)
@@ -1,4 +1,7 @@
 $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
@@ -1563,4 +1566,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * Initial CVS import 
-
index 4169f9d0dc1f0eb155ea9f6b2e8d75f3369c8d82..5a3acf61f4b1c6f4f4270d161d866a9a6f66a505 100644 (file)
@@ -1,4 +1,10 @@
-/* $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>
@@ -162,10 +168,64 @@ void pop3_pass(char *argbuf) {
  * 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);
+}
+
 
 
 /* 
@@ -210,6 +270,10 @@ void pop3_command_loop(void) {
                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");
        }