From 8838f32b8d698b032ea7912fbdaf2921a68e39e7 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Mon, 17 Jan 2000 17:09:24 +0000 Subject: [PATCH] * Implemented LIST and STAT commands in the pop3 server --- citadel/ChangeLog | 4 ++- citadel/serv_pop3.c | 68 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 69 insertions(+), 3 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index f6f3728c6..15edf37b4 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -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 Fri Jul 10 1998 Art Cancro * Initial CVS import - diff --git a/citadel/serv_pop3.c b/citadel/serv_pop3.c index 4169f9d0d..5a3acf61f 100644 --- a/citadel/serv_pop3.c +++ b/citadel/serv_pop3.c @@ -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 @@ -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; inum_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; inum_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"); } -- 2.39.2