9 char *current_mail_spool;
11 static time_t last_mail_mtime;
12 static double last_mail_update;
14 void update_mail_count()
18 if (current_mail_spool == NULL)
21 /* TODO: use that fine file modification notify on Linux 2.4 */
23 /* don't check mail so often (9.5s is minimum interval) */
24 if (current_update_time - last_mail_update < 9.5)
27 last_mail_update = current_update_time;
29 if (stat(current_mail_spool, &buf)) {
32 ERR("can't stat %s: %s", current_mail_spool,
40 if (S_ISDIR(buf.st_mode)) {
43 struct dirent *dirent;
45 info.new_mail_count = 0;
48 (char *) malloc(sizeof(char) *
49 (strlen(current_mail_spool) + 5));
54 strcpy(dirname, current_mail_spool);
56 /* checking the cur subdirectory */
57 strcat(dirname, "cur");
59 dir = opendir(dirname);
61 ERR("cannot open directory");
65 dirent = readdir(dir);
67 /* . and .. are skipped */
68 if (dirent->d_name[0] != '.') {
71 dirent = readdir(dir);
75 dirname[strlen(dirname) - 3] = '\0';
76 strcat(dirname, "new");
78 dir = opendir(dirname);
80 ERR("cannot open directory");
84 dirent = readdir(dir);
86 /* . and .. are skipped */
87 if (dirent->d_name[0] != '.') {
88 info.new_mail_count++;
91 dirent = readdir(dir);
102 if (buf.st_mtime != last_mail_mtime) {
103 /* yippee, modification time has changed, let's read mail count! */
106 int reading_status = 0;
108 /* could lock here but I don't think it's really worth it because
109 * this isn't going to write mail spool */
111 info.new_mail_count = 0;
114 fp = open_file(current_mail_spool, &rep);
118 /* NOTE: adds mail as new if there isn't Status-field at all */
122 if (fgets(buf, 128, fp) == NULL)
125 if (strncmp(buf, "From ", 5) == 0) {
126 /* ignore MAILER-DAEMON */
127 if (strncmp(buf + 5, "MAILER-DAEMON ", 14)
132 info.new_mail_count++;
138 && strncmp(buf, "X-Mozilla-Status:",
140 /* check that mail isn't already read */
141 if (strchr(buf + 21, '0'))
142 info.new_mail_count++;
148 && strncmp(buf, "Status:", 7) == 0) {
149 /* check that mail isn't already read */
150 if (strchr(buf + 7, 'R') == NULL)
151 info.new_mail_count++;
159 while (strchr(buf, '\n') == NULL && !feof(fp))
166 info.new_mail_count++;
168 last_mail_mtime = buf.st_mtime;