- if (drft)
- adios (NULL, "only one draft at a time!");
- else
- drft = cp;
- }
-
- if ((drft == NULL && (drft = getenv ("mhdraft")) == NULL) || *drft == 0)
- drft = getcpy (m_draft (dfolder, dmsg, 1, &isdf));
-
- msgnam = (cp = getenv ("mhaltmsg")) && *cp ? getcpy (cp) : NULL;
-
- if ((cp = getenv ("mhuse")) && *cp)
- use = atoi (cp);
-
- if (ed == NULL && ((ed = getenv ("mheditor")) == NULL || *ed == 0)) {
- ed = NULL;
- nedit++;
- }
-
- /* start editing the draft, unless -noedit was given */
- if (!nedit && editfile (&ed, NULL, drft, use, NULL, msgnam, NULL, 1) < 0)
- done (1);
-
- snprintf (prompt, sizeof(prompt), myprompt, invo_name);
- for (;;) {
- if (!(argp = getans (prompt, aleqs))) {
- unlink (LINK);
- done (1);
- }
- switch (smatch (*argp, aleqs)) {
- case DISPSW:
- /* display the message being replied to, or distributed */
- if (msgnam)
- showfile (++argp, msgnam);
- else
- advise (NULL, "no alternate message to display");
- break;
-
- case BUILDMIMESW:
- /* Translate MIME composition file */
- buildfile (++argp, drft);
- break;
-
- case EDITSW:
- /* Call an editor on the draft file */
- if (*++argp)
- ed = *argp++;
- if (editfile (&ed, argp, drft, NOUSE, NULL, msgnam, NULL, 1) == NOTOK)
- done (1);
- break;
-
- case LISTSW:
- /* display the draft file */
- showfile (++argp, drft);
- break;
-
- case WHOMSW:
- /* Check to whom the draft would be sent */
- whomfile (++argp, drft);
- break;
-
- case QUITSW:
- /* Quit, and possibly delete the draft */
- if (*++argp && (*argp[0] == 'd' ||
- ((*argp)[0] == '-' && (*argp)[1] == 'd'))) {
- removefile (drft);
- } else {
- if (stat (drft, &st) != NOTOK)
- advise (NULL, "draft left on %s", drft);
- }
- done (1);
-
- case DELETESW:
- /* Delete draft and exit */
- removefile (drft);
- done (1);
-
- case PUSHSW:
- /* Send draft in background */
- if (sendfile (++argp, drft, 1))
- done (1);
- break;
-
- case SENDSW:
- /* Send draft */
- sendfile (++argp, drft, 0);
- break;
-
- case REFILEOPT:
- /* Refile the draft */
- if (refile (++argp, drft) == 0)
- done (0);
- break;
-
- case CDCMDSW:
- /* Change the working directory for attachments
- *
- * Run the directory through the user's shell so that
- * we can take advantage of any syntax that the user
- * is accustomed to. Read back the absolute path.
- */
-
- if (*++argp == (char *)0) {
- (void)sprintf(buf, "$SHELL -c \"cd;pwd\"");
- }
- else if (strlen(*argp) >= BUFSIZ) {
- adios((char *)0, "arguments too long");
- }
- else {
- (void)sprintf(buf, "$SHELL -c \"cd %s;cd %s;pwd\"", cwd, *argp);
- }
- if ((f = popen(buf, "r")) != (FILE *)0) {
- fgets(cwd, sizeof (cwd), f);
-
- if (strchr(cwd, '\n') != (char *)0)
- *strchr(cwd, '\n') = '\0';
-
- pclose(f);
- }
- else {
- advise("popen", "could not get directory");
- }
-
- break;
-
- case PWDCMDSW:
- /* Print the working directory for attachments */
- printf("%s\n", cwd);
- break;
-
- case LSCMDSW:
- /* List files in the current attachment working directory
- *
- * Use the user's shell so that we can take advantage of any
- * syntax that the user is accustomed to.
- */
- writelscmd(buf, sizeof(buf), cwd, argp);
- (void)system(buf);
- break;
-
- case ALISTCMDSW:
- /*
- * List attachments on current draft. Options are:
- *
- * -l long listing (full path names)
- * -n numbers listing
- */
-
- if (attach == (char *)0) {
- advise((char *)0, "can't list because no header field name was given.");
- break;
- }
-
- l = (char *)0;
- n = 0;
-
- while (*++argp != (char *)0) {
- if (strcmp(*argp, "-l") == 0)
- l = "/";
-
- else if (strcmp(*argp, "-n") == 0)
- n = 1;
-
- else if (strcmp(*argp, "-ln") == 0 || strcmp(*argp, "-nl") == 0) {
- l = "/";
- n = 1;
- }