]> code.citadel.org Git - citadel.git/blobdiff - citadel/imap_misc.c
* Changed a bunch of localtime() calls to localtime_r(), for great justice.
[citadel.git] / citadel / imap_misc.c
index e9d33ad950d2c2a7a24003e58b6850fa277c1f27..b4299c583200b18f054f0fd9989964c1ad1ce1b5 100644 (file)
@@ -135,15 +135,15 @@ void imap_uidcopy(int num_parms, char *parms[]) {
 
 
 /*
- * Poll for express messages (yeah, we can do this in IMAP ... I think)
+ * Poll for instant messages (yeah, we can do this in IMAP ... I think)
  */
-void imap_print_express_messages(void) {
+void imap_print_instant_messages(void) {
        struct ExpressMessage *ptr, *holdptr;
        char *dumpomatic = NULL;
        char tmp[SIZ];
        int i;
        size_t size, size2;
-       struct tm *stamp;
+       struct tm stamp;
 
        if (CC->FirstExpressMessage == NULL) {
                return;
@@ -154,9 +154,9 @@ void imap_print_express_messages(void) {
        end_critical_section(S_SESSION_TABLE);
 
        while (ptr != NULL) {
-               stamp = localtime(&(ptr->timestamp));
+               localtime_r(&(ptr->timestamp), &stamp);
                size = strlen(ptr->text) + SIZ;
-               dumpomatic = mallok(size);
+               dumpomatic = malloc(size);
                strcpy(dumpomatic, "");
                if (ptr->flags && EM_BROADCAST)
                        strcat(dumpomatic, "Broadcast message ");
@@ -168,17 +168,17 @@ void imap_print_express_messages(void) {
                        strcat(dumpomatic, "Message ");
 
                /* Timestamp.  Can this be improved? */
-               if (stamp->tm_hour == 0 || stamp->tm_hour == 12)
+               if (stamp.tm_hour == 0 || stamp.tm_hour == 12)
                        sprintf(tmp, "at 12:%02d%cm",
-                               stamp->tm_min, 
-                               stamp->tm_hour ? 'p' : 'a');
-               else if (stamp->tm_hour > 12)           /* pm */
+                               stamp.tm_min, 
+                               stamp.tm_hour ? 'p' : 'a');
+               else if (stamp.tm_hour > 12)            /* pm */
                        sprintf(tmp, "at %d:%02dpm",
-                               stamp->tm_hour - 12,
-                               stamp->tm_min);
+                               stamp.tm_hour - 12,
+                               stamp.tm_min);
                else                                    /* am */
                        sprintf(tmp, "at %d:%02dam",
-                               stamp->tm_hour, stamp->tm_min);
+                               stamp.tm_hour, stamp.tm_min);
                strcat(dumpomatic, tmp);
 
                size2 = strlen(dumpomatic);
@@ -188,8 +188,8 @@ void imap_print_express_messages(void) {
                        strcat(dumpomatic, ptr->text);
 
                holdptr = ptr->next;
-               if (ptr->text != NULL) phree(ptr->text);
-               phree(ptr);
+               if (ptr->text != NULL) free(ptr->text);
+               free(ptr);
                ptr = holdptr;
 
                for (i=0; i<strlen(dumpomatic); ++i) {
@@ -199,7 +199,7 @@ void imap_print_express_messages(void) {
                }
 
                cprintf("* OK [ALERT] %s\r\n", dumpomatic);
-               phree(dumpomatic);
+               free(dumpomatic);
        }
        cprintf("000\n");
 }
@@ -242,7 +242,7 @@ void imap_append(int num_parms, char *parms[]) {
        }
 
        imap_free_transmitted_message();        /* just in case. */
-       IMAP->transmitted_message = mallok(literal_length + 1);
+       IMAP->transmitted_message = malloc(literal_length + 1);
        if (IMAP->transmitted_message == NULL) {
                cprintf("%s NO Cannot allocate memory.\r\n", parms[0]);
                return;
@@ -259,6 +259,7 @@ void imap_append(int num_parms, char *parms[]) {
                blksize = literal_length - bytes_transferred;
                if (blksize > SIZ) blksize = SIZ;
 
+               flush_output();
                ret = client_read(&IMAP->transmitted_message[bytes_transferred], blksize);
                if (ret < 1) {
                        bytes_transferred = literal_length;     /* bail out */
@@ -284,6 +285,7 @@ void imap_append(int num_parms, char *parms[]) {
         * literal (the message text) is received.  This call to
         * client_gets() absorbs it.
         */
+       flush_output();
        client_gets(buf);
        lprintf(CTDL_DEBUG, "Trailing CRLF: %s\n", buf);
 
@@ -296,6 +298,7 @@ void imap_append(int num_parms, char *parms[]) {
                }
        }
        literal_length = stripped_length;
+       IMAP->transmitted_message[literal_length] = 0;  /* reterminate it */
 
        lprintf(CTDL_DEBUG, "Converting message format\n");
         msg = convert_internet_message(IMAP->transmitted_message);
@@ -327,12 +330,12 @@ void imap_append(int num_parms, char *parms[]) {
          */
         if (CC->logged_in) {
           if ( (CC->room.QRflags & QR_MAILBOX) == 0) {
-                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->user.fullname);
-                msg->cm_fields['N'] = strdoop(config.c_nodename);
-                msg->cm_fields['H'] = strdoop(config.c_humannode);
+                if (msg->cm_fields['A'] != NULL) free(msg->cm_fields['A']);
+                if (msg->cm_fields['N'] != NULL) free(msg->cm_fields['N']);
+                if (msg->cm_fields['H'] != NULL) free(msg->cm_fields['H']);
+                msg->cm_fields['A'] = strdup(CC->user.fullname);
+                msg->cm_fields['N'] = strdup(config.c_nodename);
+                msg->cm_fields['H'] = strdup(config.c_humannode);
            }
         }