2 Copyright (c) 2004 Joey Schulze <joey@infodrom.org>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <sys/types.h>
35 int inspect_mbox(char *path, char *prefix, off_t size)
44 char from_[HDR_LEN] = "";
45 char from[HDR_LEN] = "";
46 char to[HDR_LEN] = "";
47 char subject[HDR_LEN] = "";
50 if ((f = fopen(path, "r")) == NULL)
53 if (size > 0 && fseek(f, size, SEEK_SET) != 0)
57 if ((cp = fgets(buf, sizeof(buf), f)) == NULL)
59 if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n') {
60 buf[strlen(buf)-1] = '\0';
62 while (!feof(f) && fgets(tmp, sizeof(tmp), f) != NULL) {
63 if (strlen(tmp) > 0 && tmp[strlen(tmp)-1] == '\n')
69 if (strlen(buf) == 0) {
73 /* TODO: display header */
75 from_[0] = from[0] = to[0] = subject[0] = '\0';
78 if (strncasecmp(buf, "From ", 5) == 0) {
79 strncpy(from_, buf+5, sizeof(from_)-1);
80 from[sizeof(from_)-1] = '\0';
81 } else if (strncasecmp(buf, "From: ", 6) == 0) {
82 strncpy(from, buf+6, sizeof(from)-1);
83 from[sizeof(from)-1] = '\0';
85 } else if (strncasecmp(buf, "To: ", 4) == 0) {
86 strncpy(to, buf+4, sizeof(to)-1);
87 from[sizeof(to)-1] = '\0';
89 } else if (strncasecmp(buf, "Subject: ", 9) == 0) {
90 strncpy(subject, buf+9, sizeof(subject)-1);
91 from[sizeof(subject)-1] = '\0';
92 } else if (strncasecmp(buf, "Priority: ", 10) == 0)
95 } else if (strncasecmp(buf, "From ", 5) == 0) {
97 strncpy(from_, buf+5, sizeof(from_)-1);
98 from[sizeof(from_)-1] = '\0';
106 int watch_mbox(char *path, char *prefix, off_t *size)
111 if (stat(path, &st) == 0) {
112 if (st.st_size > *size)
113 if (access(path, R_OK) == 0) {
114 newmail = inspect_mbox(path, prefix, *size);