]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/imap/serv_imap.c
Now IMAP posts Aide messages when a room is created.
[citadel.git] / citadel / modules / imap / serv_imap.c
index b37324da554d1fd716e161863f625310debac764..2a47b4e223c7247356912faa56f7792b4860c3ca 100644 (file)
@@ -741,13 +741,17 @@ void imap_select(int num_parms, char *parms[])
        cprintf("* OK [UIDVALIDITY %ld] UID validity status\r\n", GLOBAL_UIDVALIDITY_VALUE);
        cprintf("* OK [UIDNEXT %ld] Predicted next UID\r\n", CitControl.MMhighest + 1);
 
-       /* Note that \Deleted is a valid flag, but not a permanent flag,
+       /* Technically, \Deleted is a valid flag, but not a permanent flag,
         * because we don't maintain its state across sessions.  Citadel
         * automatically expunges mailboxes when they are de-selected.
+        * 
+        * Unfortunately, omitting \Deleted as a PERMANENTFLAGS flag causes
+        * some clients (particularly Thunderbird) to misbehave -- they simply
+        * electing not to transmit the flag at all.  So we have to advertise
+        * \Deleted as a PERMANENTFLAGS flag, even though it technically isn't.
         */
        cprintf("* FLAGS (\\Deleted \\Seen \\Answered)\r\n");
-       cprintf("* OK [PERMANENTFLAGS (\\Deleted \\Seen \\Answered)] "
-               "permanent flags\r\n");
+       cprintf("* OK [PERMANENTFLAGS (\\Deleted \\Seen \\Answered)] permanent flags\r\n");
 
        cprintf("%s OK [%s] %s completed\r\n",
                parms[0],
@@ -877,6 +881,7 @@ void imap_create(int num_parms, char *parms[])
        int flags;
        int newroomtype = 0;
        int newroomview = 0;
+       char *notification_message = NULL;
 
        if (strchr(parms[2], '\\') != NULL) {
                cprintf("%s NO Invalid character in folder name\r\n",
@@ -920,6 +925,18 @@ void imap_create(int num_parms, char *parms[])
                cprintf("%s NO Mailbox already exists, or create failed\r\n", parms[0]);
        } else {
                cprintf("%s OK CREATE completed\r\n", parms[0]);
+               /* post a message in Aide> describing the new room */
+               notification_message = malloc(1024);
+               snprintf(notification_message, 1024,
+                       "A new room called \"%s\" has been created by %s%s%s%s\n",
+                       roomname,
+                       CC->user.fullname,
+                       ((ret & QR_MAILBOX) ? " [personal]" : ""),
+                       ((ret & QR_PRIVATE) ? " [private]" : ""),
+                       ((ret & QR_GUESSNAME) ? " [hidden]" : "")
+               );
+               aide_message(notification_message, "Room Creation Message");
+               free(notification_message);
        }
        CtdlLogPrintf(CTDL_DEBUG, "imap_create() completed\n");
 }
@@ -1329,6 +1346,7 @@ void imap_command_loop(void)
        int num_parms;
        struct timeval tv1, tv2;
        suseconds_t total_time = 0;
+       int untagged_ok = 1;
 
        gettimeofday(&tv1, NULL);
        CC->lastcmd = time(NULL);
@@ -1382,8 +1400,24 @@ void imap_command_loop(void)
         * If the command just submitted does not contain a literal, we
         * might think about delivering some untagged stuff...
         */
-       if (cmdbuf[strlen(cmdbuf)-1] != '}') {
+       if (cmdbuf[strlen(cmdbuf)-1] == '}') {
+               untagged_ok = 0;
+       }
+
+       /* Grab the tag, command, and parameters. */
+       num_parms = imap_parameterize(parms, cmdbuf);
 
+       /* RFC3501 says that we cannot output untagged data during these commands */
+       if (num_parms >= 2) {
+               if (  (!strcasecmp(parms[1], "FETCH"))
+                  || (!strcasecmp(parms[1], "STORE"))
+                  || (!strcasecmp(parms[1], "SEARCH"))
+               ) {
+                       untagged_ok = 0;
+               }
+       }
+       
+       if (untagged_ok) {
                imap_print_instant_messages();
        
                /*
@@ -1399,8 +1433,6 @@ void imap_command_loop(void)
 
        /* Now for the command set. */
 
-       /* Grab the tag, command, and parameters.  Check syntax. */
-       num_parms = imap_parameterize(parms, cmdbuf);
        if (num_parms < 2) {
                cprintf("BAD syntax error\r\n");
        }