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 $";
6 * ========================================================================
7 * Copyright 2013-2020 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 * ========================================================================
23 #include <sys/types.h>
27 #define MAILSPOOLPCTS "/usr/spool/mail/%s"
28 /* #define MAILSPOOLPCTS "/usr/mail/%s" */
31 #define DAYSEC (60*60*24)
38 char filename
[100], buf
[100], *p
;
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
;
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 */
60 core_id
= atoi(argv
[1]);
62 fprintf(stderr
, "Bogus core starting number\n");
65 printf("Core collect starting at %d\n", core_id
);
66 core
= fopen("pine-core-collect.sh", "w");
71 while((pw
= getpwent()) != NULL
) {
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')
80 snprintf(filename
, sizeof(filename
), "%s/.pinerc", pw
->pw_dir
);
81 if(stat(filename
, &statb
) < 0)
83 if(statb
.st_mtime
+ 7 * DAYSEC
> now
)
85 else if(statb
.st_mtime
+ 14 * DAYSEC
> now
)
87 else if(statb
.st_mtime
+ 30 * DAYSEC
> now
)
89 else if(statb
.st_mtime
+ 365 * DAYSEC
> now
)
95 if(statb
.st_mtime
+ 30 * DAYSEC
>= now
) {
96 count
= mail_file_size(pw
->pw_name
);
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)
108 snprintf(filename
, sizeof(filename
), "%s/core", pw
->pw_dir
);
109 if((f
= fopen(filename
, "r")) != NULL
) {
111 while((c
= getc(f
)) != EOF
) {
115 while((c
= getc(f
)) != EOF
) {
127 if(strncmp(&buf
[strlen(buf
) - 13], "(olivebranch)", 13) == 0) {
128 printf("%s\t%s\n", filename
, buf
+ 14);
131 fprintf(core
, "mv %s core%d.%s\n", filename
,
132 core_id
++,pw
->pw_name
);
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],
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
);
167 snprintf(buf
, sizeof(buf
), MAILSPOOLPCTS
, user
);
173 while(fgets(buf
, sizeof(buf
), f
) != NULL
) {
174 if(strncmp(buf
, "From ", 5) == 0)
178 /* printf("%s %d\n", user, count); */