* Finished coding IMAP APPEND. It works, but there's a bug in it somewhere
authorArt Cancro <ajc@citadel.org>
Tue, 10 Apr 2001 01:04:10 +0000 (01:04 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 10 Apr 2001 01:04:10 +0000 (01:04 +0000)
  that is corrupting the memory.

citadel/ChangeLog
citadel/imap_misc.c
citadel/msgbase.c
citadel/msgbase.h

index 47d9f79dca8847893126f2f202f418427a97d5a8..e24c3da3463f717bfb1a784908e9bab51d9cfc6c 100644 (file)
@@ -1,4 +1,8 @@
  $Log$
+ Revision 573.124  2001/04/10 01:04:10  ajc
+ * Finished coding IMAP APPEND.  It works, but there's a bug in it somewhere
+   that is corrupting the memory.
+
  Revision 573.123  2001/04/03 00:47:23  ajc
  * Began implementing IMAP APPEND
 
@@ -2485,3 +2489,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import 
+
index 84f6854946ad3b088bb1b3b84c523fd7a1b16fdf..40c1cd62815a51c5bc5c3d278bc82b267e846106 100644 (file)
@@ -180,7 +180,13 @@ void imap_print_express_messages(void) {
  */
 void imap_append(int num_parms, char *parms[]) {
        size_t literal_length;
+       struct CtdlMessage *msg;
        int ret;
+       char roomname[ROOMNAMELEN];
+       char buf[SIZ];
+       char savedroom[ROOMNAMELEN];
+       int msgs, new;
+
 
        if (num_parms < 4) {
                cprintf("%s BAD usage error\r\n", parms[0]);
@@ -215,5 +221,65 @@ void imap_append(int num_parms, char *parms[]) {
                return;
        }
 
-       cprintf("%s NO not implemented yet ** FIXME ** \r\n", parms[0]);
+       lprintf(9, "Converting message...\n");
+        msg = convert_internet_message(IMAP->transmitted_message);
+
+        /* If the user is locally authenticated, FORCE the From: header to
+         * show up as the real sender.  FIXME do we really want to do this?
+         */
+        if (CC->logged_in) {
+                if (msg->cm_fields['A'] != NULL) phree(msg->cm_fields['A']);
+                if (msg->cm_fields['N'] != NULL) phree(msg->cm_fields['N']);
+                if (msg->cm_fields['H'] != NULL) phree(msg->cm_fields['H']);
+                msg->cm_fields['A'] = strdoop(CC->usersupp.fullname);
+                msg->cm_fields['N'] = strdoop(config.c_nodename);
+                msg->cm_fields['H'] = strdoop(config.c_humannode);
+        }
+
+       ret = imap_grabroom(roomname, parms[2]);
+       if (ret != 0) {
+               cprintf("%s NO Invalid mailbox name or location, or access denied\r\n",
+                       parms[0]);
+               return;
+       }
+
+       /*
+        * usergoto() formally takes us to the desired room.  (If another
+        * folder is selected, save its name so we can return there!!!!!)
+        */
+       if (IMAP->selected) {
+               strcpy(savedroom, CC->quickroom.QRname);
+       }
+       usergoto(roomname, 0, &msgs, &new);
+
+       /* 
+        * Can we post here?
+        */
+       ret = CtdlDoIHavePermissionToPostInThisRoom(buf);
+
+       if (ret) {
+               /* Nope ... print an error message */
+               cprintf("%s NO %s\r\n", parms[0], buf);
+       }
+
+       else {
+               /* Yes ... go ahead and post! */
+               if (msg != NULL) {
+                       CtdlSaveMsg(msg, "", "", 0);
+               }
+               cprintf("%s OK APPEND completed\r\n", parms[0]);
+       }
+
+       /*
+        * IMAP protocol response to client has already been sent by now.
+        *
+        * If another folder is selected, go back to that room so we can resume
+        * our happy day without violent explosions.
+        */
+       if (IMAP->selected) {
+               usergoto(savedroom, 0, &msgs, &new);
+       }
+
+       /* We don't need this buffer anymore */
+       CtdlFreeMessage(msg);
 }
index 1386611178a7a34ae9b87019fd0b471fd9ffb461..35ac831a7876855b8641ead0954d8d17f9647121 100644 (file)
@@ -1983,6 +1983,41 @@ struct CtdlMessage *make_message(
 }
 
 
+/*
+ * Check to see whether we have permission to post a message in the current
+ * room.  Returns a *CITADEL ERROR CODE* and puts a message in errmsgbuf, or
+ * returns 0 on success.
+ */
+int CtdlDoIHavePermissionToPostInThisRoom(char *errmsgbuf) {
+
+       if (!(CC->logged_in)) {
+               sprintf(errmsgbuf, "Not logged in.");
+               return (ERROR + NOT_LOGGED_IN);
+       }
+
+       if ((CC->usersupp.axlevel < 2)
+           && ((CC->quickroom.QRflags & QR_MAILBOX) == 0)) {
+               sprintf(errmsgbuf, "Need to be validated to enter "
+                               "(except in %s> to sysop)", MAILROOM);
+               return (ERROR + HIGHER_ACCESS_REQUIRED);
+       }
+
+       if ((CC->usersupp.axlevel < 4)
+          && (CC->quickroom.QRflags & QR_NETWORK)) {
+               sprintf(errmsgbuf, "Need net privileges to enter here.");
+               return (ERROR + HIGHER_ACCESS_REQUIRED);
+       }
+
+       if ((CC->usersupp.axlevel < 6)
+          && (CC->quickroom.QRflags & QR_READONLY)) {
+               sprintf(errmsgbuf, "Sorry, this is a read-only room.");
+               return (ERROR + HIGHER_ACCESS_REQUIRED);
+       }
+
+       strcpy(errmsgbuf, "Ok");
+       return(0);
+}
+
 
 
 
@@ -2002,6 +2037,7 @@ void cmd_ent0(char *entargs)
        int mtsflag = 0;
        struct usersupp tempUS;
        char buf[SIZ];
+       int err = 0;
 
        post = extract_int(entargs, 0);
        extract(recipient, entargs, 1);
@@ -2010,28 +2046,13 @@ void cmd_ent0(char *entargs)
 
        /* first check to make sure the request is valid. */
 
-       if (!(CC->logged_in)) {
-               cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
-               return;
-       }
-       if ((CC->usersupp.axlevel < 2) && ((CC->quickroom.QRflags & QR_MAILBOX) == 0)) {
-               cprintf("%d Need to be validated to enter ",
-                       ERROR + HIGHER_ACCESS_REQUIRED);
-               cprintf("(except in %s> to sysop)\n", MAILROOM);
-               return;
-       }
-       if ((CC->usersupp.axlevel < 4) && (CC->quickroom.QRflags & QR_NETWORK)) {
-               cprintf("%d Need net privileges to enter here.\n",
-                       ERROR + HIGHER_ACCESS_REQUIRED);
-               return;
-       }
-       if ((CC->usersupp.axlevel < 6) && (CC->quickroom.QRflags & QR_READONLY)) {
-               cprintf("%d Sorry, this is a read-only room.\n",
-                       ERROR + HIGHER_ACCESS_REQUIRED);
+       err = CtdlDoIHavePermissionToPostInThisRoom(buf);
+       if (err) {
+               cprintf("%d %s\n", err, buf);
                return;
        }
-       mtsflag = 0;
 
+       /* Check some other permission type things. */
 
        if (post == 2) {
                if (CC->usersupp.axlevel < 6) {
index eed4c17e13f35e6ed4617c7537999c09803baae8..f515e188cc147cc19ed08dbb4cb283bc36c4711d 100644 (file)
@@ -102,3 +102,4 @@ int CtdlOutputPreLoadedMsg(struct CtdlMessage *,
                int crlf);
 int CtdlCopyMsgToRoom(long msgnum, char *dest);
 int CtdlDoIHavePermissionToDeleteMessagesFromThisRoom(void);
+int CtdlDoIHavePermissionToPostInThisRoom(char *errmsgbuf);