Bug Summary

File:erver/mail.c
Location:line 171, column 3
Description:Value stored to 'tok' is never read

Annotated Source Code

1/* GKrellM
2| Copyright (C) 1999-2010 Bill Wilson
3|
4| Author: Bill Wilson billw@gkrellm.net
5| Latest versions might be found at: http://gkrellm.net
6|
7|
8| GKrellM is free software: you can redistribute it and/or modify it
9| under the terms of the GNU General Public License as published by
10| the Free Software Foundation, either version 3 of the License, or
11| (at your option) any later version.
12|
13| GKrellM is distributed in the hope that it will be useful, but WITHOUT
14| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15| or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16| License for more details.
17|
18| You should have received a copy of the GNU General Public License
19| along with this program. If not, see http://www.gnu.org/licenses/
20|
21|
22| Additional permission under GNU GPL version 3 section 7
23|
24| If you modify this program, or any covered work, by linking or
25| combining it with the OpenSSL project's OpenSSL library (or a
26| modified version of that library), containing parts covered by
27| the terms of the OpenSSL or SSLeay licenses, you are granted
28| additional permission to convey the resulting work.
29| Corresponding Source for a non-source form of such a combination
30| shall include the source code for the parts of OpenSSL used as well
31| as that of the covered work.
32*/
33
34#include "gkrellmd.h"
35#include "gkrellmd-private.h"
36
37
38#if !defined(WIN32)
39
40#define MBOX_MBOX0 0
41#define MBOX_MAILDIR1 1
42#define MBOX_MH_DIR2 2
43
44
45typedef struct
46 {
47 gchar *path;
48 gchar *homedir_path;
49 gint mboxtype;
50 gboolean (*check_func)();
51 gint mail_count;
52 gint new_mail_count;
53 gint old_mail_count;
54 gint prev_mail_count,
55 prev_new_mail_count;
56 time_t last_mtime;
57 off_t last_size;
58 gboolean is_internal; /* Internal mail message (ie: localmachine) */
59 gboolean changed;
60 }
61 Mailbox;
62
63static GList *mailbox_list;
64
65static gint mail_check_timeout = 5; /* Seconds */
66
67static gboolean unseen_is_new = TRUE(!(0)); /* Accessed but unread */
68
69static gboolean mail_need_serve;
70
71
72 /* Look at a From line to see if it is valid, lines look like:
73 | From sending_address dayofweek month dayofmonth timeofday year
74 | eg: From billw@gkrellm.net Fri Oct 22 13:52:49 2010
75 */
76static gint
77is_From_line(Mailbox *mbox, gchar *buf)
78 {
79 gchar sender[512];
80 gint dayofmonth = 0;
81
82 if (strncmp(buf, "From ", 5)(__extension__ (__builtin_constant_p (5) && ((__builtin_constant_p
(buf) && strlen (buf) < ((size_t) (5))) || (__builtin_constant_p
("From ") && strlen ("From ") < ((size_t) (5)))) ?
__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(buf) && __builtin_constant_p ("From ") && (
__s1_len = strlen (buf), __s2_len = strlen ("From "), (!((size_t
)(const void *)((buf) + 1) - (size_t)(const void *)(buf) == 1
) || __s1_len >= 4) && (!((size_t)(const void *)((
"From ") + 1) - (size_t)(const void *)("From ") == 1) || __s2_len
>= 4)) ? __builtin_strcmp (buf, "From ") : (__builtin_constant_p
(buf) && ((size_t)(const void *)((buf) + 1) - (size_t
)(const void *)(buf) == 1) && (__s1_len = strlen (buf
), __s1_len < 4) ? (__builtin_constant_p ("From ") &&
((size_t)(const void *)(("From ") + 1) - (size_t)(const void
*)("From ") == 1) ? __builtin_strcmp (buf, "From ") : (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) ("From "); int __result = (((const unsigned char *) (
const char *) (buf))[0] - __s2[0]); if (__s1_len > 0 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (buf))[1] - __s2[1]); if (__s1_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (buf))[2] - __s2[2]); if (__s1_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) (buf))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p
("From ") && ((size_t)(const void *)(("From ") + 1) -
(size_t)(const void *)("From ") == 1) && (__s2_len =
strlen ("From "), __s2_len < 4) ? (__builtin_constant_p (
buf) && ((size_t)(const void *)((buf) + 1) - (size_t)
(const void *)(buf) == 1) ? __builtin_strcmp (buf, "From ") :
(- (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) (buf); int __result = (((const unsigned
char *) (const char *) ("From "))[0] - __s2[0]); if (__s2_len
> 0 && __result == 0) { __result = (((const unsigned
char *) (const char *) ("From "))[1] - __s2[1]); if (__s2_len
> 1 && __result == 0) { __result = (((const unsigned
char *) (const char *) ("From "))[2] - __s2[2]); if (__s2_len
> 2 && __result == 0) __result = (((const unsigned
char *) (const char *) ("From "))[3] - __s2[3]); } } __result
; })))) : __builtin_strcmp (buf, "From ")))); }) : strncmp (buf
, "From ", 5)))
)
83 return FALSE(0);
84
85 /* In case sending address missing, look for a day of month
86 | number in field 3 or 4 (0 based).
87 */
88 sender[0] = '\0';
89 if (sscanf(buf, "%*s %*s %*s %d", &dayofmonth) != 1)
90 {
91 if (sscanf(buf, "%*s %511s %*s %*s %d", sender, &dayofmonth) != 2)
92 return FALSE(0);
93 }
94 if (dayofmonth < 1 || dayofmonth > 31)
95 return FALSE(0);
96 if (strcmp(sender, "MAILER-DAEMON")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(sender) && __builtin_constant_p ("MAILER-DAEMON") &&
(__s1_len = strlen (sender), __s2_len = strlen ("MAILER-DAEMON"
), (!((size_t)(const void *)((sender) + 1) - (size_t)(const void
*)(sender) == 1) || __s1_len >= 4) && (!((size_t)
(const void *)(("MAILER-DAEMON") + 1) - (size_t)(const void *
)("MAILER-DAEMON") == 1) || __s2_len >= 4)) ? __builtin_strcmp
(sender, "MAILER-DAEMON") : (__builtin_constant_p (sender) &&
((size_t)(const void *)((sender) + 1) - (size_t)(const void *
)(sender) == 1) && (__s1_len = strlen (sender), __s1_len
< 4) ? (__builtin_constant_p ("MAILER-DAEMON") &&
((size_t)(const void *)(("MAILER-DAEMON") + 1) - (size_t)(const
void *)("MAILER-DAEMON") == 1) ? __builtin_strcmp (sender, "MAILER-DAEMON"
) : (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) ("MAILER-DAEMON"); int __result = (((
const unsigned char *) (const char *) (sender))[0] - __s2[0])
; if (__s1_len > 0 && __result == 0) { __result = (
((const unsigned char *) (const char *) (sender))[1] - __s2[1
]); if (__s1_len > 1 && __result == 0) { __result =
(((const unsigned char *) (const char *) (sender))[2] - __s2
[2]); if (__s1_len > 2 && __result == 0) __result =
(((const unsigned char *) (const char *) (sender))[3] - __s2
[3]); } } __result; }))) : (__builtin_constant_p ("MAILER-DAEMON"
) && ((size_t)(const void *)(("MAILER-DAEMON") + 1) -
(size_t)(const void *)("MAILER-DAEMON") == 1) && (__s2_len
= strlen ("MAILER-DAEMON"), __s2_len < 4) ? (__builtin_constant_p
(sender) && ((size_t)(const void *)((sender) + 1) - (
size_t)(const void *)(sender) == 1) ? __builtin_strcmp (sender
, "MAILER-DAEMON") : (- (__extension__ ({ const unsigned char
*__s2 = (const unsigned char *) (const char *) (sender); int
__result = (((const unsigned char *) (const char *) ("MAILER-DAEMON"
))[0] - __s2[0]); if (__s2_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) ("MAILER-DAEMON"
))[1] - __s2[1]); if (__s2_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) ("MAILER-DAEMON"
))[2] - __s2[2]); if (__s2_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) ("MAILER-DAEMON"
))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (sender
, "MAILER-DAEMON")))); })
== 0)
97 mbox->is_internal = TRUE(!(0));
98 return TRUE(!(0));
99 }
100
101
102 /* Check if this is a Content-Type-line. If it contains a boundary
103 | field, copy boundary string to buffer (including two leading and
104 | trailing dashes marking the end of a multipart mail) and return
105 | true. Otherwise, return false.
106 */
107static gint
108is_multipart_mail(gchar *buf, gchar *separator)
109 {
110 gchar *fieldstart;
111 gchar *sepstart;
112 gint seplen;
113
114 if (strncmp(buf, "Content-Type: ", 14)(__extension__ (__builtin_constant_p (14) && ((__builtin_constant_p
(buf) && strlen (buf) < ((size_t) (14))) || (__builtin_constant_p
("Content-Type: ") && strlen ("Content-Type: ") <
((size_t) (14)))) ? __extension__ ({ size_t __s1_len, __s2_len
; (__builtin_constant_p (buf) && __builtin_constant_p
("Content-Type: ") && (__s1_len = strlen (buf), __s2_len
= strlen ("Content-Type: "), (!((size_t)(const void *)((buf)
+ 1) - (size_t)(const void *)(buf) == 1) || __s1_len >= 4
) && (!((size_t)(const void *)(("Content-Type: ") + 1
) - (size_t)(const void *)("Content-Type: ") == 1) || __s2_len
>= 4)) ? __builtin_strcmp (buf, "Content-Type: ") : (__builtin_constant_p
(buf) && ((size_t)(const void *)((buf) + 1) - (size_t
)(const void *)(buf) == 1) && (__s1_len = strlen (buf
), __s1_len < 4) ? (__builtin_constant_p ("Content-Type: "
) && ((size_t)(const void *)(("Content-Type: ") + 1) -
(size_t)(const void *)("Content-Type: ") == 1) ? __builtin_strcmp
(buf, "Content-Type: ") : (__extension__ ({ const unsigned char
*__s2 = (const unsigned char *) (const char *) ("Content-Type: "
); int __result = (((const unsigned char *) (const char *) (buf
))[0] - __s2[0]); if (__s1_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) (buf)
)[1] - __s2[1]); if (__s1_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (buf)
)[2] - __s2[2]); if (__s1_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) (buf))[
3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("Content-Type: "
) && ((size_t)(const void *)(("Content-Type: ") + 1) -
(size_t)(const void *)("Content-Type: ") == 1) && (__s2_len
= strlen ("Content-Type: "), __s2_len < 4) ? (__builtin_constant_p
(buf) && ((size_t)(const void *)((buf) + 1) - (size_t
)(const void *)(buf) == 1) ? __builtin_strcmp (buf, "Content-Type: "
) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) (buf); int __result = (((const unsigned
char *) (const char *) ("Content-Type: "))[0] - __s2[0]); if
(__s2_len > 0 && __result == 0) { __result = (((const
unsigned char *) (const char *) ("Content-Type: "))[1] - __s2
[1]); if (__s2_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) ("Content-Type: "
))[2] - __s2[2]); if (__s2_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) ("Content-Type: "
))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (buf
, "Content-Type: ")))); }) : strncmp (buf, "Content-Type: ", 14
)))
!= 0)
115 return FALSE(0);
116 if (strncmp(&buf[14], "multipart/", 10)(__extension__ (__builtin_constant_p (10) && ((__builtin_constant_p
(&buf[14]) && strlen (&buf[14]) < ((size_t
) (10))) || (__builtin_constant_p ("multipart/") && strlen
("multipart/") < ((size_t) (10)))) ? __extension__ ({ size_t
__s1_len, __s2_len; (__builtin_constant_p (&buf[14]) &&
__builtin_constant_p ("multipart/") && (__s1_len = strlen
(&buf[14]), __s2_len = strlen ("multipart/"), (!((size_t
)(const void *)((&buf[14]) + 1) - (size_t)(const void *)(
&buf[14]) == 1) || __s1_len >= 4) && (!((size_t
)(const void *)(("multipart/") + 1) - (size_t)(const void *)(
"multipart/") == 1) || __s2_len >= 4)) ? __builtin_strcmp (
&buf[14], "multipart/") : (__builtin_constant_p (&buf
[14]) && ((size_t)(const void *)((&buf[14]) + 1) -
(size_t)(const void *)(&buf[14]) == 1) && (__s1_len
= strlen (&buf[14]), __s1_len < 4) ? (__builtin_constant_p
("multipart/") && ((size_t)(const void *)(("multipart/"
) + 1) - (size_t)(const void *)("multipart/") == 1) ? __builtin_strcmp
(&buf[14], "multipart/") : (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) ("multipart/"
); int __result = (((const unsigned char *) (const char *) (&
buf[14]))[0] - __s2[0]); if (__s1_len > 0 && __result
== 0) { __result = (((const unsigned char *) (const char *) (
&buf[14]))[1] - __s2[1]); if (__s1_len > 1 && __result
== 0) { __result = (((const unsigned char *) (const char *) (
&buf[14]))[2] - __s2[2]); if (__s1_len > 2 && __result
== 0) __result = (((const unsigned char *) (const char *) (&
buf[14]))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p
("multipart/") && ((size_t)(const void *)(("multipart/"
) + 1) - (size_t)(const void *)("multipart/") == 1) &&
(__s2_len = strlen ("multipart/"), __s2_len < 4) ? (__builtin_constant_p
(&buf[14]) && ((size_t)(const void *)((&buf[
14]) + 1) - (size_t)(const void *)(&buf[14]) == 1) ? __builtin_strcmp
(&buf[14], "multipart/") : (- (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) (&buf
[14]); int __result = (((const unsigned char *) (const char *
) ("multipart/"))[0] - __s2[0]); if (__s2_len > 0 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ("multipart/"))[1] - __s2[1]); if (__s2_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ("multipart/"))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) ("multipart/"))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp
(&buf[14], "multipart/")))); }) : strncmp (&buf[14],
"multipart/", 10)))
!= 0)
117 return FALSE(0);
118 fieldstart = &buf[14];
119 while (*fieldstart!=0)
120 {
121 while (*fieldstart!=0 && *fieldstart!=';')
122 fieldstart++;
123 if (*fieldstart==';') fieldstart++;
124 while (*fieldstart!=0 && *fieldstart==' ')
125 fieldstart++;
126 if (strncmp(fieldstart, "boundary=", 9)(__extension__ (__builtin_constant_p (9) && ((__builtin_constant_p
(fieldstart) && strlen (fieldstart) < ((size_t) (
9))) || (__builtin_constant_p ("boundary=") && strlen
("boundary=") < ((size_t) (9)))) ? __extension__ ({ size_t
__s1_len, __s2_len; (__builtin_constant_p (fieldstart) &&
__builtin_constant_p ("boundary=") && (__s1_len = strlen
(fieldstart), __s2_len = strlen ("boundary="), (!((size_t)(const
void *)((fieldstart) + 1) - (size_t)(const void *)(fieldstart
) == 1) || __s1_len >= 4) && (!((size_t)(const void
*)(("boundary=") + 1) - (size_t)(const void *)("boundary=") ==
1) || __s2_len >= 4)) ? __builtin_strcmp (fieldstart, "boundary="
) : (__builtin_constant_p (fieldstart) && ((size_t)(const
void *)((fieldstart) + 1) - (size_t)(const void *)(fieldstart
) == 1) && (__s1_len = strlen (fieldstart), __s1_len <
4) ? (__builtin_constant_p ("boundary=") && ((size_t
)(const void *)(("boundary=") + 1) - (size_t)(const void *)("boundary="
) == 1) ? __builtin_strcmp (fieldstart, "boundary=") : (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) ("boundary="); int __result = (((const unsigned char
*) (const char *) (fieldstart))[0] - __s2[0]); if (__s1_len >
0 && __result == 0) { __result = (((const unsigned char
*) (const char *) (fieldstart))[1] - __s2[1]); if (__s1_len >
1 && __result == 0) { __result = (((const unsigned char
*) (const char *) (fieldstart))[2] - __s2[2]); if (__s1_len >
2 && __result == 0) __result = (((const unsigned char
*) (const char *) (fieldstart))[3] - __s2[3]); } } __result;
}))) : (__builtin_constant_p ("boundary=") && ((size_t
)(const void *)(("boundary=") + 1) - (size_t)(const void *)("boundary="
) == 1) && (__s2_len = strlen ("boundary="), __s2_len
< 4) ? (__builtin_constant_p (fieldstart) && ((size_t
)(const void *)((fieldstart) + 1) - (size_t)(const void *)(fieldstart
) == 1) ? __builtin_strcmp (fieldstart, "boundary=") : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (fieldstart); int __result = (((const unsigned char *
) (const char *) ("boundary="))[0] - __s2[0]); if (__s2_len >
0 && __result == 0) { __result = (((const unsigned char
*) (const char *) ("boundary="))[1] - __s2[1]); if (__s2_len
> 1 && __result == 0) { __result = (((const unsigned
char *) (const char *) ("boundary="))[2] - __s2[2]); if (__s2_len
> 2 && __result == 0) __result = (((const unsigned
char *) (const char *) ("boundary="))[3] - __s2[3]); } } __result
; })))) : __builtin_strcmp (fieldstart, "boundary=")))); }) :
strncmp (fieldstart, "boundary=", 9)))
== 0)
127 {
128 sepstart = fieldstart + 9;
129 if (sepstart[0]=='"')
130 {
131 sepstart++;
132 seplen = 0;
133 while (sepstart[seplen]!='"' && sepstart[seplen]>=32)
134 seplen++;
135 }
136 else
137 {
138 seplen = 0;
139 while (sepstart[seplen]!=';' && sepstart[seplen]>32)
140 seplen++;
141 }
142 strcpy(separator,"--");
143 strncpy(&separator[2],sepstart,seplen)__builtin_strncpy (&separator[2], sepstart, seplen);
144 strcpy(&separator[seplen+2],"--");
145 return TRUE(!(0));
146 }
147 }
148 return FALSE(0);
149 }
150
151static gboolean
152mh_sequences_new_count(Mailbox *mbox)
153 {
154 FILE *f;
155 gchar buf[1024];
156 gchar *path, *tok;
157 gint n0, n1;
158
159 path = g_strconcat(mbox->path, G_DIR_SEPARATOR_S"/",
160 ".mh_sequences", NULL((void*)0));
161 f = fopen(path, "r");
162 g_free(path);
163 if (!f)
164 return FALSE(0);
165 while (fgets(buf, sizeof(buf), f))
166 {
167 /* Look for unseen sequence like "unseen: 4 7-9 23"
168 */
169 if (strncmp(buf, "unseen:", 7)(__extension__ (__builtin_constant_p (7) && ((__builtin_constant_p
(buf) && strlen (buf) < ((size_t) (7))) || (__builtin_constant_p
("unseen:") && strlen ("unseen:") < ((size_t) (7)
))) ? __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(buf) && __builtin_constant_p ("unseen:") &&
(__s1_len = strlen (buf), __s2_len = strlen ("unseen:"), (!(
(size_t)(const void *)((buf) + 1) - (size_t)(const void *)(buf
) == 1) || __s1_len >= 4) && (!((size_t)(const void
*)(("unseen:") + 1) - (size_t)(const void *)("unseen:") == 1
) || __s2_len >= 4)) ? __builtin_strcmp (buf, "unseen:") :
(__builtin_constant_p (buf) && ((size_t)(const void *
)((buf) + 1) - (size_t)(const void *)(buf) == 1) && (
__s1_len = strlen (buf), __s1_len < 4) ? (__builtin_constant_p
("unseen:") && ((size_t)(const void *)(("unseen:") +
1) - (size_t)(const void *)("unseen:") == 1) ? __builtin_strcmp
(buf, "unseen:") : (__extension__ ({ const unsigned char *__s2
= (const unsigned char *) (const char *) ("unseen:"); int __result
= (((const unsigned char *) (const char *) (buf))[0] - __s2[
0]); if (__s1_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) (buf))[1] - __s2[
1]); if (__s1_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) (buf))[2] - __s2[
2]); if (__s1_len > 2 && __result == 0) __result =
(((const unsigned char *) (const char *) (buf))[3] - __s2[3]
); } } __result; }))) : (__builtin_constant_p ("unseen:") &&
((size_t)(const void *)(("unseen:") + 1) - (size_t)(const void
*)("unseen:") == 1) && (__s2_len = strlen ("unseen:"
), __s2_len < 4) ? (__builtin_constant_p (buf) && (
(size_t)(const void *)((buf) + 1) - (size_t)(const void *)(buf
) == 1) ? __builtin_strcmp (buf, "unseen:") : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (buf); int __result = (((const unsigned char *) (const
char *) ("unseen:"))[0] - __s2[0]); if (__s2_len > 0 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ("unseen:"))[1] - __s2[1]); if (__s2_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ("unseen:"))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) ("unseen:"))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp
(buf, "unseen:")))); }) : strncmp (buf, "unseen:", 7)))
)
170 continue;
171 tok = strtok(buf, " \t\n");
Value stored to 'tok' is never read
172 while ((tok = strtok(NULL((void*)0), " \t\n")) != NULL((void*)0))
173 {
174 if (sscanf(tok, "%d-%d", &n0, &n1) == 2)
175 mbox->new_mail_count += n1 - n0 + 1;
176 else
177 mbox->new_mail_count++;
178 }
179 break;
180 }
181 fclose(f);
182 return TRUE(!(0));
183 }
184
185 /* Sylpheed procmsg.h enums MSG_NEW as (1 << 0) and MSG_UNREAD as (1 << 1)
186 | And procmsg_write_flags() in Sylpheeds procmsg.c writes a mail record as
187 | a pair of ints with msgnum first followed by flags.
188 */
189#define SYLPHEED_MSG_NEW1 1
190#define SYLPHEED_MSG_UNREAD2 2
191#define SYLPHEED_MARK_VERSION2 2
192
193static gboolean
194sylpheed_mark_new_count(Mailbox *mbox)
195 {
196 FILE *f;
197 gchar *path;
198 gint msgnum, flags, ver, mark_files = 0;
199
200 path = g_strconcat(mbox->path, G_DIR_SEPARATOR_S"/",
201 ".sylpheed_mark", NULL((void*)0));
202 f = fopen(path, "rb");
203 g_free(path);
204 if (!f)
205 return FALSE(0);
206
207 if ( fread(&ver, sizeof(ver), 1, f) == 1
208 && SYLPHEED_MARK_VERSION2 == ver
209 )
210 {
211 while ( fread(&msgnum, sizeof(msgnum), 1, f) == 1
212 && fread(&flags, sizeof(flags), 1, f) == 1
213 )
214 {
215 if ( (flags & SYLPHEED_MSG_NEW1)
216 || ((flags & SYLPHEED_MSG_UNREAD2) && unseen_is_new)
217 )
218 mbox->new_mail_count += 1;
219 ++mark_files;
220 }
221 if (mark_files < mbox->mail_count)
222 mbox->new_mail_count += mbox->mail_count - mark_files;
223 }
224 fclose(f);
225 return TRUE(!(0));
226 }
227
228
229 /* Check a mh directory for mail. The way that messages are marked as new
230 | depends on the MUA being using. Only .mh_sequences and .sylpheed_mark
231 | are currently checked, otherwise all mail found is considered new mail.
232 */
233static gboolean
234check_mh_dir(Mailbox *mbox)
235 {
236 GDir *dir;
237 gchar *name;
238
239 mbox->mail_count = mbox->new_mail_count = 0;
240
241 if ((dir = g_dir_open(mbox->path, 0, NULL((void*)0))) == NULL((void*)0))
242 return FALSE(0);
243 while ((name = (gchar *) g_dir_read_name(dir)) != NULL((void*)0))
244 {
245 /* Files starting with a digit are messages. */
246 if (isdigit((unsigned char)name[0])((*__ctype_b_loc ())[(int) (((unsigned char)name[0]))] & (
unsigned short int) _ISdigit)
)
247 mbox->mail_count++;
248 }
249 g_dir_close(dir);
250
251 /* Some MH dir clients use .mh_sequences, others such as mutt or gnus
252 | do not. For mixed cases, it's a user option to ignore .mh_sequences.
253 | Sylpheed uses .sylpheed_mark.
254 */
255 if ( !mh_sequences_new_count(mbox)
256 && !sylpheed_mark_new_count(mbox)
257 )
258 mbox->new_mail_count = mbox->mail_count;
259
260 return TRUE(!(0));
261 }
262
263
264 /* A maildir has new, cur, and tmp subdirectories. Any file in new
265 | or cur that does not begin with a '.' is a mail message. It is
266 | suggested that messages begin with the output of time() (9 digits)
267 | but while mutt and qmail use this standard, procmail does not.
268 | maildir(5) says:
269 | It is a good idea for readers to skip all filenames in
270 | new and cur starting with a dot. Other than this,
271 | readers should not attempt to parse filenames.
272 | So check_maildir() simply looks for files in new and cur.
273 | But if unseen_is_new flag is set, look for ":2,*S" file suffix where
274 | the 'S' indicates the mail is seen.
275 | See http://cr.yp.to/proto/maildir.html
276 */
277static gboolean
278check_maildir(Mailbox *mbox)
279 {
280 gchar path[256], *s;
281 gchar *name;
282 GDir *dir;
283
284 mbox->new_mail_count = 0;
285 snprintf(path, sizeof(path), "%s%cnew", mbox->path,
286 G_DIR_SEPARATOR'/');
287 if ((dir = g_dir_open(path, 0, NULL((void*)0))) != NULL((void*)0))
288 {
289 while ((name = (gchar *) g_dir_read_name(dir)) != NULL((void*)0))
290 mbox->new_mail_count++;
291 g_dir_close(dir);
292 }
293 mbox->mail_count = mbox->new_mail_count;
294 snprintf(path, sizeof(path), "%s%ccur", mbox->path,
295 G_DIR_SEPARATOR'/');
296 if ((dir = g_dir_open(path, 0, NULL((void*)0))) != NULL((void*)0))
297 {
298 while ((name = (gchar *) g_dir_read_name(dir)) != NULL((void*)0))
299 {
300 mbox->mail_count++;
301 if ( unseen_is_new
302 && ( (s = strchr(name, ':')(__extension__ (__builtin_constant_p (':') && !__builtin_constant_p
(name) && (':') == '\0' ? (char *) __rawmemchr (name
, ':') : __builtin_strchr (name, ':')))
) == NULL((void*)0)
303 || !strchr(s, 'S')(__extension__ (__builtin_constant_p ('S') && !__builtin_constant_p
(s) && ('S') == '\0' ? (char *) __rawmemchr (s, 'S')
: __builtin_strchr (s, 'S')))
304 )
305 )
306 mbox->new_mail_count++;
307 }
308 g_dir_close(dir);
309 }
310
311 if (_GK.debug_level & DEBUG_MAIL0x10)
312 g_print(_("mdir %s total=%d old=%d new=%d\n")dcgettext ("gkrellmd", "mdir %s total=%d old=%d new=%d\n", 5), mbox->path,
313 mbox->mail_count, mbox->old_mail_count, mbox->new_mail_count);
314 return TRUE(!(0));
315 }
316
317
318 /* Count total mail and old mail in a mailbox. Old mail can be read
319 | with a Status: R0, or can be accessed and not read with Status: O
320 | So, new mail will be the diff - note that unread mail is not
321 | necessarily new mail. According to stat() man page:
322 | st_atime is changed by mknod(), utime(), read(), write(), truncate()
323 | st_mtime is changed by mknod(), utime(), write()
324 | But, new mail arriving (writing mailbox) sets st_mtime while reading
325 | the mailbox (mail program reading) sets st_atime. So the test
326 | st_atime > st_mtime is testing if mbox has been read since last new mail.
327 | Mail readers may restore st_mtime after writting status.
328 | And Netscape mail does status with X-Mozilla-Status: xxxS
329 | where S is bitwise or of status flags:
330 | 1: read 2: replied 4: marked 8: deleted
331 |
332 | Evolution uses status with X-Evolution: 00000000-xxxx where xxxx status is
333 | a bitfield in hexadecimal (see enum _CamelMessageFlags in evolution/camel
334 | source) and most importantly CAMEL_MESSAGE_SEEN = 1<<4.
335 */
336 /* test if buf is a status for standard mail, mozilla or evolution
337 */
338static gboolean
339is_status(gchar *buf)
340 {
341 if (buf[0] != 'S' && buf[0] != 'X')
342 return FALSE(0);
343
344 if ( !strncmp(buf, "Status:", 7)(__extension__ (__builtin_constant_p (7) && ((__builtin_constant_p
(buf) && strlen (buf) < ((size_t) (7))) || (__builtin_constant_p
("Status:") && strlen ("Status:") < ((size_t) (7)
))) ? __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(buf) && __builtin_constant_p ("Status:") &&
(__s1_len = strlen (buf), __s2_len = strlen ("Status:"), (!(
(size_t)(const void *)((buf) + 1) - (size_t)(const void *)(buf
) == 1) || __s1_len >= 4) && (!((size_t)(const void
*)(("Status:") + 1) - (size_t)(const void *)("Status:") == 1
) || __s2_len >= 4)) ? __builtin_strcmp (buf, "Status:") :
(__builtin_constant_p (buf) && ((size_t)(const void *
)((buf) + 1) - (size_t)(const void *)(buf) == 1) && (
__s1_len = strlen (buf), __s1_len < 4) ? (__builtin_constant_p
("Status:") && ((size_t)(const void *)(("Status:") +
1) - (size_t)(const void *)("Status:") == 1) ? __builtin_strcmp
(buf, "Status:") : (__extension__ ({ const unsigned char *__s2
= (const unsigned char *) (const char *) ("Status:"); int __result
= (((const unsigned char *) (const char *) (buf))[0] - __s2[
0]); if (__s1_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) (buf))[1] - __s2[
1]); if (__s1_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) (buf))[2] - __s2[
2]); if (__s1_len > 2 && __result == 0) __result =
(((const unsigned char *) (const char *) (buf))[3] - __s2[3]
); } } __result; }))) : (__builtin_constant_p ("Status:") &&
((size_t)(const void *)(("Status:") + 1) - (size_t)(const void
*)("Status:") == 1) && (__s2_len = strlen ("Status:"
), __s2_len < 4) ? (__builtin_constant_p (buf) && (
(size_t)(const void *)((buf) + 1) - (size_t)(const void *)(buf
) == 1) ? __builtin_strcmp (buf, "Status:") : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (buf); int __result = (((const unsigned char *) (const
char *) ("Status:"))[0] - __s2[0]); if (__s2_len > 0 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ("Status:"))[1] - __s2[1]); if (__s2_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ("Status:"))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) ("Status:"))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp
(buf, "Status:")))); }) : strncmp (buf, "Status:", 7)))
/* Standard mail clients */
345 || !strncmp(buf, "X-Mozilla-Status:", 17)(__extension__ (__builtin_constant_p (17) && ((__builtin_constant_p
(buf) && strlen (buf) < ((size_t) (17))) || (__builtin_constant_p
("X-Mozilla-Status:") && strlen ("X-Mozilla-Status:"
) < ((size_t) (17)))) ? __extension__ ({ size_t __s1_len, __s2_len
; (__builtin_constant_p (buf) && __builtin_constant_p
("X-Mozilla-Status:") && (__s1_len = strlen (buf), __s2_len
= strlen ("X-Mozilla-Status:"), (!((size_t)(const void *)((buf
) + 1) - (size_t)(const void *)(buf) == 1) || __s1_len >= 4
) && (!((size_t)(const void *)(("X-Mozilla-Status:") +
1) - (size_t)(const void *)("X-Mozilla-Status:") == 1) || __s2_len
>= 4)) ? __builtin_strcmp (buf, "X-Mozilla-Status:") : (__builtin_constant_p
(buf) && ((size_t)(const void *)((buf) + 1) - (size_t
)(const void *)(buf) == 1) && (__s1_len = strlen (buf
), __s1_len < 4) ? (__builtin_constant_p ("X-Mozilla-Status:"
) && ((size_t)(const void *)(("X-Mozilla-Status:") + 1
) - (size_t)(const void *)("X-Mozilla-Status:") == 1) ? __builtin_strcmp
(buf, "X-Mozilla-Status:") : (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) ("X-Mozilla-Status:"
); int __result = (((const unsigned char *) (const char *) (buf
))[0] - __s2[0]); if (__s1_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) (buf)
)[1] - __s2[1]); if (__s1_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (buf)
)[2] - __s2[2]); if (__s1_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) (buf))[
3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("X-Mozilla-Status:"
) && ((size_t)(const void *)(("X-Mozilla-Status:") + 1
) - (size_t)(const void *)("X-Mozilla-Status:") == 1) &&
(__s2_len = strlen ("X-Mozilla-Status:"), __s2_len < 4) ?
(__builtin_constant_p (buf) && ((size_t)(const void *
)((buf) + 1) - (size_t)(const void *)(buf) == 1) ? __builtin_strcmp
(buf, "X-Mozilla-Status:") : (- (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) (buf); int
__result = (((const unsigned char *) (const char *) ("X-Mozilla-Status:"
))[0] - __s2[0]); if (__s2_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) ("X-Mozilla-Status:"
))[1] - __s2[1]); if (__s2_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) ("X-Mozilla-Status:"
))[2] - __s2[2]); if (__s2_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) ("X-Mozilla-Status:"
))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (buf
, "X-Mozilla-Status:")))); }) : strncmp (buf, "X-Mozilla-Status:"
, 17)))
/* Netscape */
346 || !strncmp(buf, "X-Evolution:", 12)(__extension__ (__builtin_constant_p (12) && ((__builtin_constant_p
(buf) && strlen (buf) < ((size_t) (12))) || (__builtin_constant_p
("X-Evolution:") && strlen ("X-Evolution:") < ((size_t
) (12)))) ? __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(buf) && __builtin_constant_p ("X-Evolution:") &&
(__s1_len = strlen (buf), __s2_len = strlen ("X-Evolution:")
, (!((size_t)(const void *)((buf) + 1) - (size_t)(const void *
)(buf) == 1) || __s1_len >= 4) && (!((size_t)(const
void *)(("X-Evolution:") + 1) - (size_t)(const void *)("X-Evolution:"
) == 1) || __s2_len >= 4)) ? __builtin_strcmp (buf, "X-Evolution:"
) : (__builtin_constant_p (buf) && ((size_t)(const void
*)((buf) + 1) - (size_t)(const void *)(buf) == 1) &&
(__s1_len = strlen (buf), __s1_len < 4) ? (__builtin_constant_p
("X-Evolution:") && ((size_t)(const void *)(("X-Evolution:"
) + 1) - (size_t)(const void *)("X-Evolution:") == 1) ? __builtin_strcmp
(buf, "X-Evolution:") : (__extension__ ({ const unsigned char
*__s2 = (const unsigned char *) (const char *) ("X-Evolution:"
); int __result = (((const unsigned char *) (const char *) (buf
))[0] - __s2[0]); if (__s1_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) (buf)
)[1] - __s2[1]); if (__s1_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (buf)
)[2] - __s2[2]); if (__s1_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) (buf))[
3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("X-Evolution:"
) && ((size_t)(const void *)(("X-Evolution:") + 1) - (
size_t)(const void *)("X-Evolution:") == 1) && (__s2_len
= strlen ("X-Evolution:"), __s2_len < 4) ? (__builtin_constant_p
(buf) && ((size_t)(const void *)((buf) + 1) - (size_t
)(const void *)(buf) == 1) ? __builtin_strcmp (buf, "X-Evolution:"
) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) (buf); int __result = (((const unsigned
char *) (const char *) ("X-Evolution:"))[0] - __s2[0]); if (
__s2_len > 0 && __result == 0) { __result = (((const
unsigned char *) (const char *) ("X-Evolution:"))[1] - __s2[
1]); if (__s2_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) ("X-Evolution:"))
[2] - __s2[2]); if (__s2_len > 2 && __result == 0)
__result = (((const unsigned char *) (const char *) ("X-Evolution:"
))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (buf
, "X-Evolution:")))); }) : strncmp (buf, "X-Evolution:", 12))
)
/* Mozilla */
347 )
348 return TRUE(!(0));
349 else
350 return FALSE(0);
351 }
352
353static gboolean
354status_is_old(gchar *buf)
355 {
356 gchar c;
357 int tmp;
358
359 /* Standard mail clients
360 */
361 if ( !strncmp(buf, "Status:", 7)(__extension__ (__builtin_constant_p (7) && ((__builtin_constant_p
(buf) && strlen (buf) < ((size_t) (7))) || (__builtin_constant_p
("Status:") && strlen ("Status:") < ((size_t) (7)
))) ? __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(buf) && __builtin_constant_p ("Status:") &&
(__s1_len = strlen (buf), __s2_len = strlen ("Status:"), (!(
(size_t)(const void *)((buf) + 1) - (size_t)(const void *)(buf
) == 1) || __s1_len >= 4) && (!((size_t)(const void
*)(("Status:") + 1) - (size_t)(const void *)("Status:") == 1
) || __s2_len >= 4)) ? __builtin_strcmp (buf, "Status:") :
(__builtin_constant_p (buf) && ((size_t)(const void *
)((buf) + 1) - (size_t)(const void *)(buf) == 1) && (
__s1_len = strlen (buf), __s1_len < 4) ? (__builtin_constant_p
("Status:") && ((size_t)(const void *)(("Status:") +
1) - (size_t)(const void *)("Status:") == 1) ? __builtin_strcmp
(buf, "Status:") : (__extension__ ({ const unsigned char *__s2
= (const unsigned char *) (const char *) ("Status:"); int __result
= (((const unsigned char *) (const char *) (buf))[0] - __s2[
0]); if (__s1_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) (buf))[1] - __s2[
1]); if (__s1_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) (buf))[2] - __s2[
2]); if (__s1_len > 2 && __result == 0) __result =
(((const unsigned char *) (const char *) (buf))[3] - __s2[3]
); } } __result; }))) : (__builtin_constant_p ("Status:") &&
((size_t)(const void *)(("Status:") + 1) - (size_t)(const void
*)("Status:") == 1) && (__s2_len = strlen ("Status:"
), __s2_len < 4) ? (__builtin_constant_p (buf) && (
(size_t)(const void *)((buf) + 1) - (size_t)(const void *)(buf
) == 1) ? __builtin_strcmp (buf, "Status:") : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (buf); int __result = (((const unsigned char *) (const
char *) ("Status:"))[0] - __s2[0]); if (__s2_len > 0 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ("Status:"))[1] - __s2[1]); if (__s2_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ("Status:"))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) ("Status:"))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp
(buf, "Status:")))); }) : strncmp (buf, "Status:", 7)))
362 && (strchr(buf, 'R')(__extension__ (__builtin_constant_p ('R') && !__builtin_constant_p
(buf) && ('R') == '\0' ? (char *) __rawmemchr (buf, 'R'
) : __builtin_strchr (buf, 'R')))
|| (!unseen_is_new && strchr(buf, 'O')(__extension__ (__builtin_constant_p ('O') && !__builtin_constant_p
(buf) && ('O') == '\0' ? (char *) __rawmemchr (buf, 'O'
) : __builtin_strchr (buf, 'O')))
))
363 )
364 return TRUE(!(0));
365
366 /* Netscape
367 */
368 if (!strncmp(buf, "X-Mozilla-Status:", 17)(__extension__ (__builtin_constant_p (17) && ((__builtin_constant_p
(buf) && strlen (buf) < ((size_t) (17))) || (__builtin_constant_p
("X-Mozilla-Status:") && strlen ("X-Mozilla-Status:"
) < ((size_t) (17)))) ? __extension__ ({ size_t __s1_len, __s2_len
; (__builtin_constant_p (buf) && __builtin_constant_p
("X-Mozilla-Status:") && (__s1_len = strlen (buf), __s2_len
= strlen ("X-Mozilla-Status:"), (!((size_t)(const void *)((buf
) + 1) - (size_t)(const void *)(buf) == 1) || __s1_len >= 4
) && (!((size_t)(const void *)(("X-Mozilla-Status:") +
1) - (size_t)(const void *)("X-Mozilla-Status:") == 1) || __s2_len
>= 4)) ? __builtin_strcmp (buf, "X-Mozilla-Status:") : (__builtin_constant_p
(buf) && ((size_t)(const void *)((buf) + 1) - (size_t
)(const void *)(buf) == 1) && (__s1_len = strlen (buf
), __s1_len < 4) ? (__builtin_constant_p ("X-Mozilla-Status:"
) && ((size_t)(const void *)(("X-Mozilla-Status:") + 1
) - (size_t)(const void *)("X-Mozilla-Status:") == 1) ? __builtin_strcmp
(buf, "X-Mozilla-Status:") : (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) ("X-Mozilla-Status:"
); int __result = (((const unsigned char *) (const char *) (buf
))[0] - __s2[0]); if (__s1_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) (buf)
)[1] - __s2[1]); if (__s1_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (buf)
)[2] - __s2[2]); if (__s1_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) (buf))[
3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("X-Mozilla-Status:"
) && ((size_t)(const void *)(("X-Mozilla-Status:") + 1
) - (size_t)(const void *)("X-Mozilla-Status:") == 1) &&
(__s2_len = strlen ("X-Mozilla-Status:"), __s2_len < 4) ?
(__builtin_constant_p (buf) && ((size_t)(const void *
)((buf) + 1) - (size_t)(const void *)(buf) == 1) ? __builtin_strcmp
(buf, "X-Mozilla-Status:") : (- (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) (buf); int
__result = (((const unsigned char *) (const char *) ("X-Mozilla-Status:"
))[0] - __s2[0]); if (__s2_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) ("X-Mozilla-Status:"
))[1] - __s2[1]); if (__s2_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) ("X-Mozilla-Status:"
))[2] - __s2[2]); if (__s2_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) ("X-Mozilla-Status:"
))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (buf
, "X-Mozilla-Status:")))); }) : strncmp (buf, "X-Mozilla-Status:"
, 17)))
)
369 {
370 c = buf[21];
371 if (c < '8') /* Not deleted */
372 c -= '0';
373 if (c >= '8' || (c & 0x1))
374 return TRUE(!(0));
375 }
376
377 /* Evolution
378 */
379 if (!strncmp(buf, "X-Evolution:", 12)(__extension__ (__builtin_constant_p (12) && ((__builtin_constant_p
(buf) && strlen (buf) < ((size_t) (12))) || (__builtin_constant_p
("X-Evolution:") && strlen ("X-Evolution:") < ((size_t
) (12)))) ? __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(buf) && __builtin_constant_p ("X-Evolution:") &&
(__s1_len = strlen (buf), __s2_len = strlen ("X-Evolution:")
, (!((size_t)(const void *)((buf) + 1) - (size_t)(const void *
)(buf) == 1) || __s1_len >= 4) && (!((size_t)(const
void *)(("X-Evolution:") + 1) - (size_t)(const void *)("X-Evolution:"
) == 1) || __s2_len >= 4)) ? __builtin_strcmp (buf, "X-Evolution:"
) : (__builtin_constant_p (buf) && ((size_t)(const void
*)((buf) + 1) - (size_t)(const void *)(buf) == 1) &&
(__s1_len = strlen (buf), __s1_len < 4) ? (__builtin_constant_p
("X-Evolution:") && ((size_t)(const void *)(("X-Evolution:"
) + 1) - (size_t)(const void *)("X-Evolution:") == 1) ? __builtin_strcmp
(buf, "X-Evolution:") : (__extension__ ({ const unsigned char
*__s2 = (const unsigned char *) (const char *) ("X-Evolution:"
); int __result = (((const unsigned char *) (const char *) (buf
))[0] - __s2[0]); if (__s1_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) (buf)
)[1] - __s2[1]); if (__s1_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (buf)
)[2] - __s2[2]); if (__s1_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) (buf))[
3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("X-Evolution:"
) && ((size_t)(const void *)(("X-Evolution:") + 1) - (
size_t)(const void *)("X-Evolution:") == 1) && (__s2_len
= strlen ("X-Evolution:"), __s2_len < 4) ? (__builtin_constant_p
(buf) && ((size_t)(const void *)((buf) + 1) - (size_t
)(const void *)(buf) == 1) ? __builtin_strcmp (buf, "X-Evolution:"
) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) (buf); int __result = (((const unsigned
char *) (const char *) ("X-Evolution:"))[0] - __s2[0]); if (
__s2_len > 0 && __result == 0) { __result = (((const
unsigned char *) (const char *) ("X-Evolution:"))[1] - __s2[
1]); if (__s2_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) ("X-Evolution:"))
[2] - __s2[2]); if (__s2_len > 2 && __result == 0)
__result = (((const unsigned char *) (const char *) ("X-Evolution:"
))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (buf
, "X-Evolution:")))); }) : strncmp (buf, "X-Evolution:", 12))
)
)
380 {
381 sscanf(buf+22, "%04x", &tmp);
382 if (tmp & (1<<4))
383 return TRUE(!(0));
384 }
385
386 return FALSE(0);
387 }
388
389 /* test if a mail is marked as deleted
390 | Evolution uses status with X-Evolution: 00000000-xxxx where xxxx status is
391 | a bitfield in hexadecimal (see enum _CamelMessageFlags in evolution/camel source)
392 | and most importantly CAMEL_MESSAGE_DELETED = 1<<1.
393 */
394static gboolean
395status_is_deleted(gchar *buf)
396 {
397 gint tmp;
398
399 /* Standard mail clients
400 if ( !strncmp(buf, "Status:", 7) )
401 */
402 /* Netscape
403 if (!strncmp(buf, "X-Mozilla-Status:", 17))
404 */
405 /* Evolution
406 */
407 if (!strncmp(buf, "X-Evolution:", 12)(__extension__ (__builtin_constant_p (12) && ((__builtin_constant_p
(buf) && strlen (buf) < ((size_t) (12))) || (__builtin_constant_p
("X-Evolution:") && strlen ("X-Evolution:") < ((size_t
) (12)))) ? __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(buf) && __builtin_constant_p ("X-Evolution:") &&
(__s1_len = strlen (buf), __s2_len = strlen ("X-Evolution:")
, (!((size_t)(const void *)((buf) + 1) - (size_t)(const void *
)(buf) == 1) || __s1_len >= 4) && (!((size_t)(const
void *)(("X-Evolution:") + 1) - (size_t)(const void *)("X-Evolution:"
) == 1) || __s2_len >= 4)) ? __builtin_strcmp (buf, "X-Evolution:"
) : (__builtin_constant_p (buf) && ((size_t)(const void
*)((buf) + 1) - (size_t)(const void *)(buf) == 1) &&
(__s1_len = strlen (buf), __s1_len < 4) ? (__builtin_constant_p
("X-Evolution:") && ((size_t)(const void *)(("X-Evolution:"
) + 1) - (size_t)(const void *)("X-Evolution:") == 1) ? __builtin_strcmp
(buf, "X-Evolution:") : (__extension__ ({ const unsigned char
*__s2 = (const unsigned char *) (const char *) ("X-Evolution:"
); int __result = (((const unsigned char *) (const char *) (buf
))[0] - __s2[0]); if (__s1_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) (buf)
)[1] - __s2[1]); if (__s1_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (buf)
)[2] - __s2[2]); if (__s1_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) (buf))[
3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("X-Evolution:"
) && ((size_t)(const void *)(("X-Evolution:") + 1) - (
size_t)(const void *)("X-Evolution:") == 1) && (__s2_len
= strlen ("X-Evolution:"), __s2_len < 4) ? (__builtin_constant_p
(buf) && ((size_t)(const void *)((buf) + 1) - (size_t
)(const void *)(buf) == 1) ? __builtin_strcmp (buf, "X-Evolution:"
) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) (buf); int __result = (((const unsigned
char *) (const char *) ("X-Evolution:"))[0] - __s2[0]); if (
__s2_len > 0 && __result == 0) { __result = (((const
unsigned char *) (const char *) ("X-Evolution:"))[1] - __s2[
1]); if (__s2_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) ("X-Evolution:"))
[2] - __s2[2]); if (__s2_len > 2 && __result == 0)
__result = (((const unsigned char *) (const char *) ("X-Evolution:"
))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (buf
, "X-Evolution:")))); }) : strncmp (buf, "X-Evolution:", 12))
)
)
408 {
409 sscanf(buf+22, "%04x", &tmp);
410 if (tmp & (1<<1))
411 return TRUE(!(0));
412 /* Junk is not explicitly marked as deleted but is shown as if
413 | where in evolution
414 */
415 if (tmp & (1<<7))
416 return TRUE(!(0));
417 }
418
419 return FALSE(0);
420 }
421
422static gboolean
423check_mbox(Mailbox *mbox)
424 {
425 FILE *f;
426 struct utimbuf ut;
427 struct stat s;
428 gchar buf[1024];
429 gchar mpart_sep[1024];
430 gint in_header = FALSE(0);
431 gint marked_read = FALSE(0);
432 gint is_multipart = FALSE(0);
433
434 if (stat(mbox->path, &s) != 0)
435 {
436 mbox->mail_count = mbox->old_mail_count = mbox->new_mail_count = 0;
437 mbox->last_mtime = 0;
438 mbox->last_size = 0;
439 gkrellm_debug(DEBUG_MAIL0x10, "check_mbox can't stat(%s): %s\n",
440 mbox->path, g_strerror(errno(*__errno_location ())));
441 return FALSE(0);
442 }
443
444 /* If the mailboxes have been modified since last check, count
445 | the new/total messages.
446 */
447 if ( s.st_mtimest_mtim.tv_sec != mbox->last_mtime
448 || s.st_size != mbox->last_size
449 )
450 {
451 if ((f = fopen(mbox->path, "r")) == NULL((void*)0))
452 {
453 gkrellm_debug(DEBUG_MAIL0x10, "check_mbox can't fopen(%s): %s\n",
454 mbox->path, g_strerror(errno(*__errno_location ())));
455 return FALSE(0);
456 }
457 mbox->mail_count = 0;
458 mbox->old_mail_count = 0;
459 while(fgets(buf, sizeof(buf), f))
460 {
461 if (is_multipart && !in_header)
462 {
463 /* Skip to last line of multipart mail */
464 if (strncmp(buf,mpart_sep,strlen(mpart_sep))(__extension__ (__builtin_constant_p (strlen(mpart_sep)) &&
((__builtin_constant_p (buf) && strlen (buf) < ((
size_t) (strlen(mpart_sep)))) || (__builtin_constant_p (mpart_sep
) && strlen (mpart_sep) < ((size_t) (strlen(mpart_sep
))))) ? __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(buf) && __builtin_constant_p (mpart_sep) &&
(__s1_len = strlen (buf), __s2_len = strlen (mpart_sep), (!(
(size_t)(const void *)((buf) + 1) - (size_t)(const void *)(buf
) == 1) || __s1_len >= 4) && (!((size_t)(const void
*)((mpart_sep) + 1) - (size_t)(const void *)(mpart_sep) == 1
) || __s2_len >= 4)) ? __builtin_strcmp (buf, mpart_sep) :
(__builtin_constant_p (buf) && ((size_t)(const void *
)((buf) + 1) - (size_t)(const void *)(buf) == 1) && (
__s1_len = strlen (buf), __s1_len < 4) ? (__builtin_constant_p
(mpart_sep) && ((size_t)(const void *)((mpart_sep) +
1) - (size_t)(const void *)(mpart_sep) == 1) ? __builtin_strcmp
(buf, mpart_sep) : (__extension__ ({ const unsigned char *__s2
= (const unsigned char *) (const char *) (mpart_sep); int __result
= (((const unsigned char *) (const char *) (buf))[0] - __s2[
0]); if (__s1_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) (buf))[1] - __s2[
1]); if (__s1_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) (buf))[2] - __s2[
2]); if (__s1_len > 2 && __result == 0) __result =
(((const unsigned char *) (const char *) (buf))[3] - __s2[3]
); } } __result; }))) : (__builtin_constant_p (mpart_sep) &&
((size_t)(const void *)((mpart_sep) + 1) - (size_t)(const void
*)(mpart_sep) == 1) && (__s2_len = strlen (mpart_sep
), __s2_len < 4) ? (__builtin_constant_p (buf) && (
(size_t)(const void *)((buf) + 1) - (size_t)(const void *)(buf
) == 1) ? __builtin_strcmp (buf, mpart_sep) : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (buf); int __result = (((const unsigned char *) (const
char *) (mpart_sep))[0] - __s2[0]); if (__s2_len > 0 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (mpart_sep))[1] - __s2[1]); if (__s2_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (mpart_sep))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) (mpart_sep))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp
(buf, mpart_sep)))); }) : strncmp (buf, mpart_sep, strlen(mpart_sep
))))
==0)
465 is_multipart = FALSE(0);
466 }
467 else if (buf[0] == '\n')
468 {
469 in_header = FALSE(0);
470 mbox->is_internal = FALSE(0);
471 }
472 else if (is_From_line(mbox, buf))
473 {
474 mbox->mail_count += 1;
475 in_header = TRUE(!(0));
476 marked_read = FALSE(0);
477 }
478 else if (in_header && is_status(buf))
479 {
480 if (status_is_old(buf) && !marked_read)
481 {
482 mbox->old_mail_count += 1;
483 marked_read = TRUE(!(0));
484 }
485 if (status_is_deleted(buf))
486 {
487 if (marked_read)
488 mbox->old_mail_count -= 1;
489 mbox->mail_count -= 1;
490 }
491 }
492 else if (in_header && mbox->is_internal)
493 {
494 if (strncmp(buf, "From: Mail System Internal Data", 31)(__extension__ (__builtin_constant_p (31) && ((__builtin_constant_p
(buf) && strlen (buf) < ((size_t) (31))) || (__builtin_constant_p
("From: Mail System Internal Data") && strlen ("From: Mail System Internal Data"
) < ((size_t) (31)))) ? __extension__ ({ size_t __s1_len, __s2_len
; (__builtin_constant_p (buf) && __builtin_constant_p
("From: Mail System Internal Data") && (__s1_len = strlen
(buf), __s2_len = strlen ("From: Mail System Internal Data")
, (!((size_t)(const void *)((buf) + 1) - (size_t)(const void *
)(buf) == 1) || __s1_len >= 4) && (!((size_t)(const
void *)(("From: Mail System Internal Data") + 1) - (size_t)(
const void *)("From: Mail System Internal Data") == 1) || __s2_len
>= 4)) ? __builtin_strcmp (buf, "From: Mail System Internal Data"
) : (__builtin_constant_p (buf) && ((size_t)(const void
*)((buf) + 1) - (size_t)(const void *)(buf) == 1) &&
(__s1_len = strlen (buf), __s1_len < 4) ? (__builtin_constant_p
("From: Mail System Internal Data") && ((size_t)(const
void *)(("From: Mail System Internal Data") + 1) - (size_t)(
const void *)("From: Mail System Internal Data") == 1) ? __builtin_strcmp
(buf, "From: Mail System Internal Data") : (__extension__ ({
const unsigned char *__s2 = (const unsigned char *) (const char
*) ("From: Mail System Internal Data"); int __result = (((const
unsigned char *) (const char *) (buf))[0] - __s2[0]); if (__s1_len
> 0 && __result == 0) { __result = (((const unsigned
char *) (const char *) (buf))[1] - __s2[1]); if (__s1_len >
1 && __result == 0) { __result = (((const unsigned char
*) (const char *) (buf))[2] - __s2[2]); if (__s1_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) (buf))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p
("From: Mail System Internal Data") && ((size_t)(const
void *)(("From: Mail System Internal Data") + 1) - (size_t)(
const void *)("From: Mail System Internal Data") == 1) &&
(__s2_len = strlen ("From: Mail System Internal Data"), __s2_len
< 4) ? (__builtin_constant_p (buf) && ((size_t)(const
void *)((buf) + 1) - (size_t)(const void *)(buf) == 1) ? __builtin_strcmp
(buf, "From: Mail System Internal Data") : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (buf); int __result = (((const unsigned char *) (const
char *) ("From: Mail System Internal Data"))[0] - __s2[0]); if
(__s2_len > 0 && __result == 0) { __result = (((const
unsigned char *) (const char *) ("From: Mail System Internal Data"
))[1] - __s2[1]); if (__s2_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) ("From: Mail System Internal Data"
))[2] - __s2[2]); if (__s2_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) ("From: Mail System Internal Data"
))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (buf
, "From: Mail System Internal Data")))); }) : strncmp (buf, "From: Mail System Internal Data"
, 31)))
== 0)
495 {
496 in_header = FALSE(0);
497 mbox->mail_count -= 1;
498 mbox->is_internal = FALSE(0);
499 }
500 }
501 else if (in_header && is_multipart_mail(buf,mpart_sep))
502 {
503 is_multipart = TRUE(!(0));
504 }
505 }
506 fclose(f);
507
508 /* Restore the mbox stat times for other mail checking programs and
509 | so the (st_atime > st_mtime) animation override below will work.
510 */
511 ut.actime = s.st_atimest_atim.tv_sec;
512 ut.modtime = s.st_mtimest_mtim.tv_sec;
513 utime(mbox->path, &ut);
514
515 mbox->last_mtime = s.st_mtimest_mtim.tv_sec;
516 mbox->last_size = s.st_size;
517 if (_GK.debug_level & DEBUG_MAIL0x10)
518 g_print("mbox read <%s> total=%d old=%d\n",
519 mbox->path,
520 mbox->mail_count, mbox->old_mail_count);
521 }
522
523 /* If mbox has been accessed since last modify a MUA has probably read
524 | the mbox.
525 */
526 mbox->new_mail_count = mbox->mail_count - mbox->old_mail_count;
527 if (s.st_atimest_atim.tv_sec > s.st_mtimest_mtim.tv_sec)
528 {
529 mbox->prev_new_mail_count = mbox->new_mail_count;
530 }
531 return TRUE(!(0));
532 }
533
534
535static void
536update_mail(GkrellmdMonitor *mon, gboolean force)
537 {
538 Mailbox *mbox;
539 GList *list;
540 static gint second_count;
541
542 if ( (!GK.second_tick || (++second_count % mail_check_timeout) != 0)
543 && !force
544 )
545 return;
546
547 for (list = mailbox_list; list; list = list->next)
548 {
549 mbox = (Mailbox *) list->data;
550 if (mbox->check_func)
551 (*mbox->check_func)(mbox);
552
553 if ( mbox->prev_mail_count != mbox->mail_count
554 || mbox->prev_new_mail_count != mbox->new_mail_count
555 )
556 {
557 mbox->changed = TRUE(!(0));
558 mail_need_serve = TRUE(!(0));
559 gkrellmd_need_serve(mon);
560 }
561 mbox->prev_mail_count = mbox->mail_count;
562 mbox->prev_new_mail_count = mbox->new_mail_count;
563 }
564 }
565
566
567static void
568get_local_mboxtype(Mailbox *mbox)
569 {
570 gchar *path;
571
572 if (*(mbox->path) == '~')
573 {
574 mbox->homedir_path = mbox->path;
575 mbox->path = g_strdup_printf("%s%s", g_get_home_dir(),
576 mbox->homedir_path + 1);
577 }
578 if (g_file_test(mbox->path, G_FILE_TEST_IS_DIR))
579 {
580 path = g_build_path(G_DIR_SEPARATOR_S"/", mbox->path, "new", NULL((void*)0));
581 if (g_file_test(path, G_FILE_TEST_IS_DIR))
582 mbox->mboxtype = MBOX_MAILDIR1;
583 else
584 mbox->mboxtype = MBOX_MH_DIR2;
585 g_free(path);
586 }
587 else
588 mbox->mboxtype = MBOX_MBOX0;
589 }
590
591void
592gkrellmd_add_mailbox(gchar *path)
593 {
594 Mailbox *mbox;
595
596 if (!path || !*path)
597 return;
598 mbox = g_new0(Mailbox, 1)(Mailbox *) (__extension__ ({ gsize __n = (gsize) (1); gsize __s
= sizeof (Mailbox); gpointer __p; if (__s == 1) __p = g_malloc0
(__n); else if (__builtin_constant_p (__n) && (__s ==
0 || __n <= (9223372036854775807L *2UL+1UL) / __s)) __p =
g_malloc0 (__n * __s); else __p = g_malloc0_n (__n, __s); __p
; }))
;
599 mbox->path = g_strdup(path);
600 get_local_mboxtype(mbox);
601
602 if (mbox->mboxtype == MBOX_MAILDIR1)
603 mbox->check_func = check_maildir;
604 else if (mbox->mboxtype == MBOX_MH_DIR2)
605 mbox->check_func = check_mh_dir;
606 else
607 mbox->check_func = check_mbox;
608
609 mailbox_list = g_list_append(mailbox_list, mbox);
610 gkrellmd_add_serveflag_done(&mbox->changed);
611 }
612
613/* ============================================================= */
614
615static void
616serve_mail_data(GkrellmdMonitor *mon, gboolean first_serve)
617 {
618 Mailbox *mbox;
619 GList *list;
620 gchar *line;
621
622 if ((!mail_need_serve && !first_serve) || !mailbox_list)
623 return;
624 gkrellmd_set_serve_name(mon, "mail");
625 for (list = mailbox_list; list; list = list->next)
626 {
627 mbox = (Mailbox *) list->data;
628 if (mbox->changed || first_serve)
629 {
630 line = g_strdup_printf("%s %d %d\n", mbox->homedir_path ?
631 mbox->homedir_path : mbox->path,
632 mbox->mail_count, mbox->new_mail_count);
633 gkrellmd_serve_data(mon, line);
634 g_free(line);
635 }
636 }
637 }
638
639static void
640serve_mail_setup(GkrellmdMonitor *mon)
641 {
642 GkrellmdClient *client = mon->privat->client;
643 GList *list;
644 Mailbox *mbox;
645 gchar *line;
646
647 gkrellmd_send_to_client(client, "<mail_setup>\n");
648 for (list = mailbox_list; list; list = list->next)
649 {
650 mbox = (Mailbox *) list->data;
651 line = g_strdup_printf("%s\n", mbox->homedir_path ?
652 mbox->homedir_path : mbox->path);
653 gkrellmd_send_to_client(client, line);
654 g_free(line);
655 }
656 }
657
658static GkrellmdMonitor mail_monitor =
659 {
660 "mail",
661 update_mail,
662 serve_mail_data,
663 serve_mail_setup
664 };
665
666GkrellmdMonitor *
667gkrellmd_init_mail_monitor(void)
668 {
669 gkrellmd_add_serveflag_done(&mail_need_serve);
670 return &mail_monitor;
671 }
672
673#else /* defined(WIN32) */
674
675GkrellmdMonitor *
676gkrellmd_init_mail_monitor(void)
677 {
678 return NULL((void*)0);
679 }
680
681void
682gkrellmd_add_mailbox(gchar *path)
683 {
684 }
685
686#endif
687
688
689void
690gkrellm_mail_local_unsupported(void)
691 {
692 /* WIN32 only calls this and it is taken care of by above #if */
693 }
694
695GThread *
696gkrellm_mail_get_active_thread(void)
697 {
698 return NULL((void*)0);
699 }
700