Rocco Rutte:
[apps/madmutt.git] / buffy.c
diff --git a/buffy.c b/buffy.c
index 67800dd..1f49f91 100644 (file)
--- a/buffy.c
+++ b/buffy.c
@@ -16,8 +16,8 @@
 
 #include "mutt.h"
 #include "buffy.h"
 
 #include "mutt.h"
 #include "buffy.h"
-#include "mailbox.h"
 #include "mx.h"
 #include "mx.h"
+#include "mh.h"
 #include "sidebar.h"
 
 #include "mutt_curses.h"
 #include "sidebar.h"
 
 #include "mutt_curses.h"
@@ -71,13 +71,13 @@ int fseek_last_message (FILE * f)
    * reads will be on block boundaries, which might increase efficiency.  */
   while ((pos -= bytes_read) >= 0) {
     /* we save in the buffer at the end the first 7 chars from the last read */
    * reads will be on block boundaries, which might increase efficiency.  */
   while ((pos -= bytes_read) >= 0) {
     /* we save in the buffer at the end the first 7 chars from the last read */
-    strncpy (buffer + BUFSIZ, buffer, 5 + 2);   /* 2 == 2 * mutt_strlen(CRLF) */
+    strncpy (buffer + BUFSIZ, buffer, 5 + 2);   /* 2 == 2 * safe_strlen(CRLF) */
     fseek (f, pos, SEEK_SET);
     bytes_read = fread (buffer, sizeof (char), bytes_read, f);
     if (bytes_read == -1)
       return -1;
     for (i = bytes_read; --i >= 0;)
     fseek (f, pos, SEEK_SET);
     bytes_read = fread (buffer, sizeof (char), bytes_read, f);
     if (bytes_read == -1)
       return -1;
     for (i = bytes_read; --i >= 0;)
-      if (!mutt_strncmp (buffer + i, "\n\nFrom ", mutt_strlen ("\n\nFrom "))) { /* found it - go to the beginning of the From */
+      if (!safe_strncmp (buffer + i, "\n\nFrom ", safe_strlen ("\n\nFrom "))) { /* found it - go to the beginning of the From */
         fseek (f, pos + i + 2, SEEK_SET);
         return 0;
       }
         fseek (f, pos + i + 2, SEEK_SET);
         return 0;
       }
@@ -85,7 +85,7 @@ int fseek_last_message (FILE * f)
   }
 
   /* here we are at the beginning of the file */
   }
 
   /* here we are at the beginning of the file */
-  if (!mutt_strncmp ("From ", buffer, 5)) {
+  if (!safe_strncmp ("From ", buffer, 5)) {
     fseek (f, 0, 0);
     return (0);
   }
     fseek (f, 0, 0);
     return (0);
   }
@@ -135,19 +135,21 @@ int test_new_folder (const char *path)
 
 BUFFY *mutt_find_mailbox (const char *path)
 {
 
 BUFFY *mutt_find_mailbox (const char *path)
 {
-  BUFFY *tmp = NULL;
   struct stat sb;
   struct stat tmp_sb;
   struct stat sb;
   struct stat tmp_sb;
+  int i = 0;
 
   if (stat (path, &sb) != 0)
     return NULL;
 
 
   if (stat (path, &sb) != 0)
     return NULL;
 
-  for (tmp = Incoming; tmp; tmp = tmp->next) {
-    if (stat (tmp->path, &tmp_sb) == 0 &&
-        sb.st_dev == tmp_sb.st_dev && sb.st_ino == tmp_sb.st_ino)
-      break;
+  if (!list_empty(Incoming)) {
+    for (i = 0; i < Incoming->length; i++) {
+      if (stat (Incoming->data[i], &tmp_sb) == 0 &&
+          sb.st_dev == tmp_sb.st_dev && sb.st_ino == tmp_sb.st_ino)
+        return ((BUFFY*) Incoming->data[i]);
+    }
   }
   }
-  return tmp;
+  return (NULL);
 }
 
 void mutt_update_mailbox (BUFFY * b)
 }
 
 void mutt_update_mailbox (BUFFY * b)
@@ -176,7 +178,7 @@ int buffy_lookup (const char* path) {
   if (list_empty(Incoming) || !path || !*path)
     return (-1);
   for (i = 0; i < Incoming->length; i++) {
   if (list_empty(Incoming) || !path || !*path)
     return (-1);
   for (i = 0; i < Incoming->length; i++) {
-    if (mutt_strcmp (((BUFFY*) Incoming->data[i])->path, path) == 0)
+    if (safe_strcmp (((BUFFY*) Incoming->data[i])->path, path) == 0)
       return (i);
   }
   return (-1);
       return (i);
   }
   return (-1);
@@ -196,7 +198,7 @@ int mutt_parse_mailboxes (BUFFER * path, BUFFER * s, unsigned long data,
     mutt_extract_token (path, s, 0);
     strfcpy (buf, path->data, sizeof (buf));
 
     mutt_extract_token (path, s, 0);
     strfcpy (buf, path->data, sizeof (buf));
 
-    if (data == M_UNMAILBOXES && mutt_strcmp (buf, "*") == 0) {
+    if (data == M_UNMAILBOXES && safe_strcmp (buf, "*") == 0) {
       list_del (&Incoming, buffy_free);
       return 0;
     }
       list_del (&Incoming, buffy_free);
       return 0;
     }
@@ -269,7 +271,7 @@ int mutt_buffy_check (int force)
   struct stat contex_sb;
   time_t now, last1;
   CONTEXT *ctx;
   struct stat contex_sb;
   time_t now, last1;
   CONTEXT *ctx;
-  int i = 0;
+  int i = 0, local = 0;
 #ifdef USE_IMAP
   time_t last2;
 
 #ifdef USE_IMAP
   time_t last2;
 
@@ -301,45 +303,21 @@ int mutt_buffy_check (int force)
   BuffyCount = 0;
   BuffyNotify = 0;
 
   BuffyCount = 0;
   BuffyNotify = 0;
 
-#ifdef USE_IMAP
-  if (!Context || Context->magic != M_IMAP)
-#endif
-#ifdef USE_POP
-    if (!Context || Context->magic != M_POP)
-#endif
-#ifdef USE_NNTP
-      if (!Context || Context->magic != M_NNTP)
-#endif
-        /* check device ID and serial number instead of comparing paths */
-        if (!Context || !Context->path
-            || stat (Context->path, &contex_sb) != 0) {
-          contex_sb.st_dev = 0;
-          contex_sb.st_ino = 0;
-        }
+  if ((!Context || mx_is_local (Context->magic-1)) && stat (Context->path, &contex_sb) != 0) {
+    /* check device ID and serial number instead of comparing paths */
+    contex_sb.st_dev = 0;
+    contex_sb.st_ino = 0;
+  }
 
   for (i = 0; i < Incoming->length; i++) {
     tmp = (BUFFY*) Incoming->data[i];
 
   for (i = 0; i < Incoming->length; i++) {
     tmp = (BUFFY*) Incoming->data[i];
-#ifdef USE_IMAP
-    if (mx_is_imap (tmp->path))
-      tmp->magic = M_IMAP;
-    else
-#endif
-#ifdef USE_POP
-    if (mx_is_pop (tmp->path))
-      tmp->magic = M_POP;
-    else
-#endif
-#ifdef USE_NNTP
-    if ((tmp->magic == M_NNTP) || mx_is_nntp (tmp->path))
-      tmp->magic = M_NNTP;
-    else
-#endif
-    if (stat (tmp->path, &sb) != 0 || sb.st_size == 0 ||
-          (!tmp->magic && (tmp->magic = mx_get_magic (tmp->path)) <= 0)) {
+    tmp->magic = mx_get_magic (tmp->path);
+    local = mx_is_local (tmp->magic-1);
+    if ((tmp->magic <= 0 || local) && (stat (tmp->path, &sb) != 0 || sb.st_size == 0)) {
       /* if the mailbox still doesn't exist, set the newly created flag to
        * be ready for when it does. */
       tmp->newly_created = 1;
       /* if the mailbox still doesn't exist, set the newly created flag to
        * be ready for when it does. */
       tmp->newly_created = 1;
-      tmp->magic = 0;
+      tmp->magic = -1;
 #ifdef BUFFY_SIZE
       tmp->size = 0;
 #endif
 #ifdef BUFFY_SIZE
       tmp->size = 0;
 #endif
@@ -348,30 +326,9 @@ int mutt_buffy_check (int force)
 
     /* check to see if the folder is the currently selected folder
      * before polling */
 
     /* check to see if the folder is the currently selected folder
      * before polling */
-    if (!Context || !Context->path || ((0
-#ifdef USE_IMAP
-                                        || tmp->magic == M_IMAP
-#endif
-#ifdef USE_POP
-                                        || tmp->magic == M_POP
-#endif
-#ifdef USE_NNTP
-                                        || tmp->magic == M_NNTP
-#endif
-                                       )? mutt_strcmp (tmp->path,
-                                                       Context->path) : (sb.
-                                                                         st_dev
-                                                                         !=
-                                                                         contex_sb.
-                                                                         st_dev
-                                                                         ||
-                                                                         sb.
-                                                                         st_ino
-                                                                         !=
-                                                                         contex_sb.
-                                                                         st_ino)
-        )
-      ) {
+    if (!Context || !Context->path || (local ? (sb.st_dev != contex_sb.st_dev ||
+                                                sb.st_ino != contex_sb.st_ino) :
+                                       safe_strcmp (tmp->path, Context->path))) {
       switch (tmp->magic) {
       case M_MBOX:
       case M_MMDF:
       switch (tmp->magic) {
       case M_MBOX:
       case M_MMDF:
@@ -518,15 +475,6 @@ int mutt_buffy_check (int force)
         break;
 #endif
 
         break;
 #endif
 
-#ifdef USE_POP
-      case M_POP:
-        break;
-#endif
-
-#ifdef USE_NNTP
-      case M_NNTP:
-        break;
-#endif
       }
     }
 #ifdef BUFFY_SIZE
       }
     }
 #ifdef BUFFY_SIZE
@@ -561,7 +509,7 @@ int mutt_buffy_list (void)
   pos = 0;
   first = 1;
   buffylist[0] = 0;
   pos = 0;
   first = 1;
   buffylist[0] = 0;
-  pos += mutt_strlen (strncat (buffylist, _("New mail in "), sizeof (buffylist) - 1 - pos)); /* __STRNCAT_CHECKED__ */
+  pos += safe_strlen (strncat (buffylist, _("New mail in "), sizeof (buffylist) - 1 - pos)); /* __STRNCAT_CHECKED__ */
   if (Incoming) {
     for (i = 0; i < Incoming->length; i++) {
       tmp = (BUFFY*) Incoming->data[i];
   if (Incoming) {
     for (i = 0; i < Incoming->length; i++) {
       tmp = (BUFFY*) Incoming->data[i];
@@ -572,23 +520,23 @@ int mutt_buffy_list (void)
       strfcpy (path, tmp->path, sizeof (path));
       mutt_pretty_mailbox (path);
 
       strfcpy (path, tmp->path, sizeof (path));
       mutt_pretty_mailbox (path);
 
-      if (!first && pos + mutt_strlen (path) >= COLS - 7)
+      if (!first && pos + safe_strlen (path) >= COLS - 7)
         break;
 
       if (!first)
         break;
 
       if (!first)
-        pos += mutt_strlen (strncat (buffylist + pos, ", ", sizeof (buffylist) - 1 - pos));    /* __STRNCAT_CHECKED__ */
+        pos += safe_strlen (strncat (buffylist + pos, ", ", sizeof (buffylist) - 1 - pos));    /* __STRNCAT_CHECKED__ */
 
       /* Prepend an asterisk to mailboxes not already notified */
       if (!tmp->notified) {
 
       /* Prepend an asterisk to mailboxes not already notified */
       if (!tmp->notified) {
-        /* pos += mutt_strlen (strncat(buffylist + pos, "*", sizeof(buffylist)-1-pos));  __STRNCAT_CHECKED__ */
+        /* pos += safe_strlen (strncat(buffylist + pos, "*", sizeof(buffylist)-1-pos));  __STRNCAT_CHECKED__ */
         tmp->notified = 1;
         BuffyNotify--;
       }
         tmp->notified = 1;
         BuffyNotify--;
       }
-      pos += mutt_strlen (strncat (buffylist + pos, path, sizeof (buffylist) - 1 - pos));      /* __STRNCAT_CHECKED__ */
+      pos += safe_strlen (strncat (buffylist + pos, path, sizeof (buffylist) - 1 - pos));      /* __STRNCAT_CHECKED__ */
       first = 0;
     }
   }
       first = 0;
     }
   }
-  if (!first && tmp) {
+  if (!first && i < Incoming->length) {
     strncat (buffylist + pos, ", ...", sizeof (buffylist) - 1 - pos);   /* __STRNCAT_CHECKED__ */
   }
   if (!first) {
     strncat (buffylist + pos, ", ...", sizeof (buffylist) - 1 - pos);   /* __STRNCAT_CHECKED__ */
   }
   if (!first) {