1 /* comp.c - compose a message */
3 static char ident[] = "@(#)$Id: comp.c,v 1.7 1992/12/15 00:20:22 jromine Exp $";
16 static struct swit switches[] = {
18 "draftfolder +folder", 0,
20 "draftmessage msg", 0,
40 "whatnowproc program", 0,
53 static struct swit aqrunl[] = {
71 static struct swit aqrul[] = {
110 struct msgs *mp = NULL;
114 setlocale(LC_ALL, "");
116 invo_name = r1bindex (argv[0], '/');
117 if ((cp = m_find (invo_name)) != NULL) {
118 ap = brkstring (cp = getcpy (cp), " ", "\n");
119 ap = copyip (ap, arguments);
123 (void) copyip (argv + 1, ap);
128 while (cp = *argp++) {
130 switch (smatch (++cp, switches)) {
132 ambigsw (cp, switches);
135 adios (NULLCP, "-%s unknown", cp);
137 (void) sprintf (buf, "%s [+folder] [msg] [switches]",
139 help (buf, switches);
143 if (!(ed = *argp++) || *ed == '-')
144 adios (NULLCP, "missing argument to %s", argp[-2]);
152 if (!(whatnowproc = *argp++) || *whatnowproc == '-')
153 adios (NULLCP, "missing argument to %s", argp[-2]);
161 if (!(form = *argp++) || *form == '-')
162 adios (NULLCP, "missing argument to %s", argp[-2]);
172 case FILESW: /* compatibility */
174 adios (NULLCP, "only one file at a time!");
175 if (!(file = *argp++) || *file == '-')
176 adios (NULLCP, "missing argument to %s", argp[-2]);
182 adios (NULLCP, "only one draft folder at a time!");
183 if (!(cp = *argp++) || *cp == '-')
184 adios (NULLCP, "missing argument to %s", argp[-2]);
185 dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp,
186 *cp != '@' ? TFOLDER : TSUBCWF);
190 adios (NULLCP, "only one draft message at a time!");
191 if (!(file = *argp++) || *file == '-')
192 adios (NULLCP, "missing argument to %s", argp[-2]);
199 if (*cp == '+' || *cp == '@') {
201 adios (NULLCP, "only one folder at a time!");
203 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
207 adios (NULLCP, "only one message at a time!");
214 cwd = getcpy (pwd ());
216 if (!m_find ("path"))
217 free (path ("./", TFOLDER));
219 if ((dfolder || m_find ("Draft-Folder")) && !folder && msg && !file)
220 file = msg, msg = NULL;
221 if (form && (folder || msg))
222 adios (NULLCP, "can't mix forms and folders/msgs");
228 folder = m_getfolder ();
229 maildir = m_maildir (folder);
231 if (chdir (maildir) == NOTOK)
232 adios (maildir, "unable to change directory to");
233 if (!(mp = m_gmsg (folder)))
234 adios (NULLCP, "unable to read folder %s", folder);
235 if (mp -> hghmsg == 0)
236 adios (NULLCP, "no messages in %s", folder);
238 if (!m_convert (mp, msg))
242 if (mp -> numsel > 1)
243 adios (NULLCP, "only one message at a time!");
245 if ((in = open (form = getcpy (m_name (mp -> lowsel)), 0)) == NOTOK)
246 adios (form, "unable to open message");
250 if ((in = open (libpath (form), 0)) == NOTOK)
251 adios (form, "unable to open form file");
254 if ((in = open (libpath (components), 0)) == NOTOK)
255 adios (components, "unable to open default components file");
262 (void) strcpy (drft, m_draft (dfolder, file, use, &isdf));
263 if ((out = open (drft, 0)) != NOTOK) {
264 i = fdcompare (in, out);
269 if (stat (drft, &st) == NOTOK)
270 adios (drft, "unable to stat");
271 printf ("Draft \"%s\" exists (%ld bytes).", drft, st.st_size);
272 for (i = LISTDSW; i != YESW;) {
273 if (!(argp = getans ("\nDisposition? ", isdf ? aqrunl : aqrul)))
275 switch (i = smatch (*argp, isdf ? aqrunl : aqrul)) {
288 (void) showfile (++argp, drft);
291 if (refile (++argp, drft) == 0)
295 advise (NULLCP, "say what?");
302 adios (drft, "unable to open");
304 if ((out = creat (drft, m_gmprot ())) == NOTOK)
305 adios (drft, "unable to create");
306 cpydata (in, out, form, drft);
315 (void) what_now (ed, nedit, use, drft, NULLCP, 0, NULLMP, NULLCP, 0, cwd);