2 * Conky, a system monitor, based on torsmo
4 * This program is licensed under BSD license, read COPYING
19 char *current_mail_spool;
21 static time_t last_mail_mtime;
22 static double last_mail_update;
24 void update_mail_count()
28 if (current_mail_spool == NULL)
31 /* TODO: use that fine file modification notify on Linux 2.4 */
33 /* don't check mail so often (9.5s is minimum interval) */
34 if (current_update_time - last_mail_update < 9.5)
37 last_mail_update = current_update_time;
39 if (stat(current_mail_spool, &buf)) {
42 ERR("can't stat %s: %s", current_mail_spool,
50 if (S_ISDIR(buf.st_mode)) {
53 struct dirent *dirent;
55 info.new_mail_count = 0;
58 (char *) malloc(sizeof(char) *
59 (strlen(current_mail_spool) + 5));
64 strcpy(dirname, current_mail_spool);
66 /* checking the cur subdirectory */
67 strcat(dirname, "cur");
69 dir = opendir(dirname);
71 ERR("cannot open directory");
75 dirent = readdir(dir);
77 /* . and .. are skipped */
78 if (dirent->d_name[0] != '.') {
81 dirent = readdir(dir);
85 dirname[strlen(dirname) - 3] = '\0';
86 strcat(dirname, "new");
88 dir = opendir(dirname);
90 ERR("cannot open directory");
94 dirent = readdir(dir);
96 /* . and .. are skipped */
97 if (dirent->d_name[0] != '.') {
98 info.new_mail_count++;
101 dirent = readdir(dir);
110 if (buf.st_mtime != last_mail_mtime) {
111 /* yippee, modification time has changed, let's read mail count! */
114 int reading_status = 0;
116 /* could lock here but I don't think it's really worth it because
117 * this isn't going to write mail spool */
119 info.new_mail_count = 0;
122 fp = open_file(current_mail_spool, &rep);
126 /* NOTE: adds mail as new if there isn't Status-field at all */
130 if (fgets(buf, 128, fp) == NULL)
133 if (strncmp(buf, "From ", 5) == 0) {
134 /* ignore MAILER-DAEMON */
135 if (strncmp(buf + 5, "MAILER-DAEMON ", 14)
140 info.new_mail_count++;
146 && strncmp(buf, "X-Mozilla-Status:",
148 /* check that mail isn't already read */
149 if (strchr(buf + 21, '0'))
150 info.new_mail_count++;
156 && strncmp(buf, "Status:", 7) == 0) {
157 /* check that mail isn't already read */
158 if (strchr(buf + 7, 'R') == NULL)
159 info.new_mail_count++;
167 while (strchr(buf, '\n') == NULL && !feof(fp))
174 info.new_mail_count++;
176 last_mail_mtime = buf.st_mtime;