1 /*
2  * (C) Maint Laboratory 2003-2004
3  * Author: Elohin Igor'
4  * e-mail: maint@unona.ru
5  * fido  : 2:5070/222.52
6  * URL   : http://maint.unona.ru
7  */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <sys/stat.h>
12 #include <fcntl.h>
13 #include <dirent.h>
14 #include <errno.h>
15 #include "../common.h"
16 #include "../config.h"
17 
18 #ifdef _BSD
19 #include <limits.h>
20 #endif
21 
erase_outgoing_msgid(char * msgid)22 int erase_outgoing_msgid(char *msgid)
23 {
24     struct dirent *dir;
25     struct stat stbuf;
26     DIR *dir_fd;
27     char curr_name[PATH_MAX];
28     FILE *fd;
29     char buf[BUFSIZE];
30     char *s;
31 
32     if ((dir_fd = opendir(outgoing)) == NULL) {
33 	myerror("Cannot open %s (%s)", outgoing, strerror(errno));
34 	return 1;
35     }
36     while ((dir = readdir(dir_fd)) != NULL) {
37 	if (strcmp(dir->d_name, ".") == 0 ||
38 	    strcmp(dir->d_name, "..") == 0)
39 	    continue;
40 	snprintf(curr_name, sizeof(curr_name), "%s/%s", outgoing, dir->d_name);
41 	if (stat(curr_name, &stbuf) < 0)
42 	    continue;
43 	if ((stbuf.st_mode & S_IFMT) == S_IFDIR)
44 	    continue;
45 	if((fd = fopen(curr_name, "r")) == NULL){
46 	    myerror("%s: %s", curr_name, strerror(errno));
47             continue;
48 	}
49 	while (fgets(buf, BUFSIZE, fd)) {
50 	    if (strncmp(buf, "Message-ID: ", 12) == 0) {
51 		if ((s = strchr(buf, 0x0a)) != NULL)
52 		    *s = '\0';
53 		if ((s = strchr(buf, 0x0d)) != NULL)
54 		    *s = '\0';
55 		if (strcmp(msgid, &buf[12]) == 0) {
56 		    fclose(fd);
57 		    if (remove(curr_name)) {
58 			myerror("%s: %s", curr_name, strerror(errno));
59 		    }
60                     goto b1;
61 		}
62 	    }
63 	}
64         fclose(fd);
65     }
66 b1:
67     closedir(dir_fd);
68     return 0;
69 }
isfidogroup(char * str)70 int isfidogroup(char *str)
71 {
72     char list[128], ie[128], *s, *b;
73     char t[128];
74 
75     if(ffgroups[0] == '\0') return 1;
76 
77     strcpy(list, ffgroups);
78     b = list;
79     while((s = strtok(b, ", ")) != NULL){
80         strcpy(t, s);
81         strcat(t, ".");
82         if(!strncmp(t, str, strlen(t))) return 1;
83         b = NULL;
84     }
85     return 0;
86 }
87