Experimental changes to the default theme. Gradient
[citadel.git] / citadel / imap_tools.c
index 024f872e8f7945ef8ef7afdc131b4e6a285e8945..c12755015dcd17fdacef7350c52c7cb803423903 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Utility functions for the IMAP module.
  *
- * Note: most of the UTF7 and UTF8 handling in here was stolen from Evolution.
+ * Note: most of the UTF7 and UTF8 handling in here was lifted from Evolution.
  *
  */
 
@@ -43,21 +43,6 @@ static void string_init(struct string* s, char* buf, int bufsize)
        s->size = strlen(buf);
 }
 
-static int string_overflow(struct string* s)
-{
-       return (s->size == s->maxsize);
-}
-
-static int string_length(struct string* s)
-{
-       return s->size;
-}
-
-static char* string_ptr(struct string* s)
-{
-       return s->buffer;
-}
-
 static char* string_end(struct string* s)
 {
        return s->buffer + s->size;
@@ -126,13 +111,6 @@ static void string_append_c(struct string* s, int c)
        string_append_sn(s, buf, len);
 }      
 
-/* Append another string structure. */
-
-static void string_append(struct string* dest, struct string* src)
-{
-       string_append_sn(dest, src->buffer, src->size);
-}
-
 /* Reads a UTF8 character from a char*, advancing the pointer. */
 
 int utf8_getc(char** ptr)
@@ -182,7 +160,8 @@ int utf8_getc(char** ptr)
 
 /* IMAP has certain special requirements in its character set, which means we
  * have to do a fair bit of work to convert Citadel's UTF8 strings to IMAP
- * strings. The next two routines (and their data tables) do that. */
+ * strings. The next two routines (and their data tables) do that.
+ */
 
 static char *utf7_alphabet =
        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
@@ -220,8 +199,9 @@ static void utf7_closeb64(struct string* out, int v, int i)
        string_append_c(out, '-');
 }
 
-/* Convert from a Citadel name to an IMAP-safe name. Returns the end of the destination. */
-
+/* Convert from a Citadel name to an IMAP-safe name. Returns the end
+ * of the destination.
+ */
 static char* toimap(char* destp, char* destend, char* src)
 {
        struct string dest;
@@ -231,7 +211,7 @@ static char* toimap(char* destp, char* destend, char* src)
 
        *destp = 0;
        string_init(&dest, destp, destend-destp);
-       lprintf(CTDL_DEBUG, "toimap %s\r\n", src);
+       /* lprintf(CTDL_DEBUG, "toimap %s\r\n", src); */
 
        for (;;)
        {
@@ -297,7 +277,7 @@ static char* toimap(char* destp, char* destend, char* src)
 
        if (state == 1)
                utf7_closeb64(&dest, v, i);
-       lprintf(CTDL_DEBUG, "    -> %s\r\n", destp);
+       /* lprintf(CTDL_DEBUG, "    -> %s\r\n", destp); */
        return string_end(&dest);
 }
 
@@ -315,7 +295,7 @@ static char* fromimap(char* destp, char* destend, char* src)
 
        *destp = 0;
        string_init(&dest, destp, destend-destp);
-       lprintf(CTDL_DEBUG, "fromimap %s\r\n", src);
+       /* lprintf(CTDL_DEBUG, "fromimap %s\r\n", src); */
 
        do {
                c = *p++;
@@ -373,7 +353,7 @@ static char* fromimap(char* destp, char* destend, char* src)
                        }
        } while (c != '\0');
 
-       lprintf(CTDL_DEBUG, "      -> %s\r\n", destp);
+       /* lprintf(CTDL_DEBUG, "      -> %s\r\n", destp); */
        return string_end(&dest);
 }
 
@@ -396,12 +376,15 @@ void imap_strout(char *buf)
 {
        int i;
        int is_literal = 0;
+       int len;
 
        if (buf == NULL) {      /* yeah, we handle this */
                cprintf("NIL");
                return;
        }
-       for (i = 0; i < strlen(buf); ++i) {
+
+       len = strlen(buf);
+       for (i = 0; i < len; ++i) {
                if ((buf[i] == '\"') || (buf[i] == '\\'))
                        is_literal = 1;
        }
@@ -526,8 +509,8 @@ void imap_mailboxname(char *buf, int bufsize, struct ctdlroom *qrbuf)
 int imap_roomname(char *rbuf, int bufsize, char *foldername)
 {
        int levels;
-       char floorname[SIZ];
-       char roomname[SIZ];
+       char floorname[256];
+       char roomname[ROOMNAMELEN];
        int i;
        struct floor *fl;
        int ret = (-1);
@@ -571,7 +554,7 @@ int imap_roomname(char *rbuf, int bufsize, char *foldername)
        {
                /* Extract the main room name. */
                
-               extract_token(floorname, rbuf, 0, FDELIM);
+               extract_token(floorname, rbuf, 0, FDELIM, sizeof floorname);
                strcpy(roomname, &rbuf[strlen(floorname)+1]);
 
                /* Try and find it on any floor. */
@@ -585,7 +568,7 @@ int imap_roomname(char *rbuf, int bufsize, char *foldername)
                                {
                                        /* Got it! */
 
-                                       strcpy(rbuf, roomname);
+                                       safestrncpy(rbuf, roomname, bufsize);
                                        ret = i;
                                        goto exit;
                                }
@@ -593,8 +576,9 @@ int imap_roomname(char *rbuf, int bufsize, char *foldername)
                }
        }
 
-       /* Meh. It's either not a multi-level room name, or else we couldn't find it. */
-
+       /* Meh. It's either not a multi-level room name, or else we
+        * couldn't find it.
+        */
        ret = (0 | IR_MAILBOX);
 
 exit:
@@ -780,9 +764,9 @@ int imap_mailbox_matches_pattern(char *pattern, char *mailboxname)
  * a Unix timestamp.
  */
 int imap_datecmp(char *datestr, time_t msgtime) {
-       char daystr[SIZ];
-       char monthstr[SIZ];
-       char yearstr[SIZ];
+       char daystr[256];
+       char monthstr[256];
+       char yearstr[256];
        int i;
        int day, month, year;
        int msgday, msgmonth, msgyear;
@@ -791,9 +775,9 @@ int imap_datecmp(char *datestr, time_t msgtime) {
        if (datestr == NULL) return(0);
 
        /* Expecting a date in the form dd-Mmm-yyyy */
-       extract_token(daystr, datestr, 0, '-');
-       extract_token(monthstr, datestr, 1, '-');
-       extract_token(yearstr, datestr, 2, '-');
+       extract_token(daystr, datestr, 0, '-', sizeof daystr);
+       extract_token(monthstr, datestr, 1, '-', sizeof monthstr);
+       extract_token(yearstr, datestr, 2, '-', sizeof yearstr);
 
        day = atoi(daystr);
        year = atoi(yearstr);