Rocco Rutte:
[apps/madmutt.git] / hcache.c
index cef8fc1..5d7ef9b 100644 (file)
--- a/hcache.c
+++ b/hcache.c
@@ -1,21 +1,12 @@
 /*
+ * Copyright notice from original mutt:
  * Copyright (C) 2004 Thomas Glanzmann <sithglan@stud.uni-erlangen.de>
  * Copyright (C) 2004 Tobias Werth <sitowert@stud.uni-erlangen.de>
  * Copyright (C) 2004 Brian Fundakowski Feldman <green@FreeBSD.org>
  *
- *     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 2 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, USA.
+ * This file is part of mutt-ng, see http://www.muttng.org/.
+ * It's licensed under the GNU General Public License,
+ * please see the file GPL in the top level source directory.
  */
 
 # if HAVE_INTTYPES_H
@@ -52,6 +43,8 @@
 #include "lib.h"
 #include "md5.h"
 
+#include "lib/mem.h"
+
 #if HAVE_GDBM
 static struct
   header_cache {
@@ -72,7 +65,7 @@ static struct
 
 typedef union {
   struct timeval timeval;
-  uint64_t uid_validity;
+  unsigned long uid_validity;
 } validate;
 
 static void *lazy_malloc (size_t siz)
@@ -120,7 +113,7 @@ static unsigned char *dump_char (char *c, unsigned char *d, int *off)
     return d;
   }
 
-  size = mutt_strlen (c) + 1;
+  size = safe_strlen (c) + 1;
   d = dump_int (size, d, off);
   lazy_realloc (&d, *off + size);
   memcpy (d + *off, c, size);
@@ -377,6 +370,13 @@ static unsigned char *dump_envelope (ENVELOPE * e, unsigned char *d, int *off)
   d = dump_char (e->date, d, off);
   d = dump_char (e->x_label, d, off);
 
+#ifdef USE_NNTP
+  d = dump_char (e->newsgroups, d, off);
+  d = dump_char (e->xref, d, off);
+  d = dump_char (e->followup_to, d, off);
+  d = dump_char (e->x_comment_to, d, off);
+#endif
+
   d = dump_list (e->references, d, off);
   d = dump_list (e->in_reply_to, d, off);
   d = dump_list (e->userhdrs, d, off);
@@ -409,6 +409,13 @@ static void restore_envelope (ENVELOPE * e, const unsigned char *d, int *off)
   restore_char (&e->supersedes, d, off);
   restore_char (&e->date, d, off);
   restore_char (&e->x_label, d, off);
+  
+#ifdef USE_NNTP
+  restore_char (&e->newsgroups, d, off);
+  restore_char (&e->xref, d, off);
+  restore_char (&e->followup_to, d, off);
+  restore_char (&e->x_comment_to, d, off);
+#endif
 
   restore_list (&e->references, d, off);
   restore_list (&e->in_reply_to, d, off);
@@ -434,36 +441,41 @@ static int generate_crc32 ()
 
   crc = crc32 (crc, (unsigned char const *)
                "sithglan@stud.uni-erlangen.de[sithglan]|hcache.c|20041108231548|29613",
-               mutt_strlen
+               safe_strlen
                ("sithglan@stud.uni-erlangen.de[sithglan]|hcache.c|20041108231548|29613"));
 
 #if HAVE_LANGINFO_CODESET
-  crc = crc32 (crc, (unsigned char const *) Charset, mutt_strlen (Charset));
+  crc = crc32 (crc, (unsigned char const *) Charset, safe_strlen (Charset));
   crc =
     crc32 (crc, (unsigned char const *) "HAVE_LANGINFO_CODESET",
-           mutt_strlen ("HAVE_LANGINFO_CODESET"));
+           safe_strlen ("HAVE_LANGINFO_CODESET"));
 #endif
 
 #if EXACT_ADDRESS
   crc =
     crc32 (crc, (unsigned char const *) "EXACT_ADDRESS",
-           mutt_strlen ("EXACT_ADDRESS"));
+           safe_strlen ("EXACT_ADDRESS"));
 #endif
 
 #ifdef USE_POP
   crc =
-    crc32 (crc, (unsigned char const *) "USE_POP", mutt_strlen ("USE_POP"));
+    crc32 (crc, (unsigned char const *) "USE_POP", safe_strlen ("USE_POP"));
 #endif
 
 #ifdef MIXMASTER
   crc =
     crc32 (crc, (unsigned char const *) "MIXMASTER",
-           mutt_strlen ("MIXMASTER"));
+           safe_strlen ("MIXMASTER"));
 #endif
 
 #ifdef USE_IMAP
   crc =
-    crc32 (crc, (unsigned char const *) "USE_IMAP", mutt_strlen ("USE_IMAP"));
+    crc32 (crc, (unsigned char const *) "USE_IMAP", safe_strlen ("USE_IMAP"));
+#endif
+
+#ifdef USE_NNTP
+  crc =
+    crc32 (crc, (unsigned char const *) "USE_NNTP", safe_strlen ("USE_NNTP"));
 #endif
   return crc;
 }
@@ -502,7 +514,7 @@ static const char *mutt_hcache_per_folder (const char *path,
   }
 
   MD5Init (&md5);
-  MD5Update (&md5, (unsigned char *) folder, strlen (folder));
+  MD5Update (&md5, (unsigned char *) folder, safe_strlen (folder));
   MD5Final (md5sum, &md5);
 
   ret = snprintf (mutt_hcache_per_folder_path, _POSIX_PATH_MAX,
@@ -523,7 +535,7 @@ static const char *mutt_hcache_per_folder (const char *path,
 /* This function transforms a header into a char so that it is useable by
  * db_store */
 static void *mutt_hcache_dump (void *_db, HEADER * h, int *off,
-                               uint64_t uid_validity)
+                               unsigned long uid_validity)
 {
   struct header_cache *db = _db;
   unsigned char *d = NULL;
@@ -533,7 +545,7 @@ static void *mutt_hcache_dump (void *_db, HEADER * h, int *off,
   d = lazy_malloc (sizeof (validate));
 
   if (uid_validity) {
-    memcpy (d, &uid_validity, sizeof (uint64_t));
+    memcpy (d, &uid_validity, sizeof (unsigned long));
   }
   else {
     struct timeval now;
@@ -651,7 +663,7 @@ void *mutt_hcache_fetch (void *db, const char *filename,
   }
 
   strncpy (path, h->folder, sizeof (path));
-  strncat (path, filename, sizeof (path) - mutt_strlen (path));
+  strncat (path, filename, sizeof (path) - safe_strlen (path));
 
   key.dptr = path;
   key.dsize = keylen (path);
@@ -668,7 +680,7 @@ void *mutt_hcache_fetch (void *db, const char *filename,
 
 int
 mutt_hcache_store (void *db, const char *filename, HEADER * header,
-                   uint64_t uid_validity, size_t (*keylen) (const char *fn))
+                   unsigned long uid_validity, size_t (*keylen) (const char *fn))
 {
   struct header_cache *h = db;
   datum key;
@@ -681,7 +693,7 @@ mutt_hcache_store (void *db, const char *filename, HEADER * header,
   }
 
   strncpy (path, h->folder, sizeof (path));
-  strncat (path, filename, sizeof (path) - mutt_strlen (path));
+  strncat (path, filename, sizeof (path) - safe_strlen (path));
 
   key.dptr = path;
   key.dsize = keylen (path);
@@ -708,7 +720,7 @@ mutt_hcache_delete (void *db, const char *filename,
   }
 
   strncpy (path, h->folder, sizeof (path));
-  strncat (path, filename, sizeof (path) - mutt_strlen (path));
+  strncat (path, filename, sizeof (path) - safe_strlen (path));
 
   key.dptr = path;
   key.dsize = keylen (path);
@@ -848,7 +860,7 @@ void *mutt_hcache_fetch (void *db, const char *filename,
 
 int
 mutt_hcache_store (void *db, const char *filename, HEADER * header,
-                   uint64_t uid_validity, size_t (*keylen) (const char *fn))
+                   unsigned long uid_validity, size_t (*keylen) (const char *fn))
 {
   DBT key;
   DBT data;