]>
diplodocus.org Git - nmh/blob - uip/repl.c
3 * repl.c -- reply to a message
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
15 static struct swit switches
[] = {
25 { "cc all|to|cc|me", 0 },
29 { "draftfolder +folder", 0 },
31 { "draftmessage msg", 0 },
33 { "nodraftfolder", 0 },
35 { "editor editor", 0 },
41 { "filter filterfile", 0 },
43 { "form formfile", 0 },
61 { "whatnowproc program", 0 },
63 { "nowhatnowproc", 0 },
65 { "width columns", 0 },
71 { "file file", 4 }, /* interface from msh */
75 { "build", 5 }, /* interface from mhe */
81 static struct swit ccswitches
[] = {
93 static struct swit aqrnl
[] = {
101 { "refile +folder", 0 },
107 static struct swit aqrl
[] = {
111 { "refile +folder", 0 },
115 short ccto
= -1; /* global for replsbr */
120 short outputlinelen
= OUTPUTLINELEN
;
121 short groupreply
= 0; /* Is this a group reply? */
123 int mime
= 0; /* include original as MIME part */
124 char *form
= NULL
; /* form (components) file */
125 char *filter
= NULL
; /* message filter file */
126 char *fcc
= NULL
; /* folders to add to Fcc: header */
132 void docc (char *, int);
136 main (int argc
, char **argv
)
139 int anot
= 0, inplace
= 1;
140 int nedit
= 0, nwhat
= 0;
141 char *cp
, *cwd
, *dp
, *maildir
, *file
= NULL
;
142 char *folder
= NULL
, *msg
= NULL
, *dfolder
= NULL
;
143 char *dmsg
= NULL
, *ed
= NULL
, drft
[BUFSIZ
], buf
[BUFSIZ
];
144 char **argp
, **arguments
;
145 struct msgs
*mp
= NULL
;
154 setlocale(LC_ALL
, "");
156 invo_name
= r1bindex (argv
[0], '/');
158 /* read user profile/context */
161 arguments
= getarguments (invo_name
, argc
, argv
, 1);
164 while ((cp
= *argp
++)) {
166 switch (smatch (++cp
, switches
)) {
168 ambigsw (cp
, switches
);
171 adios (NULL
, "-%s unknown", cp
);
174 snprintf (buf
, sizeof(buf
), "%s: [+folder] [msg] [switches]",
176 print_help (buf
, switches
, 1);
179 print_version(invo_name
);
197 if (!(cp
= *argp
++) || *cp
== '-')
198 adios (NULL
, "missing argument to %s", argp
[-2]);
202 if (!(cp
= *argp
++) || *cp
== '-')
203 adios (NULL
, "missing argument to %s", argp
[-2]);
208 if (!(ed
= *argp
++) || *ed
== '-')
209 adios (NULL
, "missing argument to %s", argp
[-2]);
217 if (!(whatnowproc
= *argp
++) || *whatnowproc
== '-')
218 adios (NULL
, "missing argument to %s", argp
[-2]);
223 buildsw
++; /* fall... */
230 if (!(cp
= *argp
++) || *cp
== '-')
231 adios (NULL
, "missing argument to %s", argp
[-2]);
234 cp
= dp
= path (cp
+ 1, TSUBCWF
);
236 fcc
= add (", ", fcc
);
244 adios (NULL
, "only one file at a time!");
245 if (!(cp
= *argp
++) || *cp
== '-')
246 adios (NULL
, "missing argument to %s", argp
[-2]);
247 file
= path (cp
, TFILE
);
250 if (!(cp
= *argp
++) || *cp
== '-')
251 adios (NULL
, "missing argument to %s", argp
[-2]);
252 filter
= getcpy (etcpath (cp
));
256 if (!(form
= *argp
++) || *form
== '-')
257 adios (NULL
, "missing argument to %s", argp
[-2]);
261 filter
= getcpy (etcpath (mhlreply
));
291 if (!(cp
= *argp
++) || *cp
== '-')
292 adios (NULL
, "missing argument to %s", argp
[-2]);
293 if ((outputlinelen
= atoi (cp
)) < 10)
294 adios (NULL
, "impossible width %d", outputlinelen
);
299 adios (NULL
, "only one draft folder at a time!");
300 if (!(cp
= *argp
++) || *cp
== '-')
301 adios (NULL
, "missing argument to %s", argp
[-2]);
302 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
303 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
307 adios (NULL
, "only one draft message at a time!");
308 if (!(dmsg
= *argp
++) || *dmsg
== '-')
309 adios (NULL
, "missing argument to %s", argp
[-2]);
317 if (*cp
== '+' || *cp
== '@') {
319 adios (NULL
, "only one folder at a time!");
321 folder
= path (cp
+ 1, *cp
== '+' ? TFOLDER
: TSUBCWF
);
324 adios (NULL
, "only one message at a time!");
337 cwd
= getcpy (pwd ());
339 if (!context_find ("path"))
340 free (path ("./", TFOLDER
));
341 if (file
&& (msg
|| folder
))
342 adios (NULL
, "can't mix files and folders/msgs");
347 strncpy (drft
, buildsw
? m_maildir ("reply")
348 : m_draft (dfolder
, NULL
, NOUSE
, &isdf
), sizeof(drft
));
350 /* Check if a draft exists */
351 if (!buildsw
&& stat (drft
, &st
) != NOTOK
) {
353 strncpy (drft
, m_draft (dfolder
, dmsg
, NOUSE
, &isdf
), sizeof(drft
));
355 /* Check if a draft exists */
356 if (stat (drft
, &st
) != NOTOK
) {
358 printf ("Draft \"%s\" exists (%ld bytes).", drft
, (long) st
.st_size
);
359 for (i
= LISTDSW
; i
!= YESW
;) {
360 if (!(argp
= getans ("\nDisposition? ", isdf
? aqrnl
: aqrl
)))
362 switch (i
= smatch (*argp
, isdf
? aqrnl
: aqrl
)) {
371 showfile (++argp
, drft
);
374 if (refile (++argp
, drft
) == 0)
378 advise (NULL
, "say what?");
386 * We are replying to a file.
388 anot
= 0; /* we don't want to annotate a file */
391 * We are replying to a message.
396 folder
= getfolder (1);
397 maildir
= m_maildir (folder
);
399 if (chdir (maildir
) == NOTOK
)
400 adios (maildir
, "unable to change directory to");
402 /* read folder and create message structure */
403 if (!(mp
= folder_read (folder
)))
404 adios (NULL
, "unable to read folder %s", folder
);
406 /* check for empty folder */
408 adios (NULL
, "no messages in %s", folder
);
410 /* parse the message range/sequence/name and set SELECTED */
411 if (!m_convert (mp
, msg
))
413 seq_setprev (mp
); /* set the previous-sequence */
416 adios (NULL
, "only one message at a time!");
418 context_replace (pfolder
, folder
); /* update current folder */
419 seq_setcur (mp
, mp
->lowsel
); /* update current message */
420 seq_save (mp
); /* synchronize sequences */
421 context_save (); /* save the context file */
424 msg
= file
? file
: getcpy (m_name (mp
->lowsel
));
426 if ((in
= fopen (msg
, "r")) == NULL
)
427 adios (msg
, "unable to open");
429 /* find form (components) file */
432 form
= etcpath (replgroupcomps
);
434 form
= etcpath (replcomps
);
437 replout (in
, msg
, drft
, mp
, outputlinelen
, mime
, form
, filter
, fcc
);
442 what_now (ed
, nedit
, NOUSE
, drft
, msg
, 0, mp
,
443 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
;