2 Copyright (c) 2004,7 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.
25 #include <sys/types.h>
31 #define _PATH_MAILDIR "/var/spool/mail"
36 #define FOLDERS_DELTA 5
44 struct folder **folders = NULL;
45 unsigned int numfolders = 0;
46 unsigned int maxfolders = 0;
48 void add_folder(char *path)
50 struct folder *thisfolder;
55 if (numfolders == maxfolders) {
56 if ((folders = (struct folder **)
58 (maxfolders + FOLDERS_DELTA) * sizeof(struct folder *))) == NULL) {
62 maxfolders += FOLDERS_DELTA;
65 if ((thisfolder = (struct folder *)malloc(sizeof(struct folder))) == NULL) {
70 if ((cp = index(path, '=')) != NULL) {
72 if ((thisfolder->prefix = (char *)strdup(cp)) == NULL) {
76 strcpy(thisfolder->prefix, cp);
79 /* More than one mailbox to monitor --> need prefix anyway */
80 if ((cp = rindex(path, '/')) != NULL) {
82 if ((thisfolder->prefix = (char *)strdup(cp)) == NULL) {
87 if ((thisfolder->prefix = (char *)strdup(path)) == NULL) {
93 thisfolder->prefix = NULL;
96 if ((thisfolder->path = (char *)strdup(path)) == NULL) {
101 sh = stat(path, &st);
104 thisfolder->size = st.st_size;
105 } else if (sh == -1 && errno == ENOENT) {
106 thisfolder->size = 0;
108 free (thisfolder->path);
113 folders[numfolders++] = thisfolder;
116 void add_default_folder()
123 if ((env = getenv("MAIL")) == NULL) {
125 if ((pw = getpwuid(uid)) == NULL) {
130 snprintf (path, sizeof(path), "%s/%s", _PATH_MAILDIR, pw->pw_name);
132 snprintf (path, sizeof(path), env);
145 if (folders[0]->prefix != NULL)
148 if ((cp = rindex(folders[0]->path, '/')) != NULL) {
150 if ((folders[0]->prefix = (char *)strdup(cp)) == NULL) {
155 if ((folders[0]->prefix = (char *)strdup(folders[0]->path)) == NULL) {
162 void watch_folders(int opt_flags)
167 for (i=0; i < numfolders; i++)
168 newmail |= watch_mbox(folders[i]->path, folders[i]->prefix, &folders[i]->size, opt_flags);
171 if (!(opt_flags & OPT_WINDOW)) {
172 if (opt_flags & OPT_BELL)