]>
diplodocus.org Git - nmh/blob - docs/historical/2.9BSD/cmds/reply.c
21 "edit [<editor>]", 0, /* 1 */
22 "quit [delete]", 0, /* 2 */
23 "send [verbose]", 0, /* 3 */
27 int *vec
[MAXARGS
], anot
;
31 int inplace
; /* preserve links in anno */
33 struct swit switches
[] = {
34 "annotate", 0, /* 0 */
35 "noannotate", 0, /* 1 */
38 "editor editor", 0, /* 4 */
40 "noinplace", 0, /* 6 */
54 char *folder
, *nfolder
, *msg
, *maildir
;
55 register char *cp
, **ap
;
57 char *arguments
[50], **argp
;
62 msg
= 0; anot
= 0; folder
= 0;
64 cp
= r1bindex(argv
[0], '/');
65 if((cp
= m_find(cp
)) != NULL
) {
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:fprintf(stderr
, "repl: -%s unknown\n", cp
);
80 case 0: anot
= 1; continue; /* -annotate */
81 case 1: anot
= 0; continue; /* -noannotate */
82 case 2: ccme
= 1; continue; /* -ccme */
83 case 3: ccme
= 0; continue; /* -noccme */
84 case 4: if(!(ed
= *argp
++)) { /* -editor */
85 fprintf(stderr
, "repl: Missing argument for %s switch\n", argp
[-2]);
89 case 5: inplace
= 1; continue; /* -inplace */
90 case 6: inplace
= 0; continue; /* -noinplace */
92 case 7: help("repl [+folder] [msg] [switches]",
98 fprintf(stderr
, "Only one folder at a time.\n");
103 fprintf(stderr
, "Only one message per reply.\n");
111 folder
= m_getfolder();
112 maildir
= m_maildir(folder
);
113 if(chdir(maildir
) < 0) {
114 fprintf(stderr
, "Can't chdir to: ");
118 if(!(mp
= m_gmsg(folder
))) {
119 fprintf(stderr
, "Can't read folder!?\n");
122 if(mp
->hghmsg
== 0) {
123 fprintf(stderr
, "No messages in \"%s\".\n", folder
);
128 if(mp
->numsel
== 0) {
129 fprintf(stderr
, "repl: pepperoni pizza\n");/* never get here */
133 fprintf(stderr
, "Only one message at a time.\n");
136 m_replace(pfolder
, folder
);
137 if(mp
->lowsel
!= mp
->curmsg
)
138 m_setcur(mp
->lowsel
);
139 repl(getcpy(m_name(mp
->lowsel
)));
151 char name
[NAMESZ
], field
[BUFSIZ
];
152 char *drft
, *msgid
, *replto
, *from
, *cc
, *sub
, *date
, *to
;
153 int state
, out
, status
, intr
;
155 char **argp
, *address
;
157 if((in
= fopen(msg
, "r")) == NULL
) {
158 fprintf(stderr
, "Can't open "); perror(msg
);
161 drft
= m_maildir(draft
);
162 if((out
= open(drft
, 0)) >= 0) {
163 cp
= concat("\"", drft
, "\" exists; delete? ", 0);
164 while((i
= gans(cp
, anyl
)) == 2)
171 if((out
= creat(drft
, m_gmprot())) < 0) {
172 fprintf(stderr
, "Can't create \"%s\".\n", drft
);
177 replto
= msgid
= to
= from
= cc
= sub
= date
= 0;
181 switch(state
= m_getfld(state
, name
, field
, sizeof field
, in
)) {
186 if(uleq(name
, "from"))
187 from
= niceadd(field
, from
);
189 cc
= niceadd(field
, cc
);
190 if(uleq(name
, "subject"))
191 sub
= niceadd(field
, sub
);
192 if(uleq(name
, "date"))
193 date
= niceadd(field
, date
);
195 to
= niceadd(field
, to
);
196 if(uleq(name
, "message-id"))
197 msgid
= niceadd(field
, msgid
);
198 if(uleq(name
, "reply-to"))
199 replto
= niceadd(field
, replto
);
200 /* if(uleq(name, "sender"))
201 sender = niceadd(field, sender); */
212 fprintf(stderr
, "getfld returned %d\n", state
);
220 /* if(!(address = addr(sender)))
221 if(!(address = addr(from)))
222 address = addr(replto);
224 /* if(!(address = addr(replto)))
225 address = addr(from);
227 address
= replto
? addr(replto
) : addr(from
);
230 if(!(from
|| replto
)) {
231 fprintf(stderr
, "No one to reply to!!!\n");
235 type(out
, "To: "); /* To: */
236 type(out
, replto
? replto
: from
);
237 if(cc
|| to
) /* cc: */
241 cc
= fix(cc
, address
);
250 to
= fix(to
, address
);
253 if(sub
) { /* Subject: Re: */
254 type(out
, "Subject: ");
255 if(*sub
== ' ') sub
++;
256 if((sub
[0] != 'R' && sub
[0] != 'r') ||
257 (sub
[1] != 'E' && sub
[1] != 'e') ||
263 type(out
, "In-reply-to: Your message of ");
264 date
[strlen(date
)-1] = '.';
265 if(*date
== ' ') date
++;
270 if(*msgid
== ' ') msgid
++;
274 type(out
, "----------\n");
276 if(m_edit(&ed
, drft
, NOUSE
, msg
) < 0)
279 fprintf(stderr
, "!! Test Version of SEND Being Run !!\n");
280 fprintf(stderr
, " Send verbose !\n\n");
284 if(!(argp
= getans("\nWhat now? ", aleqs
))) {
288 switch(smatch(*argp
, aleqs
)) {
289 case 0: showfile(drft
); /* list */
291 case 1: if(*++argp
) /* edit */
293 if(m_edit(&ed
, drft
, NOUSE
, msg
) == -1)
296 case 2: if(*++argp
&& *argp
[0] == 'd') /* quit */
297 if(unlink(drft
) == -1) {
298 fprintf(stderr
, "Can't unlink %s ", drft
);
302 case 3: if(*++argp
) cp
= *argp
; else cp
= ""; /* send */
304 if(!mp
->msgflags
&READONLY
) { /* annotate first */
306 while((pid
= fork()) == -1) sleep(5);
308 while(wpid
=wait((int *)NULL
)!= -1 && wpid
!= pid
);
309 if(stat(drft
, field
) == -1)
310 annotate(msg
, "Replied", "", inplace
);
315 if(!m_send(cp
, drft
))
317 default:fprintf(stderr
, "repl: illegal option\n"); /*##*/