]> code.citadel.org Git - citadel.git/blobdiff - citadel/imap_misc.c
* CtdlSaveMsg() is now CtdlSubmitMsg() and can accept any combination of
[citadel.git] / citadel / imap_misc.c
index a0e7a7a7a70bb5b06dccd0555c1d30abc665d44f..75e4b0d33138c072c9e9d298e366716e10ef53ee 100644 (file)
 #include <pwd.h>
 #include <errno.h>
 #include <sys/types.h>
-#include <sys/time.h>
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
 #include <sys/wait.h>
 #include <ctype.h>
 #include <string.h>
 #include <limits.h>
 #include "citadel.h"
 #include "server.h"
-#include <time.h>
 #include "sysdep_decls.h"
 #include "citserver.h"
 #include "support.h"
@@ -175,3 +185,115 @@ void imap_print_express_messages(void) {
 
 
 
+/*
+ * This function is called by the main command loop.
+ */
+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]);
+               return;
+       }
+
+       if ( (parms[num_parms-1][0] != '{')
+          || (parms[num_parms-1][strlen(parms[num_parms-1])-1] != '}') )  {
+               cprintf("%s BAD no message literal supplied\r\n", parms[0]);
+               return;
+       }
+
+       literal_length = (size_t) atol(&parms[num_parms-1][1]);
+       if (literal_length < 1) {
+               cprintf("%s BAD Message length must be at least 1.\r\n",
+                       parms[0]);
+               return;
+       }
+
+       imap_free_transmitted_message();        /* just in case. */
+       IMAP->transmitted_message = mallok(literal_length + 1);
+       if (IMAP->transmitted_message == NULL) {
+               cprintf("%s NO Cannot allocate memory.\r\n", parms[0]);
+               return;
+       }
+       IMAP->transmitted_length = literal_length;
+
+       cprintf("+ Transmit message now.\r\n");
+       ret = client_read(IMAP->transmitted_message, literal_length);
+       IMAP->transmitted_message[literal_length] = 0;
+       if (ret != 1) {
+               cprintf("%s NO Read failed.\r\n", parms[0]);
+               return;
+       }
+
+       lprintf(9, "Converting message...\n");
+        msg = convert_internet_message(IMAP->transmitted_message);
+       IMAP->transmitted_message = NULL;
+       IMAP->transmitted_length = 0;
+
+        /* 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?
+        * Probably should make it site-definable or even room-definable.
+         */
+        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) {
+                       CtdlSubmitMsg(msg, NULL, "");
+               }
+               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);
+}