]>
diplodocus.org Git - nmh/blob - docs/historical/SRI-NOSC/pickup.c
6 char *anoyes
[], /* Std no/yes gans array */
13 struct iobuf in
, fout
, *aud
;
16 struct swit switches
[] {
17 "audit audit-file", 0, /* 0 */
18 "ms ms-folder", 0, /* 1 */
27 char newmail
[128], maildir
[128], *folder
, *from
, *audfile
;
29 register int i
, msgnum
;
32 char *arguments
[50], **argp
;
34 fout
.b_fildes
= dup(1);
38 from
= folder
= audfile
= 0;
44 if((cp
= m_find(ap
)) != -1) {
45 ap
= brkstring(cp
= getcpy(cp
), " ", "\n");
46 ap
= copyip(ap
, arguments
);
53 switch(smatch(++cp
, switches
)) {
54 case -2:ambigsw(cp
, switches
); /* ambiguous */
57 case -1:printf("-%s unknown\n", cp
);
59 case 0: if(!(audfile
= *argp
++)) { /* -audit */
60 missing
: printf("Missing argument for %s switch\n", argp
[-2]);
64 case 1: if(!(from
= *argp
++)) /* -ms */
68 help(concat( inp
, " [+folder] [switches]", 0), switches
);
73 printf("Only one folder at a time.\n");
78 printf("Bad arg: %s\n", argp
[-1]);
79 printf(concat("Usage: ", inp
, " [+folder] [-ms ms-folder] [-audit audit-file]\n", 0));
86 mypath
= getpath(getruid());
87 copy(mailbox
, copy(mypath
, newmail
));
88 if(stat(newmail
, &stbuf
) < 0 ||
89 !(stbuf
.i_size0
| stbuf
.i_size1
)) {
90 printf("No new mail.\n");
94 if(fopen(newmail
, &in
) < 0) {
95 printf("Can't read \"%s\"??\n", newmail
);
100 if(from
&& !equal(from
, "inbox")) {
101 cp
= concat("Do you really want to convert from ",
102 from
, " into ", folder
, "?? ", 0);
103 if(!gans(cp
, anoyes
))
107 copy(m_maildir(folder
), maildir
);
108 if(stat(maildir
, &stbuf
) < 0) {
109 if(errno
!= ENOENT
) {
110 printf("Error on folder "); flush();
114 /* cp = concat("Create folder \"", maildir, "\"? ", 0);
115 if(!gans(cp, anoyes))
117 if(!makedir(maildir
)) {
118 printf("Can't create folder \"%s\"\n", maildir
);
122 if(chdir(maildir
) < 0) {
123 printf("Can't chdir to: ");
127 if(!(mp
= m_gmsg(folder
))) {
128 printf("Can't read folder!?\n");
132 aud
= alloc(sizeof *aud
);
133 cp
= m_maildir(audfile
);
134 if(fopen2(cp
, aud
) == -1) {
135 printf("Creating Receive-Audit: %s\n", cp
);
136 if(fcreat(cp
, aud
) == -1) {
137 printf("Can't create "); flush();
144 seek(aud
->b_fildes
, 0, 2);
146 puts("<<inc>> ", aud
);
156 printf("Incorporating new mail into %s...\n\n", folder
);
160 while((i
= scan(&in
, msgnum
+1, msgnum
+1, msgnum
== mp
->hghmsg
))) {
162 printf("command aborted!\n");
164 puts("inc aborted!\n", aud
);
178 if((i
= creat(newmail
, 0600)) >= 0) /* Zap .mail file */
181 printf("Error zeroing %s\n", newmail
);
183 printf("%s not zero'd\n", newmail
);
185 i
= msgnum
- mp
->hghmsg
;
186 /* printf("%d new message%s\n", i, i==1? "":"s"); */
188 printf("[No messages incorporated.]\n");
190 if(!equal(m_getfolder(), folder
))
191 m_replace("folder", folder
);
192 m_setcur(mp
->hghmsg
+ 1);