]>
diplodocus.org Git - nmh/blob - uip/repl.c
3 * repl.c -- reply to a message
11 static struct swit switches
[] = {
21 { "cc all|to|cc|me", 0 },
25 { "draftfolder +folder", 0 },
27 { "draftmessage msg", 0 },
29 { "nodraftfolder", 0 },
31 { "editor editor", 0 },
37 { "filter filterfile", 0 },
39 { "form formfile", 0 },
57 { "whatnowproc program", 0 },
59 { "nowhatnowproc", 0 },
61 { "width columns", 0 },
67 { "file file", 4 }, /* interface from msh */
71 { "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
;
150 setlocale(LC_ALL
, "");
152 invo_name
= r1bindex (argv
[0], '/');
154 /* read user profile/context */
157 arguments
= getarguments (invo_name
, argc
, argv
, 1);
160 while ((cp
= *argp
++)) {
162 switch (smatch (++cp
, switches
)) {
164 ambigsw (cp
, switches
);
167 adios (NULL
, "-%s unknown", cp
);
170 snprintf (buf
, sizeof(buf
), "%s: [+folder] [msg] [switches]",
172 print_help (buf
, switches
, 1);
175 print_version(invo_name
);
193 if (!(cp
= *argp
++) || *cp
== '-')
194 adios (NULL
, "missing argument to %s", argp
[-2]);
198 if (!(cp
= *argp
++) || *cp
== '-')
199 adios (NULL
, "missing argument to %s", argp
[-2]);
204 if (!(ed
= *argp
++) || *ed
== '-')
205 adios (NULL
, "missing argument to %s", argp
[-2]);
213 if (!(whatnowproc
= *argp
++) || *whatnowproc
== '-')
214 adios (NULL
, "missing argument to %s", argp
[-2]);
219 buildsw
++; /* fall... */
226 if (!(cp
= *argp
++) || *cp
== '-')
227 adios (NULL
, "missing argument to %s", argp
[-2]);
230 cp
= dp
= path (cp
+ 1, TSUBCWF
);
232 fcc
= add (", ", fcc
);
240 adios (NULL
, "only one file at a time!");
241 if (!(cp
= *argp
++) || *cp
== '-')
242 adios (NULL
, "missing argument to %s", argp
[-2]);
243 file
= path (cp
, TFILE
);
246 if (!(cp
= *argp
++) || *cp
== '-')
247 adios (NULL
, "missing argument to %s", argp
[-2]);
248 filter
= getcpy (etcpath (cp
));
252 if (!(form
= *argp
++) || *form
== '-')
253 adios (NULL
, "missing argument to %s", argp
[-2]);
257 filter
= getcpy (etcpath (mhlreply
));
287 if (!(cp
= *argp
++) || *cp
== '-')
288 adios (NULL
, "missing argument to %s", argp
[-2]);
289 if ((outputlinelen
= atoi (cp
)) < 10)
290 adios (NULL
, "impossible width %d", outputlinelen
);
295 adios (NULL
, "only one draft folder at a time!");
296 if (!(cp
= *argp
++) || *cp
== '-')
297 adios (NULL
, "missing argument to %s", argp
[-2]);
298 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
299 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
303 adios (NULL
, "only one draft message at a time!");
304 if (!(dmsg
= *argp
++) || *dmsg
== '-')
305 adios (NULL
, "missing argument to %s", argp
[-2]);
313 if (*cp
== '+' || *cp
== '@') {
315 adios (NULL
, "only one folder at a time!");
317 folder
= path (cp
+ 1, *cp
== '+' ? TFOLDER
: TSUBCWF
);
320 adios (NULL
, "only one message at a time!");
333 cwd
= getcpy (pwd ());
335 if (!context_find ("path"))
336 free (path ("./", TFOLDER
));
337 if (file
&& (msg
|| folder
))
338 adios (NULL
, "can't mix files and folders/msgs");
343 strncpy (drft
, buildsw
? m_maildir ("reply")
344 : m_draft (dfolder
, NULL
, NOUSE
, &isdf
), sizeof(drft
));
346 /* Check if a draft exists */
347 if (!buildsw
&& stat (drft
, &st
) != NOTOK
) {
349 strncpy (drft
, m_draft (dfolder
, dmsg
, NOUSE
, &isdf
), sizeof(drft
));
351 /* Check if a draft exists */
352 if (stat (drft
, &st
) != NOTOK
) {
354 printf ("Draft \"%s\" exists (%ld bytes).", drft
, (long) st
.st_size
);
355 for (i
= LISTDSW
; i
!= YESW
;) {
356 if (!(argp
= getans ("\nDisposition? ", isdf
? aqrnl
: aqrl
)))
358 switch (i
= smatch (*argp
, isdf
? aqrnl
: aqrl
)) {
367 showfile (++argp
, drft
);
370 if (refile (++argp
, drft
) == 0)
374 advise (NULL
, "say what?");
382 * We are replying to a file.
384 anot
= 0; /* we don't want to annotate a file */
387 * We are replying to a message.
392 folder
= getfolder (1);
393 maildir
= m_maildir (folder
);
395 if (chdir (maildir
) == NOTOK
)
396 adios (maildir
, "unable to change directory to");
398 /* read folder and create message structure */
399 if (!(mp
= folder_read (folder
)))
400 adios (NULL
, "unable to read folder %s", folder
);
402 /* check for empty folder */
404 adios (NULL
, "no messages in %s", folder
);
406 /* parse the message range/sequence/name and set SELECTED */
407 if (!m_convert (mp
, msg
))
409 seq_setprev (mp
); /* set the previous-sequence */
412 adios (NULL
, "only one message at a time!");
414 context_replace (pfolder
, folder
); /* update current folder */
415 seq_setcur (mp
, mp
->lowsel
); /* update current message */
416 seq_save (mp
); /* synchronize sequences */
417 context_save (); /* save the context file */
420 msg
= file
? file
: getcpy (m_name (mp
->lowsel
));
422 if ((in
= fopen (msg
, "r")) == NULL
)
423 adios (msg
, "unable to open");
425 /* find form (components) file */
428 form
= etcpath (replgroupcomps
);
430 form
= etcpath (replcomps
);
433 replout (in
, msg
, drft
, mp
, outputlinelen
, mime
, form
, filter
, fcc
);
438 what_now (ed
, nedit
, NOUSE
, drft
, msg
, 0, mp
,
439 anot
? "Replied" : NULL
, inplace
, cwd
);
444 docc (char *cp
, int ccflag
)
446 switch (smatch (cp
, ccswitches
)) {
448 ambigsw (cp
, ccswitches
);
451 adios (NULL
, "-%scc %s unknown", ccflag
? "" : "no", cp
);
466 ccto
= cccc
= ccme
= ccflag
;