]> code.citadel.org Git - citadel.git/commitdiff
* Completed POP3 server. All RFC1939 commands except APOP are implemented.
authorArt Cancro <ajc@citadel.org>
Mon, 17 Jan 2000 18:30:27 +0000 (18:30 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 17 Jan 2000 18:30:27 +0000 (18:30 +0000)
citadel/ChangeLog
citadel/msgbase.c
citadel/serv_pop3.c

index 15edf37b4d46f8adbddc5ae7e709393bf58ada15..8ed2ad0727c590e81d5154707a07946ade1e3197 100644 (file)
@@ -1,4 +1,7 @@
 $Log$
+Revision 1.447  2000/01/17 18:30:27  ajc
+* Completed POP3 server.  All RFC1939 commands except APOP are implemented.
+
 Revision 1.446  2000/01/17 17:09:23  ajc
 * Implemented LIST and STAT commands in the pop3 server
 
@@ -1566,3 +1569,4 @@ 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 062d1a80ad6edb9d4def275bc16000068f203c55..b82004f937f1a3b7e1372319244905aa3817f2df 100644 (file)
@@ -545,46 +545,6 @@ void list_this_part(char *name, char *filename, char *partnum, char *disp,
 }
 
 
-/*
- * Callback function for mime parser that wants to display text
- */
-void fixed_output(char *name, char *filename, char *partnum, char *disp,
-                 void *content, char *cbtype, size_t length)
-{
-       char *ptr;
-
-       if (!strcasecmp(cbtype, "multipart/alternative")) {
-               strcpy(ma->prefix, partnum);
-               strcat(ma->prefix, ".");
-               ma->is_ma = 1;
-               ma->did_print = 0;
-               return;
-       }
-
-       if ( (!strncasecmp(partnum, ma->prefix, strlen(ma->prefix)))
-          && (ma->is_ma == 1) 
-          && (ma->did_print == 1) ) {
-               lprintf(9, "Skipping part %s (%s)\n", partnum, cbtype);
-               return;
-       }
-
-       ma->did_print = 1;
-
-       if (!strcasecmp(cbtype, "text/plain")) {
-               client_write(content, length);
-       }
-       else if (!strcasecmp(cbtype, "text/html")) {
-               ptr = html_to_ascii(content, 80, 0);
-               client_write(ptr, strlen(ptr));
-               phree(ptr);
-       }
-       else if (strncasecmp(cbtype, "multipart/", 10)) {
-               cprintf("Part %s: %s (%s) (%d bytes)\n",
-                       partnum, filename, cbtype, length);
-       }
-}
-
-
 /*
  * Callback function for mime parser that opens a section for downloading
  */
@@ -831,6 +791,55 @@ FMTEND:            omprintf("%s\n", aaa);
        }
        /* END NESTED FUNCTION omfmout() */
 
+       /* BEGIN NESTED FUNCTION fixed_output() */
+       /*
+       * Callback function for mime parser that wants to display text
+       */
+       void fixed_output(char *name, char *filename, char *partnum, char *disp,
+                       void *content, char *cbtype, size_t length)
+       {
+               char *ptr;
+               char *wptr;
+               size_t wlen;
+       
+               if (!strcasecmp(cbtype, "multipart/alternative")) {
+                       strcpy(ma->prefix, partnum);
+                       strcat(ma->prefix, ".");
+                       ma->is_ma = 1;
+                       ma->did_print = 0;
+                       return;
+               }
+       
+               if ( (!strncasecmp(partnum, ma->prefix, strlen(ma->prefix)))
+               && (ma->is_ma == 1) 
+               && (ma->did_print == 1) ) {
+                       lprintf(9, "Skipping part %s (%s)\n", partnum, cbtype);
+                       return;
+               }
+       
+               ma->did_print = 1;
+       
+               if (!strcasecmp(cbtype, "text/plain")) {
+                       wlen = length;
+                       wptr = content;
+                       while (wlen--) omprintf("%c", *wptr++);
+               }
+               else if (!strcasecmp(cbtype, "text/html")) {
+                       ptr = html_to_ascii(content, 80, 0);
+                       wlen = strlen(ptr);
+                       wptr = ptr;
+                       while (wlen--) omprintf("%c", *wptr++);
+                       phree(ptr);
+               }
+               else if (strncasecmp(cbtype, "multipart/", 10)) {
+                       omprintf("Part %s: %s (%s) (%d bytes)\n",
+                               partnum, filename, cbtype, length);
+               }
+       }
+
+       /* END NESTED FUNCTION fixed_output() */
+
+
        TheMessage = NULL;
        sprintf(mid, "%ld", msg_num);
 
@@ -1034,8 +1043,10 @@ FMTEND:          omprintf("%s\n", aaa);
        /* signify start of msg text */
        if (mode == MT_CITADEL)
                if (do_proto) cprintf("text\n");
-       if ((mode == MT_RFC822) && (TheMessage->cm_format_type != FMT_RFC822))
+       /* if ((mode == MT_RFC822) && (TheMessage->cm_format_type != FMT_RFC822)) { */
+       if (mode == MT_RFC822) {
                omprintf("\n");
+       }
 
        /* If the format type on disk is 1 (fixed-format), then we want
         * everything to be output completely literally ... regardless of
index 5a3acf61f4b1c6f4f4270d161d866a9a6f66a505..52578a3f65bc57ef55d6030ca5460815fed47627 100644 (file)
@@ -228,6 +228,173 @@ void pop3_stat(char *argbuf) {
 
 
 
+/*
+ * RETR command (fetch a message)
+ */
+void pop3_retr(char *argbuf) {
+       int which_one;
+       int ch;
+       size_t bytes_remaining;
+
+       which_one = atoi(argbuf);
+       if ( (which_one < 1) || (which_one > POP3->num_msgs) ) {
+               cprintf("-ERR No such message.\r\n");
+               return;
+       }
+
+       if (POP3->msgs[which_one - 1].deleted) {
+               cprintf("-ERR Sorry, you deleted that message.\r\n");
+               return;
+       }
+
+       cprintf("+OK Whoop, there it is:\r\n");
+       bytes_remaining = POP3->msgs[which_one -1].rfc822_length;
+       rewind(POP3->msgs[which_one - 1].temp);
+       while (bytes_remaining-- > 0) {
+               ch = getc(POP3->msgs[which_one - 1].temp);
+               cprintf("%c", ch);
+       }
+       cprintf(".\r\n");
+}
+
+
+/*
+ * TOP command (dumb way of fetching a partial message or headers-only)
+ */
+void pop3_top(char *argbuf) {
+       int which_one;
+       int lines_requested = 0;
+       int lines_dumped = 0;
+       char buf[1024];
+       char *ptr;
+       int in_body = 0;
+
+       sscanf(argbuf, "%d %d", &which_one, &lines_requested);
+       if ( (which_one < 1) || (which_one > POP3->num_msgs) ) {
+               cprintf("-ERR No such message.\r\n");
+               return;
+       }
+
+       if (POP3->msgs[which_one - 1].deleted) {
+               cprintf("-ERR Sorry, you deleted that message.\r\n");
+               return;
+       }
+
+       cprintf("+OK Whoop, there it is:\r\n");
+       rewind(POP3->msgs[which_one - 1].temp);
+       while (ptr = fgets(buf, sizeof buf, POP3->msgs[which_one - 1].temp),
+             ( (ptr!=NULL) && (lines_dumped < lines_requested) ) ) {
+               client_write(buf, strlen(buf));
+               if (in_body) ++lines_dumped;
+               if ((buf[0]==13)||(buf[0]==10)) in_body = 1;
+       }
+       if (buf[strlen(buf)-1] != 10) cprintf("\n");
+       cprintf(".\r\n");
+}
+
+
+/*
+ * DELE (delete message from mailbox)
+ */
+void pop3_dele(char *argbuf) {
+       int which_one;
+
+       which_one = atoi(argbuf);
+       if ( (which_one < 1) || (which_one > POP3->num_msgs) ) {
+               cprintf("-ERR No such message.\r\n");
+               return;
+       }
+
+       if (POP3->msgs[which_one - 1].deleted) {
+               cprintf("-ERR You already deleted that message.\r\n");
+               return;
+       }
+
+       /* Flag the message as deleted.  Will expunge during QUIT command. */
+       POP3->msgs[which_one - 1].deleted = 1;
+       cprintf("+OK Message %d disappears in a cloud of orange smoke.\r\n",
+               which_one);
+}
+
+
+/* Perform "UPDATE state" stuff (remove messages marked for deletion)
+ */
+void pop3_update(void) {
+       int i;
+
+       if (POP3->num_msgs > 0) for (i=0; i<POP3->num_msgs; ++i) {
+               if (POP3->msgs[i].deleted) {
+                       CtdlDeleteMessages(MAILROOM,
+                               POP3->msgs[i].msgnum, NULL);
+               }
+       }
+}
+
+
+/* 
+ * RSET (reset, i.e. undelete any deleted messages) command
+ */
+void pop3_rset(char *argbuf) {
+       int i;
+
+       if (POP3->num_msgs > 0) for (i=0; i<POP3->num_msgs; ++i) {
+               if (POP3->msgs[i].deleted) {
+                       POP3->msgs[i].deleted = 0;
+               }
+       }
+       cprintf("+OK all that has come to pass, has now gone away.\r\n");
+}
+
+
+
+
+/*
+ * UIDL (Universal IDentifier Listing) is easy.  Our 'unique' message
+ * identifiers are simply the Citadel message numbers in the database.
+ */
+void pop3_uidl(char *argbuf) {
+       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 %ld\n",
+                               which_one,
+                               POP3->msgs[which_one-1].msgnum
+                               );
+                       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 %ld\r\n",
+                                       i+1,
+                                       POP3->msgs[i].msgnum);
+                       }
+               }
+               cprintf(".\r\n");
+       }
+}
+
+
+
+
 /* 
  * Main command loop for POP3 sessions.
  */
@@ -250,6 +417,7 @@ void pop3_command_loop(void) {
 
        else if (!strncasecmp(cmdbuf, "QUIT", 4)) {
                cprintf("+OK Goodbye...\r\n");
+               pop3_update();
                CC->kill_me = 1;
                return;
        }
@@ -274,6 +442,26 @@ void pop3_command_loop(void) {
                pop3_stat(&cmdbuf[5]);
        }
 
+       else if (!strncasecmp(cmdbuf, "RETR", 4)) {
+               pop3_retr(&cmdbuf[5]);
+       }
+
+       else if (!strncasecmp(cmdbuf, "DELE", 4)) {
+               pop3_dele(&cmdbuf[5]);
+       }
+
+       else if (!strncasecmp(cmdbuf, "RSET", 4)) {
+               pop3_rset(&cmdbuf[5]);
+       }
+
+       else if (!strncasecmp(cmdbuf, "UIDL", 4)) {
+               pop3_uidl(&cmdbuf[5]);
+       }
+
+       else if (!strncasecmp(cmdbuf, "TOP", 3)) {
+               pop3_top(&cmdbuf[4]);
+       }
+
        else {
                cprintf("500 I'm afraid I can't do that, Dave.\r\n");
        }