]>
diplodocus.org Git - nmh/blob - docs/historical/SRI-NOSC/forward.c
17 int *vec
[MAXARGS
], fout
;
34 struct swit switches
[] {
36 "annotate", 0, /* 1 */
37 "noannotate", 0, /* 2 */
38 "editor editor", 0, /* 3 */
39 "form formfile", 0, /* 4 */
47 char *folder
, *maildir
, *msgs
[100], *ed
, *form
;
49 register char *cp
, *ap
;
51 int msgp
, status
, anot
;
53 char *arguments
[50], **argp
;
59 form
= anot
= folder
= msgp
= ed
= 0;
65 if((cp
= m_find(ap
)) != -1) {
66 ap
= brkstring(cp
= getcpy(cp
), " ", "\n");
67 ap
= copyip(ap
, arguments
);
74 switch(smatch(++cp
, switches
)) {
75 case -2:ambigsw(cp
, switches
); /* ambiguous */
78 case -1:printf("-%s unknown\n", cp
);
81 case 0: printf("\"-all\" changed to \"all\"\n");
83 case 1: anot
= 1; continue; /* -annotate */
84 case 2: anot
= 0; continue; /* -noannotate */
85 case 3: if(!(ed
= *argp
++)) { /* -editor */
86 missing
: printf("Missing argument for %s switch\n", argp
[-2]);
90 case 4: if(!(form
= *argp
++)) /* -form */
94 case 5: help(concat( inp
, " [+folder] [msgs] [switches]", 0),
100 printf("Only one folder at a time.\n");
108 msgs
[msgp
++] = "cur";
110 folder
= m_getfolder();
111 maildir
= m_maildir(folder
);
112 if(chdir(maildir
) < 0) {
113 printf("Can't chdir to: "); flush();
117 if(!(mp
= m_gmsg(folder
))) {
118 printf("Can't read folder!?\n");
121 if(mp
->hghmsg
== 0) {
122 printf("No messages in \"%s\".\n", folder
);
125 for(msgnum
= 0; msgnum
< msgp
; msgnum
++)
126 if(!m_convert(msgs
[msgnum
], UNDELETED
, UNDELETED
))
128 if(mp
->numsel
== 0) {
129 printf("No undeleted messages specified\n");
133 if((in
= open(m_maildir(form
), 0)) < 0) {
134 printf("Can't open form file: %s\n", form
);
137 } else if((in
= open(m_maildir(components
), 0)) < 0 &&
138 (in
= open(stdcomps
, 0)) < 0) {
139 printf("Can't open default components file!!\n");
142 copy(m_maildir(draft
), drft
);
143 if((out
= open(drft
, 0)) >= 0) {
145 if(!fdcompare(in, out)) {
146 cp = concat("\"", drft, "\" exists; Delete? ", 0);
147 while((msgnum = gans(cp, anysh)) == 2)
155 if((out
= creat(drft
, m_gmprot())) < 0) {
156 printf("Can't create \"%s\"\n", drft
);
161 printf("Forwarding message%s ", mp
->numsel
> 1 ? "s" : "");
162 for(msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++)
163 if(mp
->msgstats
[msgnum
]&SELECTED
) {
164 if((in
= open(cp
= m_name(msgnum
), 0)) < 0) {
165 printf("Can't open message \"%s\"\n", cp
);
169 printf("%d ", msgnum
);
170 type(out
, "-------");
171 if(msgnum
== mp
->lowsel
) {
172 type(out
, " Forwarded Message");
180 type(out
, "------- End of Forwarded Message");
187 m_replace("folder", folder
);
188 if(mp
->lowsel
!= mp
->curmsg
)
189 m_setcur(mp
->lowsel
);
190 if(!ed
&& (ed
= m_find("editor")) == -1)
196 intr
= signal(SIGINT
, 1);
197 if((in
= fork()) == 0) {
200 execlsrh(ed
, drft
, 0);
201 printf("Can't exec the editor!!\n");
203 } else if(in
== -1) {
204 printf("No forks!\n");
207 while((out
= waita(&status
)) != -1 && out
!= in
) ;
208 signal(SIGINT
, intr
);
212 printf("[command aborted--%s %s]\n", drft
,
213 status
> 0377? "deleted" : "preserved");
217 printf("!! Test Version of SEND Being Run !!\n");
218 printf(" Send verbose !\n\n");
220 /* cp = concat("Send \"", draft, "\"? ", 0); */
222 if((out
= gans(cp
, anyv
)) > 0) {
224 while((in
= fork()) == -1) sleep(5);
226 while(msgnum
= wait() != -1 && msgnum
!= in
);
232 vec
[in
++] = "mh-sndproc";
235 vec
[in
++] = "-verbose";
240 printf("Can't exec send process.\n");
256 if((i
= read(in
, buf
, sizeof buf
)) > 0)
258 while(i
== sizeof buf
);
265 char name
[NAMESZ
], field
[256];
266 register int ind
, state
;
269 if(stat(drft
, field
) != -1) {
270 printf("%s not sent-- no annotations made.\n", drft
);
273 text
= copy(drft
, field
);
277 while(--text
>= field
&& *text
!= '/');
278 *++text
= ','; /* New backup convention */
279 if(fopen(field
, &in
) < 0) {
280 printf("Can't open %s\n", field
);
285 for(;;) switch(state
= m_getfld(state
, name
, field
, sizeof field
, &in
)) {
290 if(uleq(name
, "to") || equal(name
, "cc")) {
292 text
= add(name
, text
);
293 text
= add(":", text
);
295 text
= add(field
, text
);
304 printf("Getfld returned %d\n", state
);
311 for(ind
= mp
->lowsel
; ind
<= mp
->hghsel
; ind
++)
312 if(mp
->msgstats
[ind
] & SELECTED
)
313 annotate(m_name(ind
), "Forwarded", text
);