* NTLM authentication support with the ntlm library, in Unix systems.
[alpine.git] / alpine / pine-use.c
blob7712d72e7d0165d21a26a735da53ddae4864725a
1 #if !defined(lint) && !defined(DOS)
2 static char rcsid[] = "$Id: pine-use.c 761 2007-10-23 22:35:18Z hubert@u.washington.edu $";
3 #endif
5 /*
6 * ========================================================================
7 * Copyright 2013-2017 Eduardo Chappa
8 * Copyright 2006 University of Washington
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * ========================================================================
19 #include <stdlib.h>
20 #include <string.h>
21 #include <stdio.h>
22 #include <pwd.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
26 #ifndef MAILSPOOLPCTS
27 #define MAILSPOOLPCTS "/usr/spool/mail/%s"
28 /* #define MAILSPOOLPCTS "/usr/mail/%s" */
29 #endif
31 #define DAYSEC (60*60*24)
33 main(argc, argv)
34 int argc;
35 char **argv;
37 struct passwd *pw;
38 char filename[100], buf[100], *p;
39 struct stat statb;
40 long now, inbox_mess, inboxes, inbox_mess_max;
41 int core_files, c, core_id, count, sig_files;
42 int user_count[6], so_far;
43 FILE *f, *core;
45 user_count[0] = 0; /* Last week */
46 user_count[1] = 0; /* Last 2 weeks */
47 user_count[2] = 0; /* Last month */
48 user_count[3] = 0; /* Last year */
49 user_count[4] = 0; /* Ever */
50 sig_files = 0;
51 core_files = 0;
52 inboxes = 0;
53 inbox_mess = 0;
54 inbox_mess_max = 0;
56 now = time(0);
57 core = NULL;
59 if(argc > 1) {
60 core_id = atoi(argv[1]);
61 if(core_id == 0){
62 fprintf(stderr, "Bogus core starting number\n");
63 exit(-1);
64 } else {
65 printf("Core collect starting at %d\n", core_id);
66 core = fopen("pine-core-collect.sh", "w");
70 so_far = 0;
71 while((pw = getpwent()) != NULL) {
72 so_far++;
73 if((so_far % 200) == 0) {
74 printf("%5d users processed so far\n", so_far);
77 if(pw->pw_dir && *pw->pw_dir == '/' && pw->pw_dir[1] == '\0')
78 continue;
80 snprintf(filename, sizeof(filename), "%s/.pinerc", pw->pw_dir);
81 if(stat(filename, &statb) < 0)
82 continue;
83 if(statb.st_mtime + 7 * DAYSEC > now)
84 user_count[0]++;
85 else if(statb.st_mtime + 14 * DAYSEC > now)
86 user_count[1]++;
87 else if(statb.st_mtime + 30 * DAYSEC > now)
88 user_count[2]++;
89 else if(statb.st_mtime + 365 * DAYSEC > now)
90 user_count[3]++;
91 else
92 user_count[4]++;
95 if(statb.st_mtime + 30 * DAYSEC >= now) {
96 count = mail_file_size(pw->pw_name);
97 if(count >= 0){
98 inboxes++;
99 inbox_mess += count;
100 inbox_mess_max = inbox_mess_max > count ? inbox_mess_max:count;
104 snprintf(filename, sizeof(filename), "%s/.signature", pw->pw_dir);
105 if(access(filename, 0) == 0)
106 sig_files++;
108 snprintf(filename, sizeof(filename), "%s/core", pw->pw_dir);
109 if((f = fopen(filename, "r")) != NULL) {
110 fflush(stdout);
111 while((c = getc(f)) != EOF) {
112 if(c == 'P'){
113 p = buf;
114 *p++ = c;
115 while((c = getc(f)) != EOF) {
116 *p++ = c;
117 if(p > &buf[50]) {
118 break;
120 if(c == ')') {
121 break;
124 *p = '\0';
125 if(c == EOF)
126 break;
127 if(strncmp(&buf[strlen(buf) - 13], "(olivebranch)", 13) == 0) {
128 printf("%s\t%s\n", filename, buf + 14);
129 core_files++;
130 if(core != NULL) {
131 fprintf(core, "mv %s core%d.%s\n", filename,
132 core_id++,pw->pw_name);
134 break;
138 fclose(f);
139 } else {
140 /* printf("%s\n", pw->pw_name); */
145 printf("%5d: last week\n", user_count[0]);
146 printf("%5d: last two weeks (+%d)\n", user_count[1] + user_count[0],
147 user_count[1]);
148 printf("%5d: last month (+%d)\n", user_count[2] + user_count[1] + user_count[0], user_count[2]);
149 printf("%5d: last year\n", user_count[3]);
150 printf("%5d: more than a year\n", user_count[4]);
151 printf("%5d: core files\n", core_files);
152 printf("%5ld: Average messages in inbox (%ld/%ld)\n",
153 inbox_mess/(inboxes ? inboxes : 1), inbox_mess, inboxes);
154 printf("%5d: Largest inbox in messages\n", inbox_mess_max);
155 printf("%5d: Total users checked\n", so_far);
156 printf("%5d: signature files\n", sig_files);
160 mail_file_size(user)
161 char *user;
163 int count = 0;
164 FILE *f;
165 char buf[20480];
167 snprintf(buf, sizeof(buf), MAILSPOOLPCTS, user);
169 f = fopen(buf, "r");
170 if(f == NULL)
171 return(-1);
173 while(fgets(buf, sizeof(buf), f) != NULL) {
174 if(strncmp(buf, "From ", 5) == 0)
175 count++;
177 fclose(f);
178 /* printf("%s %d\n", user, count); */
179 return(count);