2 Proprietary Rand Corporation
, 1981.
3 Further distribution of
this software
4 subject to the terms of the Rand
12 #include <sys/types.h>
15 extern char *sprintf();
23 int inplace
; /* preserve links in anno */
25 struct swit anyl
[] = {
32 struct swit switches
[] = {
34 "annotate", 0, /* 1 */
35 "noannotate", 0, /* 2 */
36 "editor editor", 0, /* 3 */
37 "form formfile", 0, /* 4 */
39 "noinplace", 0, /* 6 */
44 struct swit aleqs
[] = {
46 "edit [<editor>]", 0, /* 1 */
47 "quit [delete]", 0, /* 2 */
48 "send [switches]", 0, /* 3 */
56 char *folder
, *maildir
, *msgs
[100], *ed
, *form
;
58 register char *cp
, **ap
;
61 int pid
, wpid
, msgcnt
;
62 char *arguments
[50], **argp
;
69 form
= 0; anot
= 0; folder
= 0; msgp
= 0; ed
= 0;
70 cp
= r1bindex(argv
[0], '/');
71 if((cp
= m_find(cp
)) != NULL
) {
72 ap
= brkstring(cp
= getcpy(cp
), " ", "\n");
73 ap
= copyip(ap
, arguments
);
76 VOID
copyip(argv
+1, ap
);
80 switch(smatch(++cp
, switches
)) {
81 case -2:ambigsw(cp
, switches
); /* ambiguous */
84 case -1:fprintf(stderr
, "forw: -%s unknown\n", cp
);
87 case 0: fprintf(stderr
, "\"-all\" changed to \"all\"\n");
89 case 1: anot
= 1; continue; /* -annotate */
90 case 2: anot
= 0; continue; /* -noannotate */
91 case 3: if(!(ed
= *argp
++)) { /* -editor */
92 missing
: fprintf(stderr
, "forw: Missing argument for %s switch\n", argp
[-2]);
96 case 4: if(!(form
= *argp
++)) /* -form */
99 case 5: inplace
= 1; continue; /* -inplace */
100 case 6: inplace
= 0; continue; /* -noinplace */
102 case 7: help("forw [+folder] [msgs] [switches]",
108 fprintf(stderr
, "Only one folder at a time.\n");
111 folder
= path(cp
+1, TFOLDER
);
115 if(!m_find("path")) free(path("./", TFOLDER
));
117 msgs
[msgp
++] = "cur";
119 folder
= m_getfolder();
120 maildir
= m_maildir(folder
);
121 if(chdir(maildir
) < 0) {
122 fprintf(stderr
, "Can't chdir to: ");
126 if(!(mp
= m_gmsg(folder
))) {
127 fprintf(stderr
, "Can't read folder!?\n");
130 if(mp
->hghmsg
== 0) {
131 fprintf(stderr
, "No messages in \"%s\".\n", folder
);
134 for(msgnum
= 0; msgnum
< msgp
; msgnum
++)
135 if(!m_convert(msgs
[msgnum
]))
137 if(mp
->numsel
== 0) {
138 fprintf(stderr
, "forw: italian salami.\n"); /* never get here */
142 if((in
= open(m_maildir(form
), 0)) < 0) {
143 fprintf(stderr
, "forw: Can't open form file: %s\n", form
);
146 } else if((in
= open(m_maildir(components
), 0)) < 0 &&
147 (in
= open(stdcomps
, 0)) < 0) {
148 fprintf(stderr
, "forw: Can't open default components file!!\n");
151 VOID
copy(m_maildir(draft
), drft
);
152 if((out
= open(drft
, 0)) >= 0) {
153 if(!fdcompare(in
, out
)) {
154 cp
= concat("\"", drft
, "\" exists; Delete? ", 0);
155 while((msgnum
= gans(cp
, anyl
)) == 2)
162 if((out
= creat(drft
, m_gmprot())) < 0) {
163 fprintf(stderr
, "Can't create \"%s\"\n", drft
);
168 for(msgcnt
= 1, msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++)
169 if(mp
->msgstats
[msgnum
]&SELECTED
) {
170 if((in
= open(cp
= m_name(msgnum
), 0)) < 0) {
171 fprintf(stderr
, "Can't open message \"%s\"\n", cp
);
175 VOID
type(out
, "\n\n-------");
176 if(msgnum
== mp
->lowsel
) {
177 VOID
type(out
, " Forwarded Message");
181 VOID
type(out
, " Message ");
182 VOID
sprintf(numbuf
, "%d", msgcnt
);
183 VOID
type(out
, numbuf
);
185 VOID
type(out
, "\n\n");
190 VOID
type(out
, "\n\n------- End of Forwarded Message");
193 VOID
type(out
, "\n");
195 m_replace(pfolder
, folder
);
196 if(mp
->lowsel
!= mp
->curmsg
)
197 m_setcur(mp
->lowsel
);
198 if(m_edit(&ed
, drft
, NOUSE
, NULLCP
) < 0)
202 fprintf(stderr
, "!! Test Version of SEND Being Run !!\n");
203 fprintf(stderr
, " Send verbose !\n\n");
206 if(!(argp
= getans("\nWhat now? ", aleqs
)))
208 switch(smatch(*argp
, aleqs
)) {
209 case 0: VOID
showfile(drft
); /* list */
212 case 1: if(*++argp
) /* edit */
214 if(m_edit(&ed
, drft
, NOUSE
, NULLCP
) == -1)
217 case 2: if(*++argp
&& (*argp
[0] == 'd' || /* quit */
218 (*argp
[0]=='-' && *argp
[1]=='d')))
219 if(unlink(drft
) == -1) {
220 fprintf(stderr
, "Can't unlink %s ", drft
);
226 if(!mp
->msgflags
&READONLY
) { /* annotate first */
228 while((pid
= fork()) == -1) sleep(5);
230 while((wpid
=wait((int *)NULL
))!= -1
237 VOID
m_send(++argp
, drft
);
240 default:fprintf(stderr
, "forw: illegal option\n"); /*##*/
257 if((i
= read(in
, buf
, sizeof buf
)) > 0)
258 if(write(out
, buf
, i
) != i
) {
259 fprintf(stderr
, "forw: write ");
263 while(i
== sizeof buf
);
270 char name
[NAMESZ
], field
[256];
271 register int ind
, state
;
274 if(stat(drft
, (struct stat
*)field
) != -1) {
275 fprintf(stderr
, "%s not sent-- no annotations made.\n", drft
);
278 text
= copy(drft
, field
);
282 while(--text
>= field
&& *text
!= '/');
283 *++text
= ','; /* New backup convention */
284 if((in
= fopen(field
, "r")) == NULL
) {
285 fprintf(stderr
, "Can't open "); perror(field
);
290 for(;;) switch(state
= m_getfld(state
, name
, field
, sizeof field
, in
)) {
295 if(uleq(name
, "to") || uleq(name
, "cc") ) {
297 text
= add(name
, text
);
298 text
= add(":", text
);
300 text
= add(field
, text
);
309 fprintf(stderr
, "Getfld returned %d\n", state
);
316 for(ind
= mp
->lowsel
; ind
<= mp
->hghsel
; ind
++)
317 if(mp
->msgstats
[ind
] & SELECTED
)
318 VOID
annotate(m_name(ind
), "Forwarded", text
, inpl