1 /* Conky, a system monitor, based on torsmo
3 * Any original torsmo code is licensed under the BSD license
5 * All code written since the fork of torsmo is licensed under the GPL
7 * Please see COPYING for details
9 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
10 * Copyright (c) 2005-2007 Brenden Matthews, Philip Kovacs, et. al.
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/>.
38 char *current_mail_spool;
40 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;
57 if (stat(mail->box, &buf)) {
61 ERR("can't stat %s: %s", mail->box, strerror(errno));
68 if (S_ISDIR(buf.st_mode)) {
71 struct dirent *dirent;
73 mail->mail_count = mail->new_mail_count = 0;
74 dirname = (char *) malloc(sizeof(char) * (strlen(mail->box) + 5));
79 strcpy(dirname, mail->box);
81 /* checking the cur subdirectory */
82 strcat(dirname, "cur");
84 dir = opendir(dirname);
86 ERR("cannot open directory");
90 dirent = readdir(dir);
92 /* . and .. are skipped */
93 if (dirent->d_name[0] != '.') {
96 dirent = readdir(dir);
100 dirname[strlen(dirname) - 3] = '\0';
101 strcat(dirname, "new");
103 dir = opendir(dirname);
105 ERR("cannot open directory");
109 dirent = readdir(dir);
111 /* . and .. are skipped */
112 if (dirent->d_name[0] != '.') {
113 mail->new_mail_count++;
116 dirent = readdir(dir);
125 if (buf.st_mtime != mail->last_mtime) {
126 /* yippee, modification time has changed, let's read mail count! */
129 int reading_status = 0;
131 /* could lock here but I don't think it's really worth it because
132 * this isn't going to write mail spool */
134 mail->new_mail_count = mail->mail_count = 0;
136 fp = open_file(mail->box, &rep);
141 /* NOTE: adds mail as new if there isn't Status-field at all */
146 if (fgets(buf, 128, fp) == NULL) {
150 if (strncmp(buf, "From ", 5) == 0) {
151 /* ignore MAILER-DAEMON */
152 if (strncmp(buf + 5, "MAILER-DAEMON ", 14) != 0) {
155 if (reading_status) {
156 mail->new_mail_count++;
163 && strncmp(buf, "X-Mozilla-Status:", 17) == 0) {
164 /* check that mail isn't already read */
165 if (strchr(buf + 21, '0')) {
166 mail->new_mail_count++;
172 if (reading_status && strncmp(buf, "Status:", 7) == 0) {
173 /* check that mail isn't already read */
174 if (strchr(buf + 7, 'R') == NULL) {
175 mail->new_mail_count++;
184 while (strchr(buf, '\n') == NULL && !feof(fp)) {
191 if (reading_status) {
192 mail->new_mail_count++;
195 mail->last_mtime = buf.st_mtime;