| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 
 | From f448072225a25bba74cab0ceedcf349951cdaab3 Mon Sep 17 00:00:00 2001
From: "Bernhard R. Link" <brlink@debian.org>
Date: Sat, 19 Dec 2009 13:23:35 +0100
Subject: Retry autodetection when mailbox is not statable
See http://bugs.debian.org/168910
---
 xbuffy.c | 72 +++++++++++++++++++++++++++++++++++++---------------------------
 xbuffy.h |  1 +
 2 files changed, 43 insertions(+), 30 deletions(-)
diff --git a/xbuffy.c b/xbuffy.c
index 7d89b2c..81dee2c 100644
--- a/xbuffy.c
+++ b/xbuffy.c
@@ -210,7 +210,7 @@ void CheckBox(i)
     }
 #endif                          /* USE_NNTP */
     if ((boxInfo[i].type == MAILBOX) || (boxInfo[i].type == MAILDIR) ||
-	(boxInfo[i].type == MHDIR))
+	(boxInfo[i].type == MHDIR) || (boxInfo[i].type == UNKNOWNMBOX))
     {
         num = CountUnixMail(currentBox, NULL, &beenTouched);
     }
@@ -570,7 +570,7 @@ void PopupHeader(w, i, event, cont)
 
     /* update the number on the box (in case there are new articles) */
     if ((currentBox->type == MAILBOX) || (currentBox->type == MAILDIR) ||
-	(currentBox->type == MHDIR))
+	(currentBox->type == MHDIR) || (currentBox->type == UNKNOWNMBOX))
     {
         number = CountUnixMail(currentBox, mailHeaders, &beenTouched);
 
@@ -584,7 +584,7 @@ void PopupHeader(w, i, event, cont)
     UpdateBoxNumber(&boxInfo[i]);
 
     /* if the number is zero, there's no header, so leave */
-    if (boxInfo[i].n == 0)
+    if (boxInfo[i].n <= 0)
     {
         return;
     }
@@ -699,6 +699,34 @@ void BreakPopup(w, i, event, cont)
     headerUp[i] = FALSE;
 }
 
+void determineMBoxType(BoxInfo_t *b)
+{
+      struct stat st;
+      char tmp[_POSIX_PATH_MAX];
+
+      if (stat (b->box, &st) != -1) {
+	if (S_ISDIR (st.st_mode)) {
+	  /* check for maildir mailb->box */
+	  sprintf(tmp, "%s/cur", b->box);
+	  if (stat (tmp, &st) == 0 && S_ISDIR (st.st_mode)) {
+	    b->type = MAILDIR;
+	  } else {
+	    /* check for mh mailb->box */
+	    sprintf(tmp, "%s/.mh_sequences", b->box);
+	    if (access (tmp, F_OK) == 0) {
+	      b->type = MHDIR;
+	    } else {
+	      sprintf(tmp, "%s/.xmhcache", b->box);
+	      if (access (tmp, F_OK) == 0) {
+		b->type = MHDIR;
+	      }
+	    }
+	  }
+	} else
+	      b->type = MAILBOX;
+      } else
+	      b->type = UNKNOWNMBOX;
+}
 
 void ExecuteCommand(w, i, event, cont)
     Widget w;
@@ -978,6 +1006,12 @@ int CountUnixMail(mailBox, headerString, beenTouched)
 
     *beenTouched = FALSE;
    
+    if (mailBox->type == UNKNOWNMBOX) {
+	determineMBoxType(mailBox);
+    	if (mailBox->type == UNKNOWNMBOX)
+		return -1;
+    }
+
     if (mailBox->type == MAILBOX) {
       if (isLocked(mailBox->box))
         return (mailBox->n);
@@ -1015,8 +1049,7 @@ int CountUnixMail(mailBox, headerString, beenTouched)
       case MHDIR:
 	count = CountDirMail(mailBox, headerString);
 	break;
-      case NNTPBOX:
-      case CHECKFILE:
+      default:
 	return(0);
     }
 
@@ -1117,29 +1150,7 @@ void initBox(box, BoxType, pollTime, headerTime, BoxNameType, command, audioCmd,
       tempBox.type = CHECKFILE;
     } else if (BoxType == MAILBOX) 
     {
-      struct stat st;
-      char tmp[_POSIX_PATH_MAX];
-
-      if (stat (box, &st) != -1) {
-	if (S_ISDIR (st.st_mode)) {
-	  /* check for maildir mailbox */
-	  sprintf(tmp, "%s/cur", box);
-	  if (stat (tmp, &st) == 0 && S_ISDIR (st.st_mode)) {
-	    tempBox.type = MAILDIR;
-	  } else {
-	    /* check for mh mailbox */
-	    sprintf(tmp, "%s/.mh_sequences", box);
-	    if (access (tmp, F_OK) == 0) {
-	      tempBox.type = MHDIR;
-	    } else {
-	      sprintf(tmp, "%s/.xmhcache", box);
-	      if (access (tmp, F_OK) == 0) {
-		tempBox.type = MHDIR;
-	      }
-	    }
-	  }
-	}
-      }
+      determineMBoxType(&tempBox);
     }
     if ((pollTime <= 0) || (pollTime >= 3600))
         tempBox.pollTime = envPolltime;
@@ -1335,7 +1346,8 @@ int makeBoxTitle(currentBox)
     line[0] = '\0';
 
     if ((currentBox->type == MAILBOX) || (currentBox->type == MAILDIR) ||
-	(currentBox->type == MHDIR) || (currentBox->type == CHECKFILE))
+	(currentBox->type == MHDIR) || (currentBox->type == CHECKFILE) ||
+	(currentBox->type == UNKNOWN))
     {
         switch (currentBox->BoxNameType)
         {
@@ -1658,7 +1670,7 @@ int main(argc, argv)
         headerUp[i] = FALSE;
 
         if ((boxInfo[i].type == MAILBOX) || (boxInfo[i].type == MAILDIR) ||
-	    (boxInfo[i].type == MHDIR))
+	    (boxInfo[i].type == MHDIR) || (boxInfo[i].type == UNKNOWNMBOX))
             boxInfo[i].n = CountUnixMail(&boxInfo[i], NULL, &dummy);
 
         if (boxInfo[i].type == CHECKFILE)
diff --git a/xbuffy.h b/xbuffy.h
index 2c02a1c..e713364 100644
--- a/xbuffy.h
+++ b/xbuffy.h
@@ -45,6 +45,7 @@ enum BoxType_e {
   MHDIR,
   NNTPBOX,
   CHECKFILE,
+  UNKNOWNMBOX,
 };
 
 typedef enum BoxType_e BoxType_t;
 |