2 Proprietary Rand Corporation
, 1981.
3 Further distribution of
this software
4 subject to the terms of the Rand
12 #include <sys/types.h>
19 struct swit anyl
[] = {
26 struct swit aleqs
[] = {
28 "edit [<editor>]", 0, /* 1 */
29 "quit [delete]", 0, /* 2 */
30 "send [switches]", 0, /* 3 */
36 int inplace
; /* preserve links in anno */
38 struct swit switches
[] = {
39 "annotate", 0, /* 0 */
40 "noannotate", 0, /* 1 */
41 "editor editor", 0, /* 2 */
42 "form formfile", 0, /* 3 */
44 "noinplace", 0, /* 5 */
53 char *folder
, *maildir
, *msgs
[100], *ed
, *form
;
55 register char *cp
, **ap
;
59 char *arguments
[50], **argp
;
65 anot
= 0; folder
= 0; msgp
= 0; ed
= 0; form
= 0;
66 cp
= r1bindex(argv
[0], '/');
67 if((cp
= m_find(cp
)) != NULL
) {
68 ap
= brkstring(cp
= getcpy(cp
), " ", "\n");
69 ap
= copyip(ap
, arguments
);
72 VOID
copyip(argv
+1, ap
);
76 switch(smatch(++cp
, switches
)) {
77 case -2:ambigsw(cp
, switches
); /* ambiguous */
80 case -1:fprintf(stderr
, "dist: -%s unknown\n", cp
);
82 case 0: anot
= 1; continue; /* -annotate */
83 case 1: anot
= 0; continue; /* -noannotate */
84 case 2: if(!(ed
= *argp
++)) { /* -editor */
85 missing
: fprintf(stderr
, "dist: Missing argument for %s switch\n", argp
[-2]);
89 case 3: if(!(form
= *argp
++)) /* -form */
92 case 4: inplace
= 1; continue; /* -inplace */
93 case 5: inplace
= 0; continue; /* -noinplace */
95 case 6: help("dist [+folder] [msg] [switches]",
101 fprintf(stderr
, "Only one folder at a time.\n");
104 folder
= path(cp
+1, TFOLDER
);
108 if(!m_find("path")) free(path("./", TFOLDER
));
110 msgs
[msgp
++] = "cur";
112 folder
= m_getfolder();
113 maildir
= m_maildir(folder
);
114 if(chdir(maildir
) < 0) {
115 fprintf(stderr
, "Can't chdir to: ");
119 if(!(mp
= m_gmsg(folder
))) {
120 fprintf(stderr
, "Can't read folder!?\n");
123 if(mp
->hghmsg
== 0) {
124 fprintf(stderr
, "No messages in \"%s\".\n", folder
);
127 for(msgnum
= 0; msgnum
< msgp
; msgnum
++)
128 if(!m_convert((cp
= msgs
[msgnum
])))
130 if(mp
->numsel
== 0) {
131 fprintf(stderr
, "dist: Tuna Melt\n"); /* never get here */
135 fprintf(stderr
, "Only one message at a time.\n");
139 if((in
= open(m_maildir(form
), 0)) < 0) {
140 fprintf(stderr
, "dist: Can't open form file: %s\n", form
);
143 } else if(/***(in = open(m_maildir(distcomps), 0)) < 0 && ***/
144 (in
= open(stddcomps
, 0)) < 0) {
145 fprintf(stderr
, "dist: Can't open default components file!!\n");
148 VOID
copy(m_maildir(draft
), drft
);
149 if((out
= open(drft
, 0)) >= 0) {
150 if(!fdcompare(in
, out
)) {
151 cp
= concat("\"", drft
, "\" exists; Delete? ", 0);
152 while((msgnum
= gans(cp
, anyl
)) == 2)
159 if((out
= creat(drft
, m_gmprot())) < 0) {
160 fprintf(stderr
, "Can't create \"%s\"\n", drft
);
165 if((in
= open(cp
= m_name(mp
->lowsel
), 0)) < 0) {
166 fprintf(stderr
, "Can't open message \"%s\"\n", cp
);
173 m_replace(pfolder
, folder
);
174 if(mp
->lowsel
!= mp
->curmsg
)
175 m_setcur(mp
->lowsel
);
176 if(m_edit(&ed
, drft
, NOUSE
, NULLCP
) < 0)
179 fprintf(stderr
, "!! Test Version of SEND Being Run !!\n");
180 fprintf(stderr
, " Send verbose !\n\n");
184 if(!(argp
= getans("\nWhat now? ", aleqs
)))
186 switch(smatch(*argp
, aleqs
)) {
187 case 0: VOID
showfile(drft
); /* list */
190 case 1: if(*++argp
) /* edit */
192 if(m_edit(&ed
, drft
, NOUSE
, NULLCP
) == -1)
196 case 2: if(*++argp
&& (*argp
[0] == 'd' || /* quit */
197 (*argp
[0]=='-' && *argp
[1]=='d')))
198 if(unlink(drft
) == -1) {
199 fprintf(stderr
, "Can't unlink %s ", drft
);
204 if(!mp
->msgflags
&READONLY
) { /* annotate first */
206 while((pid
= fork()) == -1) sleep(5);
208 while((wpid
=wait((int *)NULL
))!= -1
215 VOID
m_send(++argp
, drft
);
218 default:fprintf(stderr
, "dist: illegal option\n"); /*##*/
235 if((i
= read(in
, buf
, sizeof buf
)) > 0)
236 if(write(out
, buf
, i
) != i
) {
237 fprintf(stderr
, "dist: error on ");
241 while(i
== sizeof buf
);
248 char name
[NAMESZ
], field
[256];
252 if(stat(drft
, (struct stat
*)field
) != -1) {
253 fprintf(stderr
, "%s not sent-- no annotations made.\n", drft
);
256 text
= copy(drft
, field
);
260 while(--text
>= field
&& *text
!= '/');
261 *++text
= ','; /* New backup convention */
262 if((in
= fopen(field
, "r")) == NULL
) {
263 fprintf(stderr
, "Can't open %s\n", field
);
268 for(;;) switch(state
= m_getfld(state
, name
, field
, sizeof field
, in
)) {
273 if(uleq(name
, "distribute-to") ||
274 uleq(name
, "distribute-cc") ) {
276 text
= add(name
, text
);
277 text
= add(":", text
);
279 text
= add(field
, text
);
288 fprintf(stderr
, "Getfld returned %d\n", state
);
294 annotate(m_name(mp
->lowsel
), "Distributed", text
, inplace
);