#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"
*/
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]);
}
imap_free_transmitted_message(); /* just in case. */
- IMAP->transmitted_message = mallok(literal_length);
+ IMAP->transmitted_message = mallok(literal_length + 1);
if (IMAP->transmitted_message == NULL) {
cprintf("%s NO Cannot allocate memory.\r\n", parms[0]);
return;
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;
}
- cprintf("%s NO not implemented yet ** FIXME ** \r\n", parms[0]);
+ 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) {
+ 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);
}