2 * Conky, a system monitor, based on torsmo
4 * This program is licensed under BSD license, read COPYING
17 char *current_mail_spool;
19 static time_t last_mail_mtime;
20 static double last_mail_update;
22 void update_mail_count()
26 if (current_mail_spool == NULL)
29 /* TODO: use that fine file modification notify on Linux 2.4 */
31 /* don't check mail so often (9.5s is minimum interval) */
32 if (current_update_time - last_mail_update < 9.5)
35 last_mail_update = current_update_time;
37 if (stat(current_mail_spool, &buf)) {
40 ERR("can't stat %s: %s", current_mail_spool,
48 if (S_ISDIR(buf.st_mode)) {
51 struct dirent *dirent;
53 info.new_mail_count = 0;
56 (char *) malloc(sizeof(char) *
57 (strlen(current_mail_spool) + 5));
62 strcpy(dirname, current_mail_spool);
64 /* checking the cur subdirectory */
65 strcat(dirname, "cur");
67 dir = opendir(dirname);
69 ERR("cannot open directory");
73 dirent = readdir(dir);
75 /* . and .. are skipped */
76 if (dirent->d_name[0] != '.') {
79 dirent = readdir(dir);
83 dirname[strlen(dirname) - 3] = '\0';
84 strcat(dirname, "new");
86 dir = opendir(dirname);
88 ERR("cannot open directory");
92 dirent = readdir(dir);
94 /* . and .. are skipped */
95 if (dirent->d_name[0] != '.') {
96 info.new_mail_count++;
99 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;