/* repl.c - reply to a message */
static char ident
[] = "@(#)$Id: repl.c,v 1.8 1992/12/15 00:20:22 jromine Exp $";
static struct swit switches
[] = {
"draftfolder +folder", 0,
"whatnowproc program", 0,
"file file", -4, /* interface from msh */
"build", -5, /* interface from mhe */
static struct swit ccswitches
[] = {
static struct swit aqrnl
[] = {
static struct swit aqrl
[] = {
short ccto
= CCDFLT
; /* global for replsbr */
short outputlinelen
= OUTPUTLINELEN
;
char *fcc
= NULL
; /* global for replsbr */
invo_name
= r1bindex (argv
[0], '/');
if ((cp
= m_find (invo_name
)) != NULL
) {
ap
= brkstring (cp
= getcpy (cp
), " ", "\n");
ap
= copyip (ap
, arguments
);
(void) copyip (argv
+ 1, ap
);
switch (smatch (++cp
, switches
)) {
adios (NULLCP
, "-%s unknown", cp
);
(void) sprintf (buf
, "%s: [+folder] [msg] [switches]",
if (!(cp
= *argp
++) || *cp
== '-')
adios (NULLCP
, "missing argument to %s", argp
[-2]);
if (!(cp
= *argp
++) || *cp
== '-')
adios (NULLCP
, "missing argument to %s", argp
[-2]);
if (!(ed
= *argp
++) || *ed
== '-')
adios (NULLCP
, "missing argument to %s", argp
[-2]);
if (!(whatnowproc
= *argp
++) || *whatnowproc
== '-')
adios (NULLCP
, "missing argument to %s", argp
[-2]);
if (!(cp
= *argp
++) || *cp
== '-')
adios (NULLCP
, "missing argument to %s", argp
[-2]);
cp
= dp
= path (cp
+ 1, TSUBCWF
);
adios (NULLCP
, "only one file at a time!");
if (!(cp
= *argp
++) || *cp
== '-')
adios (NULLCP
, "missing argument to %s", argp
[-2]);
if (!(cp
= *argp
++) || *cp
== '-')
adios (NULLCP
, "missing argument to %s", argp
[-2]);
filter
= getcpy (libpath (cp
));
if (!(form
= *argp
++) || *form
== '-')
adios (NULLCP
, "missing argument to %s", argp
[-2]);
if (!(cp
= *argp
++) || *cp
== '-')
adios (NULLCP
, "missing argument to %s", argp
[-2]);
if ((outputlinelen
= atoi (cp
)) < 10)
adios (NULLCP
, "impossible width %d", outputlinelen
);
adios (NULLCP
, "only one draft folder at a time!");
if (!(cp
= *argp
++) || *cp
== '-')
adios (NULLCP
, "missing argument to %s", argp
[-2]);
dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
*cp
!= '@' ? TFOLDER
: TSUBCWF
);
adios (NULLCP
, "only one draft message at a time!");
if (!(dmsg
= *argp
++) || *dmsg
== '-')
adios (NULLCP
, "missing argument to %s", argp
[-2]);
if (*cp
== '+' || *cp
== '@') {
adios (NULLCP
, "only one folder at a time!");
folder
= path (cp
+ 1, *cp
== '+' ? TFOLDER
: TSUBCWF
);
adios (NULLCP
, "only one message at a time!");
free (path ("./", TFOLDER
));
if (file
&& (msg
|| folder
))
adios (NULLCP
, "can't mix files and folders/msgs");
(void) strcpy (drft
, m_draft (dfolder
, dmsg
, NOUSE
, &isdf
));
if (stat (drft
, &st
) != NOTOK
) {
(void) strcpy (drft
, buildsw
? m_maildir ("reply")
: m_draft (dfolder
, NULLCP
, NOUSE
, &isdf
));
if (!buildsw
&& stat (drft
, &st
) != NOTOK
) {
printf ("Draft \"%s\" exists (%ld bytes).", drft
, st
.st_size
);
for (i
= LISTDSW
; i
!= YESW
;) {
if (!(argp
= getans ("\nDisposition? ", isdf
? aqrnl
: aqrl
)))
switch (i
= smatch (*argp
, isdf
? aqrnl
: aqrl
)) {
(void) showfile (++argp
, drft
);
if (refile (++argp
, drft
) == 0)
advise (NULLCP
, "say what?");
maildir
= m_maildir (folder
);
if (chdir (maildir
) == NOTOK
)
adios (maildir
, "unable to change directory to");
if (!(mp
= m_gmsg (folder
)))
adios (NULLCP
, "unable to read folder %s", folder
);
adios (NULLCP
, "no messages in %s", folder
);
if (!m_convert (mp
, msg
))
adios (NULLCP
, "only one message at a time!");
m_replace (pfolder
, folder
);
if (mp
-> lowsel
!= mp
-> curmsg
)
m_setcur (mp
, mp
-> lowsel
);
msg
= file
? file
: getcpy (m_name (mp
-> lowsel
));
if ((in
= fopen (msg
, "r")) == NULL
)
adios (msg
, "unable to open");
(void) what_now (ed
, nedit
, NOUSE
, drft
, msg
, 0, mp
,
anot
? "Replied" : NULLCP
, inplace
, cwd
);
switch (smatch (cp
, ccswitches
)) {
ambigsw (cp
, ccswitches
);
adios (NULLCP
, "-%scc %s unknown", ccflag
? "" : "no", cp
);
ccto
= cccc
= ccme
= ccflag
;