2 * ========================================================================
3 * Copyright 2013-2022 Eduardo Chappa
4 * Copyright 2006 University of Washington
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * ========================================================================
19 #include <sys/types.h>
23 #define MAILSPOOLPCTS "/usr/spool/mail/%s"
24 /* #define MAILSPOOLPCTS "/usr/mail/%s" */
27 #define DAYSEC (60*60*24)
34 char filename
[100], buf
[100], *p
;
36 long now
, inbox_mess
, inboxes
, inbox_mess_max
;
37 int core_files
, c
, core_id
, count
, sig_files
;
38 int user_count
[6], so_far
;
41 user_count
[0] = 0; /* Last week */
42 user_count
[1] = 0; /* Last 2 weeks */
43 user_count
[2] = 0; /* Last month */
44 user_count
[3] = 0; /* Last year */
45 user_count
[4] = 0; /* Ever */
56 core_id
= atoi(argv
[1]);
58 fprintf(stderr
, "Bogus core starting number\n");
61 printf("Core collect starting at %d\n", core_id
);
62 core
= fopen("pine-core-collect.sh", "w");
67 while((pw
= getpwent()) != NULL
) {
69 if((so_far
% 200) == 0) {
70 printf("%5d users processed so far\n", so_far
);
73 if(pw
->pw_dir
&& *pw
->pw_dir
== '/' && pw
->pw_dir
[1] == '\0')
76 snprintf(filename
, sizeof(filename
), "%s/.pinerc", pw
->pw_dir
);
77 if(stat(filename
, &statb
) < 0)
79 if(statb
.st_mtime
+ 7 * DAYSEC
> now
)
81 else if(statb
.st_mtime
+ 14 * DAYSEC
> now
)
83 else if(statb
.st_mtime
+ 30 * DAYSEC
> now
)
85 else if(statb
.st_mtime
+ 365 * DAYSEC
> now
)
91 if(statb
.st_mtime
+ 30 * DAYSEC
>= now
) {
92 count
= mail_file_size(pw
->pw_name
);
96 inbox_mess_max
= inbox_mess_max
> count
? inbox_mess_max
:count
;
100 snprintf(filename
, sizeof(filename
), "%s/.signature", pw
->pw_dir
);
101 if(access(filename
, 0) == 0)
104 snprintf(filename
, sizeof(filename
), "%s/core", pw
->pw_dir
);
105 if((f
= fopen(filename
, "r")) != NULL
) {
107 while((c
= getc(f
)) != EOF
) {
111 while((c
= getc(f
)) != EOF
) {
123 if(strncmp(&buf
[strlen(buf
) - 13], "(olivebranch)", 13) == 0) {
124 printf("%s\t%s\n", filename
, buf
+ 14);
127 fprintf(core
, "mv %s core%d.%s\n", filename
,
128 core_id
++,pw
->pw_name
);
136 /* printf("%s\n", pw->pw_name); */
141 printf("%5d: last week\n", user_count
[0]);
142 printf("%5d: last two weeks (+%d)\n", user_count
[1] + user_count
[0],
144 printf("%5d: last month (+%d)\n", user_count
[2] + user_count
[1] + user_count
[0], user_count
[2]);
145 printf("%5d: last year\n", user_count
[3]);
146 printf("%5d: more than a year\n", user_count
[4]);
147 printf("%5d: core files\n", core_files
);
148 printf("%5ld: Average messages in inbox (%ld/%ld)\n",
149 inbox_mess
/(inboxes
? inboxes
: 1), inbox_mess
, inboxes
);
150 printf("%5d: Largest inbox in messages\n", inbox_mess_max
);
151 printf("%5d: Total users checked\n", so_far
);
152 printf("%5d: signature files\n", sig_files
);
163 snprintf(buf
, sizeof(buf
), MAILSPOOLPCTS
, user
);
169 while(fgets(buf
, sizeof(buf
), f
) != NULL
) {
170 if(strncmp(buf
, "From ", 5) == 0)
174 /* printf("%s %d\n", user, count); */