* More license declarations
[citadel.git] / citadel / modules / imap / imap_tools.c
index b73bb8b8e47bea5490b6f5908c12c9b3ac957bc9..0ca98feb701d53fa4458615e825dbcf0372dd0d3 100644 (file)
@@ -3,8 +3,22 @@
  *
  * Utility functions for the IMAP module.
  *
- * Note: most of the UTF7 and UTF8 handling in here was lifted from Evolution.
+ * Copyright (c) 2001-2009 by the citadel.org team and others, except for
+ * most of the UTF7 and UTF8 handling code which was lifted from Evolution.
  *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
 #include <stdlib.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <string.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "sysdep_decls.h"
-#include "tools.h"
 #include "room_ops.h"
 #include "internet_addressing.h"
 #include "imap_tools.h"
-
+#include "ctdl_module.h"
 
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
 
 /* String handling helpers */
 
-/* This code uses some pretty narsty string manipulation. To make everything
+/* This code uses some pretty nasty string manipulation. To make everything
  * manageable, we use this semi-high-level string manipulation API. Strings are
- * always \0-terminated, despite the fact that we keep track of the size. */
-
+ * always \0-terminated, despite the fact that we keep track of the size.
+ */
 struct string {
        char* buffer;
        int maxsize;
@@ -211,7 +225,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); */
+       /* CtdlLogPrintf(CTDL_DEBUG, "toimap %s\r\n", src); */
 
        for (;;)
        {
@@ -277,7 +291,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); */
+       /* CtdlLogPrintf(CTDL_DEBUG, "    -> %s\r\n", destp); */
        return string_end(&dest);
 }
 
@@ -295,7 +309,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); */
+       /* CtdlLogPrintf(CTDL_DEBUG, "fromimap %s\r\n", src); */
 
        do {
                c = *p++;
@@ -353,7 +367,7 @@ static char* fromimap(char* destp, char* destend, char* src)
                        }
        } while (c != '\0');
 
-       /* lprintf(CTDL_DEBUG, "      -> %s\r\n", destp); */
+       /* CtdlLogPrintf(CTDL_DEBUG, "      -> %s\r\n", destp); */
        return string_end(&dest);
 }
 
@@ -582,7 +596,7 @@ int imap_roomname(char *rbuf, int bufsize, char *foldername)
        ret = (0 | IR_MAILBOX);
 
 exit:
-       lprintf(CTDL_DEBUG, "(That translates to \"%s\")\n", rbuf);
+       CtdlLogPrintf(CTDL_DEBUG, "(That translates to \"%s\")\n", rbuf);
        return(ret);
 }
 
@@ -632,7 +646,7 @@ int imap_is_message_set(char *buf)
        if (!strcasecmp(buf, "ALL"))
                return (1);     /* macro?  why?  */
 
-       for (i = 0; !IsEmptyStr(&buf[i]); ++i) {        /* now start the scan */
+       for (i = 0; buf[i]; ++i) {      /* now start the scan */
                if (
                           (!isdigit(buf[i]))
                           && (buf[i] != ':')
@@ -772,6 +786,10 @@ int imap_datecmp(char *datestr, time_t msgtime) {
        int msgday, msgmonth, msgyear;
        struct tm msgtm;
 
+       char *imap_datecmp_ascmonths[12] = {
+               "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+       };
+
        if (datestr == NULL) return(0);
 
        /* Expecting a date in the form dd-Mmm-yyyy */
@@ -783,7 +801,7 @@ int imap_datecmp(char *datestr, time_t msgtime) {
        year = atoi(yearstr);
        month = 0;
        for (i=0; i<12; ++i) {
-               if (!strcasecmp(monthstr, ascmonths[i])) {
+               if (!strcasecmp(monthstr, imap_datecmp_ascmonths[i])) {
                        month = i;
                }
        }