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-2008 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/>.
36 char *current_mail_spool;
38 void update_mail_count(struct local_mail_s *mail)
46 /* TODO: use that fine file modification notify on Linux 2.4 */
48 /* don't check mail so often (9.5s is minimum interval) */
49 if (current_update_time - mail->last_update < 9.5) {
52 mail->last_update = current_update_time;
55 if (stat(mail->box, &st)) {
59 ERR("can't stat %s: %s", mail->box, strerror(errno));
66 if (S_ISDIR(st.st_mode)) {
69 struct dirent *dirent;
71 mail->mail_count = mail->new_mail_count = 0;
72 dirname = (char *) malloc(sizeof(char) * (strlen(mail->box) + 5));
77 strcpy(dirname, mail->box);
79 /* checking the cur subdirectory */
80 strcat(dirname, "cur");
82 dir = opendir(dirname);
84 ERR("cannot open directory");
88 dirent = readdir(dir);
90 /* . and .. are skipped */
91 if (dirent->d_name[0] != '.') {
94 dirent = readdir(dir);
98 dirname[strlen(dirname) - 3] = '\0';
99 strcat(dirname, "new");
101 dir = opendir(dirname);
103 ERR("cannot open directory");
107 dirent = readdir(dir);
109 /* . and .. are skipped */
110 if (dirent->d_name[0] != '.') {
111 mail->new_mail_count++;
114 dirent = readdir(dir);
123 if (st.st_mtime != mail->last_mtime) {
124 /* yippee, modification time has changed, let's read mail count! */
127 int reading_status = 0;
129 /* could lock here but I don't think it's really worth it because
130 * this isn't going to write mail spool */
132 mail->new_mail_count = mail->mail_count = 0;
134 fp = open_file(mail->box, &rep);
139 /* NOTE: adds mail as new if there isn't Status-field at all */
144 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) != 0) {
153 if (reading_status) {
154 mail->new_mail_count++;
161 && strncmp(buf, "X-Mozilla-Status:", 17) == 0) {
162 /* check that mail isn't already read */
163 if (strchr(buf + 21, '0')) {
164 mail->new_mail_count++;
170 if (reading_status && strncmp(buf, "Status:", 7) == 0) {
171 /* check that mail isn't already read */
172 if (strchr(buf + 7, 'R') == NULL) {
173 mail->new_mail_count++;
182 while (strchr(buf, '\n') == NULL && !feof(fp)) {
189 if (reading_status) {
190 mail->new_mail_count++;
193 mail->last_mtime = st.st_mtime;