-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquser.c
60 lines (52 loc) · 1.65 KB
/
quser.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*******************************************************************************
* *
* This file is part of quser. *
* *
* $Id: quser.c,v 1.4 2002/09/30 13:43:15 cwright Exp $ *
* *
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <dirent.h>
#include "quser.h"
int addressmatch(char *sender, char match[MAX_ADDRESS]) {
char *endofline;
char *senderdomain;
int matches=0;
int i=0;
int j=0;
for(i=0;i<sizeof(sender);i++) sender[i] = tolower(sender[i]);
for(j=0;j<sizeof(match);j++) match[j] = tolower(match[j]);
printf("s:%s, m:%s\n",sender,match);
endofline=(strchr(match,'\n'));
if(endofline!=NULL) *endofline='\0';
if(strcmp(sender,match) == 0) {
matches=1;
} else {
if(match[0]=='@') match++;
if(strchr(match,'@')==NULL) {
if((senderdomain=strrchr(sender,'@'))!=NULL) {
if(strcmp(++senderdomain,match) == 0) {
matches=1;
}
}
}
}
return (matches==0) ? 0 : 1;
}
int getMessages(char *fldr) {
DIR *dir;
struct dirent *entry;
int mesg = 0;
if((dir = opendir(fldr)) != NULL) {
while((entry = readdir(dir)) != NULL)
if((entry->d_name)[0] != '.') ++mesg;
closedir(dir);
} else {
fprintf(stderr,"cmaildir: cannot open dir: %s\n",fldr);
mesg = -1;
}
return mesg;
}