2 Proprietary Rand Corporation
, 1981.
3 Further distribution of
this software
4 subject to the terms of the Rand
10 #include <sys/types.h>
17 extern char *sprintf();
19 extern struct swit anoyes
[]; /* Std no/yes gans array */
26 int lockwait
; /* Secs to wait for lock-Def in strings/lockdir.c */
27 #define LOCKWAIT (lockwait*5) /* If lock is this old, simply ignore it! */
32 extern int errno
; /* MLW 4bsd does not have errno defined in errno.h */
33 extern char _sobuf
[]; /* MLW standard out buffer */
35 struct swit switches
[] = {
36 "audit audit-file", 0, /* 0 */
37 "ms ms-folder", 0, /* 1 */
39 "changecur", 0, /* 3 */
40 "nochangecur", 0, /* 4 */
44 "nonumdate", 0, /* 8 */
53 char *newmail
, maildir
[128], *folder
, *from
, *audfile
;
57 register int i
, msgnum
;
60 char *arguments
[50], **argp
;
65 setbuf(stdout
, _sobuf
);
70 change_cur
= 1; /* Default */
71 from
= 0; folder
= 0; audfile
= 0;
72 cp
= r1bindex(argv
[0], '/');
73 if((cp
= m_find(cp
)) != NULL
) {
74 ap
= brkstring(cp
= getcpy(cp
), " ", "\n");
75 ap
= copyip(ap
, arguments
);
78 VOID
copyip(argv
+1, ap
);
82 switch(smatch(++cp
, switches
)) {
83 case -2:ambigsw(cp
, switches
); /* ambiguous */
86 case -1:fprintf(stderr
, "inc: -%s unknown\n", cp
);
88 case 0: if(!(audfile
= *argp
++)) { /* -audit */
89 missing
: fprintf(stderr
, "inc: Missing argument for %s switch\n", argp
[-2]);
93 case 1: if(!(from
= *argp
++)) /* -ms */
97 help("inc [+folder] [switches]", switches
);
105 case 5: timeflag
= 1; continue; /* -time */
106 case 6: timeflag
= 0; continue; /* -notime */
107 case 7: numflag
= 1; continue; /* -numdate */
108 case 8: numflag
= 0; continue; /* -nonumdate */
112 fprintf(stderr
, "Only one folder at a time.\n");
115 folder
= path(cp
+1, TFOLDER
);
117 fprintf(stderr
, "Bad arg: %s\n", argp
[-1]);
118 fprintf(stderr
, "Usage: inc [+folder] [-ms ms-folder] [-audit audit-file]\n");
122 if(!m_find("path")) free(path("./", TFOLDER
));
126 if((myname
= getenv("USER")) == 0) {
128 "Environment Variable \"USER\" Must be set to your login name!\n");
131 newmail
= concat(mailboxes
, "/", myname
, NULLCP
);
132 /*** VOID copy(mailbox, copy(mypath, newmail)); ***/
133 if(stat(newmail
, &stbuf
) < 0 ||
134 stbuf
.st_size
== 0) {
135 fprintf(stderr
, "No Mail to incorporate.\n");
141 if(from
&& strcmp(from
, "inbox") == 0) {
142 cp
= concat("Do you really want to convert from ",
143 from
, " into ", folder
, "?? ", NULLCP
);
144 if(!gans(cp
, anoyes
))
149 VOID
copy(m_maildir(folder
), maildir
);
150 if(stat(maildir
, &stbuf
) < 0) {
151 if(errno
!= ENOENT
) {
152 fprintf(stderr
, "Error on folder ");
156 cp
= concat("Create folder \"", maildir
, "\"? ", NULLCP
);
157 if(!gans(cp
, anoyes
))
159 if(!makedir(maildir
)) {
160 fprintf(stderr
, "Can't create folder \"%s\"\n", maildir
);
164 if(chdir(maildir
) < 0) {
165 fprintf(stderr
, "Can't chdir to: ");
169 if(!(mp
= m_gmsg(folder
))) {
170 fprintf(stderr
, "Can't read folder!?\n");
173 /* Lock the mail file */
175 VOID
signal(SIGINT
, done
);
176 cp
= concat(lockdir
, "/", myname
, NULLCP
);
177 for(i
= 0; i
< lockwait
; i
+= 2) {
178 if(link(newmail
, cp
) == -1) {
179 fprintf(stderr
, "Mailbox busy...\n");
180 if(i
== 0 && stat(newmail
, &stbuf
) >= 0)
181 if(stbuf
.st_ctime
+ LOCKWAIT
< time((long *)0)) {
183 fprintf(stderr
, "Removing lock.\n");
188 locknode
= cp
; /* We own the lock now! */
193 fprintf(stderr
, "Try again.\n");
197 if((in
= fopen(newmail
, "r")) == NULL
) {
198 fprintf(stderr
, "Can't open "); perror(newmail
);
202 cp
= m_maildir(audfile
);
203 if((i
= stat(cp
, &stbuf
)) < 0)
204 fprintf(stderr
, "Creating Receive-Audit: %s\n", cp
);
205 if((aud
= fopen(cp
, "a")) == NULL
) {
206 fprintf(stderr
, "Can't append to ");
210 VOID
chmod(cp
, 0600);
211 now
= time((long *)0);
212 fputs("<<inc>> ", aud
);
222 printf("Incorporating new mail into %s...\n\n", folder
);
226 while((i
= scan(in
, msgnum
+1, msgnum
+1, msgnum
== mp
->hghmsg
,
227 (timeflag
? DOTIME
: 0)
228 | (numflag
? NUMDATE
: 0), 0))) {
230 fprintf(stderr
, "inc aborted!\n");
232 fputs("inc aborted!\n", aud
);
237 "More than %d messages. Inc aborted!\n",
239 fprintf(stderr
,"%s not zero'd\n", newmail
);
253 if((i
= creat(newmail
, 0600)) >= 0) /* Zap .mail file */
256 fprintf(stderr
, "Error zeroing %s\n", newmail
);
258 printf("%s not zero'd\n", newmail
);
260 i
= msgnum
- mp
->hghmsg
;
261 /* printf("%d new message%s\n", i, i==1? "":"s"); */
263 fprintf(stderr
, "[No messages incorporated.]\n");
265 m_replace(pfolder
, folder
);
267 m_setcur(mp
->hghmsg
+ 1);
278 VOID
unlink(locknode
);