]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_pop3.c
* Shut off hostname resolution when dealing with Unix domain sockets
[citadel.git] / citadel / serv_pop3.c
index a4d8a8a0813aa1b7ba0af97845b6332c2907575f..59c7a2ca74c0282321826fd1b3fb900d907331ab 100644 (file)
@@ -4,11 +4,19 @@
  * Copyright (C) 1998-2000 by Art Cancro and others.
  * This code is released under the terms of the GNU General Public License.
  *
- * This module implements all required POP3 server commands as described
- * in RFC1939.  It also implements nearly all of the optional commands.  The
- * only one missing is APOP, because it implements a "shared secret" method
- * of authentication which currently does not fit well with Citadel.  Perhaps
- * we'll do it later.
+ * Current status of standards conformance:
+ *
+ * -> All required POP3 commands described in RFC1939 are implemented.
+ * 
+ * -> Nearly all of the optional commands in RFC1939 are also implemented.
+ *    The only one missing is APOP, because it implements a "shared secret"
+ *    method  of authentication which would require some major changes to the
+ *    Citadel server core.
+ *
+ * -> The deprecated "LAST" command is included in this implementation, because
+ *    there exist mail clients which insist on using it (such as Bynari
+ *    TradeMail, and certain versions of Eudora).
+ * 
  */
 
 #include "sysdep.h"
@@ -123,7 +131,11 @@ void pop3_add_message(long msgnum) {
        POP3->msgs[POP3->num_msgs-1].deleted = 0;
        fp = tmpfile();
        POP3->msgs[POP3->num_msgs-1].temp = fp;
-       CtdlOutputMsg(msgnum, MT_RFC822, 0, 0, fp, 0, 1);
+
+       CtdlRedirectOutput(fp, -1);
+       CtdlOutputMsg(msgnum, MT_RFC822, 0, 0, 1);
+       CtdlRedirectOutput(NULL, -1);
+
        POP3->msgs[POP3->num_msgs-1].rfc822_length = ftell(fp);
 }
 
@@ -135,8 +147,23 @@ void pop3_add_message(long msgnum) {
  * of messages in the inbox, or -1 for error)
  */
 int pop3_grab_mailbox(void) {
+        struct visit vbuf;
+       int i;
+
        if (getroom(&CC->quickroom, MAILROOM) != 0) return(-1);
+
+       /* Load up the messages */
        CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, pop3_add_message);
+
+       /* Figure out which are old and which are new */
+        CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
+       POP3->lastseen = (-1);
+       if (POP3->num_msgs) for (i=0; i<POP3->num_msgs; ++i) {
+               if ((POP3->msgs[POP3->num_msgs-1].msgnum) <= vbuf.v_lastseen) {
+                       POP3->lastseen = i;
+               }
+       }
+
        return(POP3->num_msgs);
 }
 
@@ -238,7 +265,7 @@ void pop3_stat(char *argbuf) {
  */
 void pop3_retr(char *argbuf) {
        int which_one;
-       int ch;
+       int ch = 0;
        size_t bytes_remaining;
 
        which_one = atoi(argbuf);
@@ -259,6 +286,9 @@ void pop3_retr(char *argbuf) {
                ch = getc(POP3->msgs[which_one - 1].temp);
                cprintf("%c", ch);
        }
+       if (ch != 10) {
+               lprintf(5, "Problem: message ends with 0x%2x, not 0x0a\n", ch);
+       }
        cprintf(".\r\n");
 }
 
@@ -326,17 +356,31 @@ void pop3_dele(char *argbuf) {
 }
 
 
-/* Perform "UPDATE state" stuff (remove messages marked for deletion)
+/* Perform "UPDATE state" stuff
  */
 void pop3_update(void) {
        int i;
+        struct visit vbuf;
 
+       /* Remove messages marked for deletion */
        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);
                }
        }
+
+       /* Set last read pointer */
+       if (POP3->num_msgs > 0) {
+               lgetuser(&CC->usersupp, CC->curr_user);
+
+               CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
+               vbuf.v_lastseen = POP3->msgs[POP3->num_msgs-1].msgnum;
+               CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
+
+               lputuser(&CC->usersupp);
+       }
+
 }
 
 
@@ -356,6 +400,14 @@ void pop3_rset(char *argbuf) {
 
 
 
+/* 
+ * LAST (Determine which message is the last unread message)
+ */
+void pop3_last(char *argbuf) {
+       cprintf("+OK %d\r\n", POP3->lastseen + 1);
+}
+
+
 
 /*
  * UIDL (Universal IDentifier Listing) is easy.  Our 'unique' message
@@ -471,6 +523,10 @@ void pop3_command_loop(void) {
                pop3_top(&cmdbuf[4]);
        }
 
+       else if (!strncasecmp(cmdbuf, "LAST", 4)) {
+               pop3_last(&cmdbuf[4]);
+       }
+
        else {
                cprintf("500 I'm afraid I can't do that, Dave.\r\n");
        }
@@ -482,7 +538,8 @@ void pop3_command_loop(void) {
 char *Dynamic_Module_Init(void)
 {
        SYM_POP3 = CtdlGetDynamicSymbol();
-       CtdlRegisterServiceHook(POP3_PORT,
+       CtdlRegisterServiceHook(config.c_pop3_port,
+                               NULL,
                                pop3_greeting,
                                pop3_command_loop);
        CtdlRegisterSessionHook(pop3_cleanup_function, EVT_STOP);