]>
diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/uip/repl.c
1 /* repl.c - reply to a message */
3 static char ident
[] = "@(#)$Id: repl.c,v 1.9 1995/12/06 21:07:03 jromine Exp $";
15 #define MIMEminc(a) (a)
22 static struct swit switches
[] = {
34 "draftfolder +folder", 0,
36 "draftmessage msg", 0,
49 "filter filterfile", 0,
66 "nomime", MIMEminc(-6),
74 "whatnowproc program", 0,
85 "file file", -4, /* interface from msh */
89 "build", -5, /* interface from mhe */
96 static struct swit ccswitches
[] = {
111 static struct swit aqrnl
[] = {
127 static struct swit aqrl
[] = {
144 short ccto
= CCDFLT
; /* global for replsbr */
148 short outputlinelen
= OUTPUTLINELEN
;
153 char *fcc
= NULL
; /* global for replsbr */
189 struct msgs
*mp
= NULL
;
194 setlocale(LC_ALL
, "");
196 invo_name
= r1bindex (argv
[0], '/');
197 if ((cp
= m_find (invo_name
)) != NULL
) {
198 ap
= brkstring (cp
= getcpy (cp
), " ", "\n");
199 ap
= copyip (ap
, arguments
);
203 (void) copyip (argv
+ 1, ap
);
208 while (cp
= *argp
++) {
210 switch (smatch (++cp
, switches
)) {
212 ambigsw (cp
, switches
);
215 adios (NULLCP
, "-%s unknown", cp
);
217 (void) sprintf (buf
, "%s: [+folder] [msg] [switches]",
219 help (buf
, switches
);
230 if (!(cp
= *argp
++) || *cp
== '-')
231 adios (NULLCP
, "missing argument to %s", argp
[-2]);
235 if (!(cp
= *argp
++) || *cp
== '-')
236 adios (NULLCP
, "missing argument to %s", argp
[-2]);
241 if (!(ed
= *argp
++) || *ed
== '-')
242 adios (NULLCP
, "missing argument to %s", argp
[-2]);
250 if (!(whatnowproc
= *argp
++) || *whatnowproc
== '-')
251 adios (NULLCP
, "missing argument to %s", argp
[-2]);
256 buildsw
++; /* fall... */
263 if (!(cp
= *argp
++) || *cp
== '-')
264 adios (NULLCP
, "missing argument to %s", argp
[-2]);
267 cp
= dp
= path (cp
+ 1, TSUBCWF
);
269 fcc
= add (", ", fcc
);
277 adios (NULLCP
, "only one file at a time!");
278 if (!(cp
= *argp
++) || *cp
== '-')
279 adios (NULLCP
, "missing argument to %s", argp
[-2]);
280 file
= path (cp
, TFILE
);
283 if (!(cp
= *argp
++) || *cp
== '-')
284 adios (NULLCP
, "missing argument to %s", argp
[-2]);
285 filter
= getcpy (libpath (cp
));
289 if (!(form
= *argp
++) || *form
== '-')
290 adios (NULLCP
, "missing argument to %s", argp
[-2]);
325 if (!(cp
= *argp
++) || *cp
== '-')
326 adios (NULLCP
, "missing argument to %s", argp
[-2]);
327 if ((outputlinelen
= atoi (cp
)) < 10)
328 adios (NULLCP
, "impossible width %d", outputlinelen
);
333 adios (NULLCP
, "only one draft folder at a time!");
334 if (!(cp
= *argp
++) || *cp
== '-')
335 adios (NULLCP
, "missing argument to %s", argp
[-2]);
336 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
337 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
341 adios (NULLCP
, "only one draft message at a time!");
342 if (!(dmsg
= *argp
++) || *dmsg
== '-')
343 adios (NULLCP
, "missing argument to %s", argp
[-2]);
350 if (*cp
== '+' || *cp
== '@') {
352 adios (NULLCP
, "only one folder at a time!");
354 folder
= path (cp
+ 1, *cp
== '+' ? TFOLDER
: TSUBCWF
);
358 adios (NULLCP
, "only one message at a time!");
365 cwd
= getcpy (pwd ());
367 if (!m_find ("path"))
368 free (path ("./", TFOLDER
));
369 if (file
&& (msg
|| folder
))
370 adios (NULLCP
, "can't mix files and folders/msgs");
374 (void) strcpy (drft
, m_draft (dfolder
, dmsg
, NOUSE
, &isdf
));
375 if (stat (drft
, &st
) != NOTOK
) {
377 (void) strcpy (drft
, buildsw
? m_maildir ("reply")
378 : m_draft (dfolder
, NULLCP
, NOUSE
, &isdf
));
379 if (!buildsw
&& stat (drft
, &st
) != NOTOK
) {
381 printf ("Draft \"%s\" exists (%ld bytes).", drft
, st
.st_size
);
382 for (i
= LISTDSW
; i
!= YESW
;) {
383 if (!(argp
= getans ("\nDisposition? ", isdf
? aqrnl
: aqrl
)))
385 switch (i
= smatch (*argp
, isdf
? aqrnl
: aqrl
)) {
394 (void) showfile (++argp
, drft
);
397 if (refile (++argp
, drft
) == 0)
401 advise (NULLCP
, "say what?");
417 folder
= m_getfolder ();
418 maildir
= m_maildir (folder
);
420 if (chdir (maildir
) == NOTOK
)
421 adios (maildir
, "unable to change directory to");
422 if (!(mp
= m_gmsg (folder
)))
423 adios (NULLCP
, "unable to read folder %s", folder
);
424 if (mp
-> hghmsg
== 0)
425 adios (NULLCP
, "no messages in %s", folder
);
427 if (!m_convert (mp
, msg
))
431 if (mp
-> numsel
> 1)
432 adios (NULLCP
, "only one message at a time!");
434 m_replace (pfolder
, folder
);
435 if (mp
-> lowsel
!= mp
-> curmsg
)
436 m_setcur (mp
, mp
-> lowsel
);
441 msg
= file
? file
: getcpy (m_name (mp
-> lowsel
));
443 if ((in
= fopen (msg
, "r")) == NULL
)
444 adios (msg
, "unable to open");
446 replout (in
, msg
, drft
, mp
);
451 (void) what_now (ed
, nedit
, NOUSE
, drft
, msg
, 0, mp
,
452 anot
? "Replied" : NULLCP
, inplace
, cwd
);
462 switch (smatch (cp
, ccswitches
)) {
464 ambigsw (cp
, ccswitches
);
467 adios (NULLCP
, "-%scc %s unknown", ccflag
? "" : "no", cp
);
482 ccto
= cccc
= ccme
= ccflag
;