simplify hcache yet a bit more.
[apps/madmutt.git] / lib-mx / mh.c
index bfaaab2..ab24c4f 100644 (file)
@@ -86,19 +86,6 @@ static short mhs_set (struct mh_sequences *mhs, int i, short f)
   return mhs->flags[i];
 }
 
-#if 0
-
-/* unused */
-
-static short mhs_unset (struct mh_sequences *mhs, int i, short f)
-{
-  mhs_alloc (mhs, i);
-  mhs->flags[i] &= ~f;
-  return mhs->flags[i];
-}
-
-#endif
-
 static void mh_read_token (char *t, int *first, int *last)
 {
   char *p;
@@ -151,7 +138,7 @@ static void mh_read_sequences (struct mh_sequences *mhs, const char *path)
   }
 
   p_delete(&buff);
-  safe_fclose (&fp);
+  m_fclose(&fp);
 }
 
 int mh_buffy (const char *path)
@@ -171,12 +158,13 @@ int mh_buffy (const char *path)
 
 static int mh_mkstemp (CONTEXT * dest, FILE ** fp, char **tgt)
 {
+  static int Counter = 0;
   int fd;
   char path[_POSIX_PATH_MAX];
 
   for (;;) {
     snprintf (path, _POSIX_PATH_MAX, "%s/.mutt-%s-%d-%d",
-              dest->path, NONULL (Hostname), (int) getpid (), Counter++);
+              dest->path, NONULL(MCore.shorthost), (int) getpid (), Counter++);
     umask (Umask);
     if ((fd = open (path, O_WRONLY | O_EXCL | O_CREAT, 0666)) == -1) {
       if (errno != EEXIST) {
@@ -291,7 +279,7 @@ static void mh_update_sequences (CONTEXT * ctx)
       fprintf (nfp, "%s\n", buff);
     }
   }
-  safe_fclose (&ofp);
+  m_fclose(&ofp);
 
   /* now, update our unseen, flagged, and replied sequences */
   for (l = 0; l < ctx->msgcount; l++) {
@@ -331,7 +319,7 @@ static void mh_update_sequences (CONTEXT * ctx)
 
 
   /* try to commit the changes - no guarantee here */
-  safe_fclose (&nfp);
+  m_fclose(&nfp);
 
   unlink (sequences);
   if (safe_rename (tmpfname, sequences) != 0) {
@@ -372,17 +360,17 @@ static void mh_sequences_add_one (CONTEXT * ctx, int n, short unseen,
   snprintf (sequences, sizeof (sequences), "%s/.mh_sequences", ctx->path);
   if ((ofp = fopen (sequences, "r"))) {
     while ((buff = mutt_read_line (buff, &sz, ofp, &line))) {
-      if (unseen && !strncmp (buff, seq_unseen, m_strlen(seq_unseen))) {
+      if (unseen && !m_strncmp (buff, seq_unseen, m_strlen(seq_unseen))) {
         fprintf (nfp, "%s %d\n", buff, n);
         unseen_done = 1;
       }
       else if (flagged
-               && !strncmp (buff, seq_flagged, m_strlen(seq_flagged))) {
+               && !m_strncmp (buff, seq_flagged, m_strlen(seq_flagged))) {
         fprintf (nfp, "%s %d\n", buff, n);
         flagged_done = 1;
       }
       else if (replied
-               && !strncmp (buff, seq_replied, m_strlen(seq_replied))) {
+               && !m_strncmp (buff, seq_replied, m_strlen(seq_replied))) {
         fprintf (nfp, "%s %d\n", buff, n);
         replied_done = 1;
       }
@@ -390,7 +378,7 @@ static void mh_sequences_add_one (CONTEXT * ctx, int n, short unseen,
         fprintf (nfp, "%s\n", buff);
     }
   }
-  safe_fclose (&ofp);
+  m_fclose(&ofp);
   p_delete(&buff);
 
   if (!unseen_done && unseen)
@@ -400,7 +388,7 @@ static void mh_sequences_add_one (CONTEXT * ctx, int n, short unseen,
   if (!replied_done && replied)
     fprintf (nfp, "%s: %d\n", NONULL (MhReplied), n);
 
-  safe_fclose (&nfp);
+  m_fclose(&nfp);
 
   unlink (sequences);
   if (safe_rename (tmpfname, sequences) != 0)
@@ -547,7 +535,7 @@ static HEADER *maildir_parse_message (int magic, const char *fname,
     h->env = mutt_read_rfc822_header (f, h, 0, 0);
 
     fstat (fileno (f), &st);
-    fclose (f);
+    m_fclose(&f);
 
     if (!h->received)
       h->received = h->date_sent;
@@ -742,7 +730,7 @@ static void maildir_delayed_parsing (CONTEXT * ctx, struct maildir *md)
   int count;
 
 #ifdef USE_HCACHE
-  void *hc = NULL;
+  hcache_t *hc = NULL;
   void *data;
   struct timeval *when = NULL;
   struct stat lastchanged;
@@ -793,7 +781,7 @@ static void maildir_delayed_parsing (CONTEXT * ctx, struct maildir *md)
 #endif
   }
 #ifdef USE_HCACHE
-  mutt_hcache_close (hc);
+  mutt_hcache_close (&hc);
 #endif
 }
 
@@ -905,6 +893,7 @@ static void maildir_flags (char *dest, ssize_t destlen, HEADER * hdr)
 
 static int maildir_open_new_message (MESSAGE * msg, CONTEXT * dest, HEADER * hdr)
 {
+  static int Counter = 0;
   int fd;
   char path[_POSIX_PATH_MAX];
   char suffix[16];
@@ -930,7 +919,7 @@ static int maildir_open_new_message (MESSAGE * msg, CONTEXT * dest, HEADER * hdr
   for (;;) {
     snprintf (path, _POSIX_PATH_MAX, "%s/tmp/%s.%ld.%u_%d.%s%s",
               dest->path, subdir, (long) time (NULL),
-              (unsigned int) getpid (), Counter++, NONULL (Hostname), suffix);
+              (unsigned int) getpid (), Counter++, NONULL (MCore.shorthost), suffix);
 
     umask (Umask);
     if ((fd = open (path, O_WRONLY | O_EXCL | O_CREAT, 0666)) == -1) {
@@ -979,13 +968,14 @@ static int maildir_open_new_message (MESSAGE * msg, CONTEXT * dest, HEADER * hdr
 
 static int maildir_commit_message (MESSAGE * msg, CONTEXT * ctx, HEADER * hdr)
 {
+  static int Counter = 0;
   char subdir[4];
   char suffix[16];
   char path[_POSIX_PATH_MAX];
   char full[_POSIX_PATH_MAX];
   char *s;
 
-  if (safe_fclose (&msg->fp) != 0)
+  if (m_fclose(&msg->fp) != 0)
     return -1;
 
   /* extract the subdir */
@@ -1002,7 +992,7 @@ static int maildir_commit_message (MESSAGE * msg, CONTEXT * ctx, HEADER * hdr)
   for (;;) {
     snprintf (path, _POSIX_PATH_MAX, "%s/%ld.%u_%d.%s%s", subdir,
               (long) time (NULL), (unsigned int) getpid (), Counter++,
-              NONULL (Hostname), suffix);
+              NONULL (MCore.shorthost), suffix);
     snprintf (full, _POSIX_PATH_MAX, "%s/%s", ctx->path, path);
 
     if (safe_rename (msg->path, full) == 0) {
@@ -1053,7 +1043,7 @@ static int _mh_commit_message (MESSAGE * msg, CONTEXT * ctx, HEADER * hdr,
   char path[_POSIX_PATH_MAX];
   char tmp[16];
 
-  if (safe_fclose (&msg->fp) != 0)
+  if (m_fclose(&msg->fp) != 0)
     return -1;
 
   if ((dirp = opendir (ctx->path)) == NULL) {
@@ -1441,7 +1431,7 @@ static int maildir_check_mailbox (CONTEXT * ctx, int *index_hint, int unused __a
   struct maildir *md;           /* list of messages in the mailbox */
   struct maildir **last, *p;
   int i;
-  HASH *fnames;                 /* hash table for quickly looking up the base filename
+  hash_t *fnames;                 /* hash table for quickly looking up the base filename
                                    for a maildir message */
 
   if (!option (OPTCHECKNEW))
@@ -1482,12 +1472,12 @@ static int maildir_check_mailbox (CONTEXT * ctx, int *index_hint, int unused __a
    * of each message we scanned.  This is used in the loop over the
    * existing messages below to do some correlation.
    */
-  fnames = hash_create (1031);
+  fnames = hash_new (1031, 0);
 
   for (p = md; p; p = p->next) {
     maildir_canon_filename (buf, p->h->path, sizeof (buf));
     p->canon_fname = m_strdup(buf);
-    hash_insert (fnames, p->canon_fname, p, 0);
+    hash_insert (fnames, p->canon_fname, p);
   }
 
   /* check for modifications and adjust flags */
@@ -1522,8 +1512,8 @@ static int maildir_check_mailbox (CONTEXT * ctx, int *index_hint, int unused __a
      * Check to see if we have enough information to know if the
      * message has disappeared out from underneath us.
      */
-    else if (((changed & 1) && (!strncmp (ctx->hdrs[i]->path, "new/", 4))) ||
-             ((changed & 2) && (!strncmp (ctx->hdrs[i]->path, "cur/", 4)))) {
+    else if (((changed & 1) && (!m_strncmp (ctx->hdrs[i]->path, "new/", 4))) ||
+             ((changed & 2) && (!m_strncmp (ctx->hdrs[i]->path, "cur/", 4)))) {
       /* This message disappeared, so we need to simulate a "reopen"
        * event.  We know it disappeared because we just scanned the
        * subdirectory it used to reside in.
@@ -1540,7 +1530,7 @@ static int maildir_check_mailbox (CONTEXT * ctx, int *index_hint, int unused __a
   }
 
   /* destroy the file name hash */
-  hash_destroy (&fnames, NULL);
+  hash_delete (&fnames, NULL);
 
   /* If we didn't just get new mail, update the tables. */
   if (occult)
@@ -1574,7 +1564,7 @@ static int mh_check_mailbox (CONTEXT * ctx, int *index_hint, int unused __attrib
   struct maildir *md, *p;
   struct maildir **last = NULL;
   struct mh_sequences mhs;
-  HASH *fnames;
+  hash_t *fnames;
   int i;
 
   if (!option (OPTCHECKNEW))
@@ -1591,7 +1581,7 @@ static int mh_check_mailbox (CONTEXT * ctx, int *index_hint, int unused __attrib
     FILE *fp = NULL;
 
     if (mh_mkstemp (ctx, &fp, &tmp) == 0) {
-      safe_fclose (&fp);
+      m_fclose(&fp);
       if (safe_rename (tmp, buf) == -1)
         unlink (tmp);
       p_delete(&tmp);
@@ -1620,10 +1610,10 @@ static int mh_check_mailbox (CONTEXT * ctx, int *index_hint, int unused __attrib
   mhs_free_sequences (&mhs);
 
   /* check for modifications and adjust flags */
-  fnames = hash_create (1031);
+  fnames = hash_new (1031, 0);
 
   for (p = md; p; p = p->next)
-    hash_insert (fnames, p->h->path, p, 0);
+    hash_insert (fnames, p->h->path, p);
 
   for (i = 0; i < ctx->msgcount; i++) {
     ctx->hdrs[i]->active = 0;
@@ -1643,7 +1633,7 @@ static int mh_check_mailbox (CONTEXT * ctx, int *index_hint, int unused __attrib
 
   /* destroy the file name hash */
 
-  hash_destroy (&fnames, NULL);
+  hash_delete (&fnames, NULL);
 
   /* If we didn't just get new mail, update the tables. */
   if (occult)
@@ -1690,7 +1680,7 @@ static FILE *_maildir_open_find_message (const char *folder, const char *unique,
     if (!m_strcmp(tunique, unique)) {
       snprintf (fname, sizeof (fname), "%s/%s/%s", folder, subfolder,
                 de->d_name);
-      fp = fopen (fname, "r");  /* __FOPEN_CHECKED__ */
+      fp = fopen(fname, "r");
       oe = errno;
       break;
     }