]>
diplodocus.org Git - nmh/blob - uip/repl.c
3 * repl.c -- reply to a message
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
14 static struct swit switches
[] = {
24 { "cc all|to|cc|me", 0 },
28 { "draftfolder +folder", 0 },
30 { "draftmessage msg", 0 },
32 { "nodraftfolder", 0 },
34 { "editor editor", 0 },
40 { "filter filterfile", 0 },
42 { "form formfile", 0 },
60 { "whatnowproc program", 0 },
62 { "nowhatnowproc", 0 },
64 { "width columns", 0 },
70 { "file file", 4 }, /* interface from msh */
72 { "build", 5 }, /* interface from mhe */
77 static struct swit ccswitches
[] = {
89 static struct swit aqrnl
[] = {
97 { "refile +folder", 0 },
103 static struct swit aqrl
[] = {
107 { "refile +folder", 0 },
111 short ccto
= -1; /* global for replsbr */
116 short outputlinelen
= OUTPUTLINELEN
;
117 short groupreply
= 0; /* Is this a group reply? */
119 int mime
= 0; /* include original as MIME part */
120 char *form
= NULL
; /* form (components) file */
121 char *filter
= NULL
; /* message filter file */
122 char *fcc
= NULL
; /* folders to add to Fcc: header */
128 void docc (char *, int);
132 main (int argc
, char **argv
)
135 int anot
= 0, inplace
= 1;
136 int nedit
= 0, nwhat
= 0;
137 char *cp
, *cwd
, *dp
, *maildir
, *file
= NULL
;
138 char *folder
= NULL
, *msg
= NULL
, *dfolder
= NULL
;
139 char *dmsg
= NULL
, *ed
= NULL
, drft
[BUFSIZ
], buf
[BUFSIZ
];
140 char **argp
, **arguments
;
141 struct msgs
*mp
= NULL
;
148 setlocale(LC_ALL
, "");
150 invo_name
= r1bindex (argv
[0], '/');
152 /* read user profile/context */
155 arguments
= getarguments (invo_name
, argc
, argv
, 1);
158 while ((cp
= *argp
++)) {
160 switch (smatch (++cp
, switches
)) {
162 ambigsw (cp
, switches
);
165 adios (NULL
, "-%s unknown", cp
);
168 snprintf (buf
, sizeof(buf
), "%s: [+folder] [msg] [switches]",
170 print_help (buf
, switches
, 1);
173 print_version(invo_name
);
191 if (!(cp
= *argp
++) || *cp
== '-')
192 adios (NULL
, "missing argument to %s", argp
[-2]);
196 if (!(cp
= *argp
++) || *cp
== '-')
197 adios (NULL
, "missing argument to %s", argp
[-2]);
202 if (!(ed
= *argp
++) || *ed
== '-')
203 adios (NULL
, "missing argument to %s", argp
[-2]);
211 if (!(whatnowproc
= *argp
++) || *whatnowproc
== '-')
212 adios (NULL
, "missing argument to %s", argp
[-2]);
216 buildsw
++; /* fall... */
222 if (!(cp
= *argp
++) || *cp
== '-')
223 adios (NULL
, "missing argument to %s", argp
[-2]);
226 cp
= dp
= path (cp
+ 1, TSUBCWF
);
228 fcc
= add (", ", fcc
);
236 adios (NULL
, "only one file at a time!");
237 if (!(cp
= *argp
++) || *cp
== '-')
238 adios (NULL
, "missing argument to %s", argp
[-2]);
239 file
= path (cp
, TFILE
);
242 if (!(cp
= *argp
++) || *cp
== '-')
243 adios (NULL
, "missing argument to %s", argp
[-2]);
244 filter
= getcpy (etcpath (cp
));
248 if (!(form
= *argp
++) || *form
== '-')
249 adios (NULL
, "missing argument to %s", argp
[-2]);
253 filter
= getcpy (etcpath (mhlreply
));
283 if (!(cp
= *argp
++) || *cp
== '-')
284 adios (NULL
, "missing argument to %s", argp
[-2]);
285 if ((outputlinelen
= atoi (cp
)) < 10)
286 adios (NULL
, "impossible width %d", outputlinelen
);
291 adios (NULL
, "only one draft folder at a time!");
292 if (!(cp
= *argp
++) || *cp
== '-')
293 adios (NULL
, "missing argument to %s", argp
[-2]);
294 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
295 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
299 adios (NULL
, "only one draft message at a time!");
300 if (!(dmsg
= *argp
++) || *dmsg
== '-')
301 adios (NULL
, "missing argument to %s", argp
[-2]);
309 if (*cp
== '+' || *cp
== '@') {
311 adios (NULL
, "only one folder at a time!");
313 folder
= pluspath (cp
);
316 adios (NULL
, "only one message at a time!");
329 cwd
= getcpy (pwd ());
331 if (!context_find ("path"))
332 free (path ("./", TFOLDER
));
333 if (file
&& (msg
|| folder
))
334 adios (NULL
, "can't mix files and folders/msgs");
338 strncpy (drft
, buildsw
? m_maildir ("reply")
339 : m_draft (dfolder
, NULL
, NOUSE
, &isdf
), sizeof(drft
));
341 /* Check if a draft exists */
342 if (!buildsw
&& stat (drft
, &st
) != NOTOK
) {
343 printf ("Draft \"%s\" exists (%ld bytes).", drft
, (long) st
.st_size
);
344 for (i
= LISTDSW
; i
!= YESW
;) {
345 if (!(argp
= getans ("\nDisposition? ", isdf
? aqrnl
: aqrl
)))
347 switch (i
= smatch (*argp
, isdf
? aqrnl
: aqrl
)) {
356 showfile (++argp
, drft
);
359 if (refile (++argp
, drft
) == 0)
363 advise (NULL
, "say what?");
371 * We are replying to a file.
373 anot
= 0; /* we don't want to annotate a file */
376 * We are replying to a message.
381 folder
= getfolder (1);
382 maildir
= m_maildir (folder
);
384 if (chdir (maildir
) == NOTOK
)
385 adios (maildir
, "unable to change directory to");
387 /* read folder and create message structure */
388 if (!(mp
= folder_read (folder
)))
389 adios (NULL
, "unable to read folder %s", folder
);
391 /* check for empty folder */
393 adios (NULL
, "no messages in %s", folder
);
395 /* parse the message range/sequence/name and set SELECTED */
396 if (!m_convert (mp
, msg
))
398 seq_setprev (mp
); /* set the previous-sequence */
401 adios (NULL
, "only one message at a time!");
403 context_replace (pfolder
, folder
); /* update current folder */
404 seq_setcur (mp
, mp
->lowsel
); /* update current message */
405 seq_save (mp
); /* synchronize sequences */
406 context_save (); /* save the context file */
409 msg
= file
? file
: getcpy (m_name (mp
->lowsel
));
411 if ((in
= fopen (msg
, "r")) == NULL
)
412 adios (msg
, "unable to open");
414 /* find form (components) file */
417 form
= etcpath (replgroupcomps
);
419 form
= etcpath (replcomps
);
422 replout (in
, msg
, drft
, mp
, outputlinelen
, mime
, form
, filter
, fcc
);
427 what_now (ed
, nedit
, NOUSE
, drft
, msg
, 0, mp
,
428 anot
? "Replied" : NULL
, inplace
, cwd
);
434 docc (char *cp
, int ccflag
)
436 switch (smatch (cp
, ccswitches
)) {
438 ambigsw (cp
, ccswitches
);
441 adios (NULL
, "-%scc %s unknown", ccflag
? "" : "no", cp
);
456 ccto
= cccc
= ccme
= ccflag
;