]>
diplodocus.org Git - nmh/blob - docs/historical/mh-nov-1983/cmds/forw.c
2 static char sccsid
[] = "@(#)forw.c 4.1 2/23/83";
18 int inplace
; /* preserve links in anno */
34 struct swit switches
[] = {
36 "annotate", 0, /* 1 */
37 "noannotate", 0, /* 2 */
38 "editor editor", 0, /* 3 */
39 "form formfile", 0, /* 4 */
41 "noinplace", 0, /* 6 */
48 "edit [<editor>]", 0, /* 1 */
49 "quit [delete]", 0, /* 2 */
50 "send [verbose]", 0, /* 3 */
58 char *folder
, *maildir
, *msgs
[100], *ed
, *form
;
60 register char *cp
, **ap
;
61 int msgp
, status
, anot
;
63 int pid
, wpid
, msgcnt
;
64 char *arguments
[50], **argp
;
70 form
= 0; anot
= 0; folder
= 0; msgp
= 0; ed
= 0;
71 cp
= r1bindex(argv
[0], '/');
72 if((cp
= m_find(cp
)) != NULL
) {
73 ap
= brkstring(cp
= getcpy(cp
), " ", "\n");
74 ap
= copyip(ap
, arguments
);
81 switch(smatch(++cp
, switches
)) {
82 case -2:ambigsw(cp
, switches
); /* ambiguous */
85 case -1:fprintf(stderr
, "forw: -%s unknown\n", cp
);
88 case 0: fprintf(stderr
, "\"-all\" changed to \"all\"\n");
90 case 1: anot
= 1; continue; /* -annotate */
91 case 2: anot
= 0; continue; /* -noannotate */
92 case 3: if(!(ed
= *argp
++)) { /* -editor */
93 missing
: fprintf(stderr
, "forw: Missing argument for %s switch\n", argp
[-2]);
97 case 4: if(!(form
= *argp
++)) /* -form */
100 case 5: inplace
= 1; continue; /* -inplace */
101 case 6: inplace
= 0; continue; /* -noinplace */
103 case 7: help("forw [+folder] [msgs] [switches]",
109 fprintf(stderr
, "Only one folder at a time.\n");
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 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 type(out
, "\n\n-------");
176 if(msgnum
== mp
->lowsel
) {
177 type(out
, " Forwarded Message");
181 type(out
, " Message ");
182 sprintf(numbuf
, "%d", msgcnt
);
190 type(out
, "\n\n------- End of Forwarded Message");
195 m_replace(pfolder
, folder
);
196 if(mp
->lowsel
!= mp
->curmsg
)
197 m_setcur(mp
->lowsel
);
198 if(m_edit(&ed
, drft
, NOUSE
, NONE
) < 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: showfile(drft
); /* list */
211 case 1: if(*++argp
) /* edit */
213 if(m_edit(&ed
, drft
, NOUSE
, NONE
) == -1)
216 case 2: if(*++argp
&& *argp
[0] == 'd') /* quit */
217 if(unlink(drft
) == -1) {
218 fprintf(stderr
, "Can't unlink %s ", drft
);
222 case 3: if(*++argp
) cp
= *argp
; else cp
= ""; /* send */
224 if(!mp
->msgflags
&READONLY
) { /* annotate first */
226 while((pid
= fork()) == -1) sleep(5);
228 while(wpid
=wait((int *)NULL
)!= -1 && wpid
!= pid
);
234 if(!m_send(cp
, drft
))
236 default:fprintf(stderr
, "forw: illegal option\n"); /*##*/
253 if((i
= read(in
, buf
, sizeof buf
)) > 0)
255 while(i
== sizeof buf
);
262 char name
[NAMESZ
], field
[256];
263 register int ind
, state
;
266 if(stat(drft
, field
) != -1) {
267 fprintf(stderr
, "%s not sent-- no annotations made.\n", drft
);
270 text
= copy(drft
, field
);
274 while(--text
>= field
&& *text
!= '/');
279 ','; /* New backup convention */
281 if((in
= fopen(field
, "r")) == NULL
) {
282 fprintf(stderr
, "Can't open "); perror(field
);
287 for(;;) switch(state
= m_getfld(state
, name
, field
, sizeof field
, in
)) {
292 if(uleq(name
, "to") || uleq(name
, "cc") == 0) {
294 text
= add(name
, text
);
295 text
= add(":", text
);
297 text
= add(field
, text
);
306 fprintf(stderr
, "Getfld returned %d\n", state
);
313 for(ind
= mp
->lowsel
; ind
<= mp
->hghsel
; ind
++)
314 if(mp
->msgstats
[ind
] & SELECTED
)
315 annotate(m_name(ind
), "Forwarded", text
, inplace
);