home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
TELECOM
/
OSKBox.lzh
/
MAILBOX
/
CC
/
renumber.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-01
|
2KB
|
85 lines
#include <stdio.h>
#include <errno.h>
#include "mailbox.h"
struct {
int was, is;
} map[MAXMAIL];
rename_file (name, newname)
char *name, *newname;
{
char *argv[4];
int stat;
extern char **environ;
extern int os9fork();
argv[0] = "rename";
argv[1] = name;
argv[2] = newname;
argv[3] = 0;
os9exec (os9fork, argv[0], argv, environ, 0, 0, 3);
wait (&stat);
return ((stat == 0) ? 0 : -1);
}
main (argc, argv)
char *argv[];
{
int i = 1;
struct msg_header head;
struct userstruct user;
int mailcount = 0;
int f1, f2;
char str1[40], str2[40];
chdir (HOME);
if ((f1 = open ("mail_dir", 1)) < 0)
exit (errno, printf ("Error opening mail_dir\n"));
f2 = creat ("mail_dir.tmp", 3);
while (read (f1, &head, sizeof (head))) {
if (head.mhstat == ' ') {
write (f2, &head, sizeof (head));
continue;
}
if (head.mhnr == i) {
i++;
write (f2, &head, sizeof (head));
continue;
}
printf ("%d -> %d\n", head.mhnr, i);
sprintf (str1, "MAIL/%06d", head.mhnr);
sprintf (str2, "%06d", i);
rename_file (str1, str2);
map[mailcount].was = head.mhnr;
map[mailcount].is = i;
mailcount++;
head.mhnr = i++;
write (f2, &head, sizeof (head));
}
close (f1);
close (f2);
unlink ("mail_dir");
rename_file ("mail_dir.tmp", "mail_dir");
if ((f1 = open ("users", 1)) < 0)
exit (errno, printf ("Error opening users\n"));
f2 = creat ("users.tmp", 3);
while (read (f1, &user, sizeof (user))) {
for (i = 0; i < mailcount; i++)
if (user.usnmr == map[i].was) {
user.usnmr = map[i].is;
break;
}
else if (user.usnmr < map[i].was) {
user.usnmr = map[i-1].is;
break;
}
write (f2, &user, sizeof (user));
}
close (f1);
close (f2);
unlink ("users");
rename_file ("users.tmp", "users");
}