2 * Conky, a system monitor, based on torsmo
4 * Any original torsmo code is licensed under the BSD license
6 * All code written since the fork of torsmo is licensed under the GPL
8 * Please see COPYING for details
10 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
11 * Copyright (c) 2005-2007 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
12 * All rights reserved.
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
39 char *current_mail_spool;
41 void update_mail_count(struct local_mail_s *mail)
48 /* TODO: use that fine file modification notify on Linux 2.4 */
50 /* don't check mail so often (9.5s is minimum interval) */
51 if (current_update_time - mail->last_update < 9.5)
54 mail->last_update = current_update_time;
56 if (stat(mail->box, &buf)) {
59 ERR("can't stat %s: %s", mail->box,
67 if (S_ISDIR(buf.st_mode)) {
70 struct dirent *dirent;
72 mail->mail_count = mail->new_mail_count = 0;
74 (char *) malloc(sizeof(char) *
75 (strlen(mail->box) + 5));
80 strcpy(dirname, mail->box);
82 /* checking the cur subdirectory */
83 strcat(dirname, "cur");
85 dir = opendir(dirname);
87 ERR("cannot open directory");
91 dirent = readdir(dir);
93 /* . and .. are skipped */
94 if (dirent->d_name[0] != '.') {
97 dirent = readdir(dir);
101 dirname[strlen(dirname) - 3] = '\0';
102 strcat(dirname, "new");
104 dir = opendir(dirname);
106 ERR("cannot open directory");
110 dirent = readdir(dir);
112 /* . and .. are skipped */
113 if (dirent->d_name[0] != '.') {
114 mail->new_mail_count++;
117 dirent = readdir(dir);
126 if (buf.st_mtime != mail->last_mtime) {
127 /* yippee, modification time has changed, let's read mail count! */
130 int reading_status = 0;
132 /* could lock here but I don't think it's really worth it because
133 * this isn't going to write mail spool */
135 mail->new_mail_count = mail->mail_count = 0;
137 fp = open_file(mail->box, &rep);
141 /* NOTE: adds mail as new if there isn't Status-field at all */
145 if (fgets(buf, 128, fp) == NULL)
148 if (strncmp(buf, "From ", 5) == 0) {
149 /* ignore MAILER-DAEMON */
150 if (strncmp(buf + 5, "MAILER-DAEMON ", 14)
155 mail->new_mail_count++;
161 && strncmp(buf, "X-Mozilla-Status:",
163 /* check that mail isn't already read */
164 if (strchr(buf + 21, '0'))
165 mail->new_mail_count++;
171 && strncmp(buf, "Status:", 7) == 0) {
172 /* check that mail isn't already read */
173 if (strchr(buf + 7, 'R') == NULL)
174 mail->new_mail_count++;
182 while (strchr(buf, '\n') == NULL && !feof(fp))
189 mail->new_mail_count++;
191 mail->last_mtime = buf.st_mtime;