]> code.citadel.org Git - citadel.git/blobdiff - citadel/imap_tools.c
* extract_token() now expects to be supplied with the size of the
[citadel.git] / citadel / imap_tools.c
index abb75b666e0cd18ca545791c8812f6d9d16deca8..72b8325ea5ee4162cd73b4dcfa7593cc7bdb9f6d 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.
  *
  */
 
@@ -160,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+,";
@@ -198,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;
@@ -209,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 (;;)
        {
@@ -275,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);
 }
 
@@ -293,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++;
@@ -351,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);
 }
 
@@ -504,8 +506,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);
@@ -549,7 +551,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. */
@@ -563,7 +565,7 @@ int imap_roomname(char *rbuf, int bufsize, char *foldername)
                                {
                                        /* Got it! */
 
-                                       strcpy(rbuf, roomname);
+                                       safestrncpy(rbuf, roomname, bufsize);
                                        ret = i;
                                        goto exit;
                                }
@@ -571,8 +573,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:
@@ -758,9 +761,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;
@@ -769,9 +772,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);