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 2006 University of Washington
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * ========================================================================
22 #include <sys/types.h>
26 #define MAILSPOOLPCTS "/usr/spool/mail/%s"
27 /* #define MAILSPOOLPCTS "/usr/mail/%s" */
30 #define DAYSEC (60*60*24)
37 char filename
[100], buf
[100], *p
;
39 long now
, inbox_mess
, inboxes
, inbox_mess_max
;
40 int core_files
, c
, core_id
, count
, sig_files
;
41 int user_count
[6], so_far
;
44 user_count
[0] = 0; /* Last week */
45 user_count
[1] = 0; /* Last 2 weeks */
46 user_count
[2] = 0; /* Last month */
47 user_count
[3] = 0; /* Last year */
48 user_count
[4] = 0; /* Ever */
59 core_id
= atoi(argv
[1]);
61 fprintf(stderr
, "Bogus core starting number\n");
64 printf("Core collect starting at %d\n", core_id
);
65 core
= fopen("pine-core-collect.sh", "w");
70 while((pw
= getpwent()) != NULL
) {
72 if((so_far
% 200) == 0) {
73 printf("%5d users processed so far\n", so_far
);
76 if(strncmp(pw
->pw_dir
, "/", 1) == 0)
79 snprintf(filename
, sizeof(filename
), "%s/.pinerc", pw
->pw_dir
);
80 if(stat(filename
, &statb
) < 0)
82 if(statb
.st_mtime
+ 7 * DAYSEC
> now
)
84 else if(statb
.st_mtime
+ 14 * DAYSEC
> now
)
86 else if(statb
.st_mtime
+ 30 * DAYSEC
> now
)
88 else if(statb
.st_mtime
+ 365 * DAYSEC
> now
)
94 if(statb
.st_mtime
+ 30 * DAYSEC
>= now
) {
95 count
= mail_file_size(pw
->pw_name
);
99 inbox_mess_max
= inbox_mess_max
> count
? inbox_mess_max
:count
;
103 snprintf(filename
, sizeof(filename
), "%s/.signature", pw
->pw_dir
);
104 if(access(filename
, 0) == 0)
107 snprintf(filename
, sizeof(filename
), "%s/core", pw
->pw_dir
);
108 if((f
= fopen(filename
, "r")) != NULL
) {
110 while((c
= getc(f
)) != EOF
) {
114 while((c
= getc(f
)) != EOF
) {
126 if(strncmp(&buf
[strlen(buf
) - 13], "(olivebranch)", 13) == 0) {
127 printf("%s\t%s\n", filename
, buf
+ 14);
130 fprintf(core
, "mv %s core%d.%s\n", filename
,
131 core_id
++,pw
->pw_name
);
139 /* printf("%s\n", pw->pw_name); */
144 printf("%5d: last week\n", user_count
[0]);
145 printf("%5d: last two weeks (+%d)\n", user_count
[1] + user_count
[0],
147 printf("%5d: last month (+%d)\n", user_count
[2] + user_count
[1] + user_count
[0], user_count
[2]);
148 printf("%5d: last year\n", user_count
[3]);
149 printf("%5d: more than a year\n", user_count
[4]);
150 printf("%5d: core files\n", core_files
);
151 printf("%5d: Average messages in inbox (%ld/%d)\n",
152 inbox_mess
/(inboxes
? inboxes
: 1), inbox_mess
, inboxes
);
153 printf("%5d: Largest inbox in messages\n", inbox_mess_max
);
154 printf("%5d: Total users checked\n", so_far
);
155 printf("%5d: signature files\n", sig_files
);
166 snprintf(buf
, sizeof(buf
), MAILSPOOLPCTS
, user
);
172 while(fgets(buf
, sizeof(buf
), f
) != NULL
) {
173 if(strncmp(buf
, "From ", 5) == 0)
177 /* printf("%s %d\n", user, count); */