]>
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 */
74 { "build", 5 }, /* interface from mhe */
80 static struct swit ccswitches
[] = {
92 static struct swit aqrnl
[] = {
100 { "refile +folder", 0 },
106 static struct swit aqrl
[] = {
110 { "refile +folder", 0 },
114 short ccto
= -1; /* global for replsbr */
119 short outputlinelen
= OUTPUTLINELEN
;
120 short groupreply
= 0; /* Is this a group reply? */
122 int mime
= 0; /* include original as MIME part */
123 char *form
= NULL
; /* form (components) file */
124 char *filter
= NULL
; /* message filter file */
125 char *fcc
= NULL
; /* folders to add to Fcc: header */
131 void docc (char *, int);
135 main (int argc
, char **argv
)
138 int anot
= 0, inplace
= 1;
139 int nedit
= 0, nwhat
= 0;
140 char *cp
, *cwd
, *dp
, *maildir
, *file
= NULL
;
141 char *folder
= NULL
, *msg
= NULL
, *dfolder
= NULL
;
142 char *dmsg
= NULL
, *ed
= NULL
, drft
[BUFSIZ
], buf
[BUFSIZ
];
143 char **argp
, **arguments
;
144 struct msgs
*mp
= NULL
;
153 setlocale(LC_ALL
, "");
155 invo_name
= r1bindex (argv
[0], '/');
157 /* read user profile/context */
160 arguments
= getarguments (invo_name
, argc
, argv
, 1);
163 while ((cp
= *argp
++)) {
165 switch (smatch (++cp
, switches
)) {
167 ambigsw (cp
, switches
);
170 adios (NULL
, "-%s unknown", cp
);
173 snprintf (buf
, sizeof(buf
), "%s: [+folder] [msg] [switches]",
175 print_help (buf
, switches
, 1);
178 print_version(invo_name
);
196 if (!(cp
= *argp
++) || *cp
== '-')
197 adios (NULL
, "missing argument to %s", argp
[-2]);
201 if (!(cp
= *argp
++) || *cp
== '-')
202 adios (NULL
, "missing argument to %s", argp
[-2]);
207 if (!(ed
= *argp
++) || *ed
== '-')
208 adios (NULL
, "missing argument to %s", argp
[-2]);
216 if (!(whatnowproc
= *argp
++) || *whatnowproc
== '-')
217 adios (NULL
, "missing argument to %s", argp
[-2]);
222 buildsw
++; /* fall... */
229 if (!(cp
= *argp
++) || *cp
== '-')
230 adios (NULL
, "missing argument to %s", argp
[-2]);
233 cp
= dp
= path (cp
+ 1, TSUBCWF
);
235 fcc
= add (", ", fcc
);
243 adios (NULL
, "only one file at a time!");
244 if (!(cp
= *argp
++) || *cp
== '-')
245 adios (NULL
, "missing argument to %s", argp
[-2]);
246 file
= path (cp
, TFILE
);
249 if (!(cp
= *argp
++) || *cp
== '-')
250 adios (NULL
, "missing argument to %s", argp
[-2]);
251 filter
= getcpy (etcpath (cp
));
255 if (!(form
= *argp
++) || *form
== '-')
256 adios (NULL
, "missing argument to %s", argp
[-2]);
260 filter
= getcpy (etcpath (mhlreply
));
290 if (!(cp
= *argp
++) || *cp
== '-')
291 adios (NULL
, "missing argument to %s", argp
[-2]);
292 if ((outputlinelen
= atoi (cp
)) < 10)
293 adios (NULL
, "impossible width %d", outputlinelen
);
298 adios (NULL
, "only one draft folder at a time!");
299 if (!(cp
= *argp
++) || *cp
== '-')
300 adios (NULL
, "missing argument to %s", argp
[-2]);
301 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
302 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
306 adios (NULL
, "only one draft message at a time!");
307 if (!(dmsg
= *argp
++) || *dmsg
== '-')
308 adios (NULL
, "missing argument to %s", argp
[-2]);
316 if (*cp
== '+' || *cp
== '@') {
318 adios (NULL
, "only one folder at a time!");
320 folder
= pluspath (cp
);
323 adios (NULL
, "only one message at a time!");
336 cwd
= getcpy (pwd ());
338 if (!context_find ("path"))
339 free (path ("./", TFOLDER
));
340 if (file
&& (msg
|| folder
))
341 adios (NULL
, "can't mix files and folders/msgs");
346 strncpy (drft
, buildsw
? m_maildir ("reply")
347 : m_draft (dfolder
, NULL
, NOUSE
, &isdf
), sizeof(drft
));
349 /* Check if a draft exists */
350 if (!buildsw
&& stat (drft
, &st
) != NOTOK
) {
352 strncpy (drft
, m_draft (dfolder
, dmsg
, NOUSE
, &isdf
), sizeof(drft
));
354 /* Check if a draft exists */
355 if (stat (drft
, &st
) != NOTOK
) {
357 printf ("Draft \"%s\" exists (%ld bytes).", drft
, (long) st
.st_size
);
358 for (i
= LISTDSW
; i
!= YESW
;) {
359 if (!(argp
= getans ("\nDisposition? ", isdf
? aqrnl
: aqrl
)))
361 switch (i
= smatch (*argp
, isdf
? aqrnl
: aqrl
)) {
370 showfile (++argp
, drft
);
373 if (refile (++argp
, drft
) == 0)
377 advise (NULL
, "say what?");
385 * We are replying to a file.
387 anot
= 0; /* we don't want to annotate a file */
390 * We are replying to a message.
395 folder
= getfolder (1);
396 maildir
= m_maildir (folder
);
398 if (chdir (maildir
) == NOTOK
)
399 adios (maildir
, "unable to change directory to");
401 /* read folder and create message structure */
402 if (!(mp
= folder_read (folder
)))
403 adios (NULL
, "unable to read folder %s", folder
);
405 /* check for empty folder */
407 adios (NULL
, "no messages in %s", folder
);
409 /* parse the message range/sequence/name and set SELECTED */
410 if (!m_convert (mp
, msg
))
412 seq_setprev (mp
); /* set the previous-sequence */
415 adios (NULL
, "only one message at a time!");
417 context_replace (pfolder
, folder
); /* update current folder */
418 seq_setcur (mp
, mp
->lowsel
); /* update current message */
419 seq_save (mp
); /* synchronize sequences */
420 context_save (); /* save the context file */
423 msg
= file
? file
: getcpy (m_name (mp
->lowsel
));
425 if ((in
= fopen (msg
, "r")) == NULL
)
426 adios (msg
, "unable to open");
428 /* find form (components) file */
431 form
= etcpath (replgroupcomps
);
433 form
= etcpath (replcomps
);
436 replout (in
, msg
, drft
, mp
, outputlinelen
, mime
, form
, filter
, fcc
);
441 what_now (ed
, nedit
, NOUSE
, drft
, msg
, 0, mp
,
442 anot
? "Replied" : NULL
, inplace
, cwd
);
448 docc (char *cp
, int ccflag
)
450 switch (smatch (cp
, ccswitches
)) {
452 ambigsw (cp
, ccswitches
);
455 adios (NULL
, "-%scc %s unknown", ccflag
? "" : "no", cp
);
470 ccto
= cccc
= ccme
= ccflag
;