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.
25 #include <sys/types.h>
31 #define FOLDERS_DELTA 5
39 struct folder **folders = NULL;
40 unsigned int numfolders = 0;
41 unsigned int maxfolders = 0;
43 void add_folder(char *path)
45 struct folder *thisfolder;
50 if (numfolders == maxfolders) {
51 if ((folders = (struct folder **)
53 (maxfolders + FOLDERS_DELTA) * sizeof(struct folder *))) == NULL) {
57 maxfolders += FOLDERS_DELTA;
60 if ((thisfolder = (struct folder *)malloc(sizeof(struct folder))) == NULL) {
65 if ((cp = index(path, '=')) != NULL) {
67 if ((thisfolder->prefix = (char *)strdup(cp)) == NULL) {
71 strcpy(thisfolder->prefix, cp);
74 /* More than one mailbox to monitor --> need prefix anyway */
75 if ((cp = rindex(path, '/')) != NULL) {
77 if ((thisfolder->prefix = (char *)strdup(cp)) == NULL) {
82 if ((thisfolder->prefix = (char *)strdup(path)) == NULL) {
88 thisfolder->prefix = NULL;
91 if ((thisfolder->path = (char *)strdup(path)) == NULL) {
99 thisfolder->size = st.st_size;
100 } else if (sh == -1 && errno == ENOENT) {
101 thisfolder->size = 0;
103 free (thisfolder->path);
108 folders[numfolders++] = thisfolder;
111 void add_default_folder()
118 if ((env = getenv("MAIL")) == NULL) {
120 if ((pw = getpwuid(uid)) == NULL) {
125 snprintf(path, sizeof(path), "%s/%s", _PATH_MAILDIR, pw->pw_name);
127 snprintf(path, sizeof(path), env);
140 if (folders[0]->prefix != NULL)
143 if ((cp = rindex(folders[0]->path, '/')) != NULL) {
145 if ((folders[0]->prefix = (char *)strdup(cp)) == NULL) {
150 if ((folders[0]->prefix = (char *)strdup(folders[0]->path)) == NULL) {
157 void watch_folders(int opt_bell)
162 for (i=0; i < numfolders; i++)
163 newmail |= watch_mbox(folders[i]->path, folders[i]->prefix, &folders[i]->size);
165 if (newmail && opt_bell) {