3 * m_draft.c -- construct the name of a draft 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.
19 m_draft (char *folder, char *msg, int use, int *isdf)
22 register struct msgs *mp;
24 static char buffer[BUFSIZ];
26 if (*isdf == -1 || folder == NULL || *folder == '\0') {
27 if (*isdf == -1 || (cp = context_find ("Draft-Folder")) == NULL) {
29 return m_maildir (msg && *msg ? msg : draft);
31 folder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp,
32 *cp != '@' ? TFOLDER : TSUBCWF);
37 chdir (m_maildir (""));
38 strncpy (buffer, m_maildir (folder), sizeof(buffer));
39 if (stat (buffer, &st) == -1) {
41 adios (buffer, "error on folder");
42 cp = concat ("Create folder \"", buffer, "\"? ", NULL);
46 if (!makedir (buffer))
47 adios (NULL, "unable to create folder %s", buffer);
50 if (chdir (buffer) == -1)
51 adios (buffer, "unable to change directory to");
53 if (!(mp = folder_read (folder)))
54 adios (NULL, "unable to read folder %s", folder);
57 * Make sure we have enough message status space for all
58 * the message numbers from 1 to "new", since we might
59 * select an empty slot. If we add more space at the
60 * end, go ahead and add 10 additional slots.
62 if (mp->hghmsg >= mp->hghoff) {
63 if (!(mp = folder_realloc (mp, 1, mp->hghmsg + 10)))
64 adios (NULL, "unable to allocate folder storage");
65 } else if (mp->lowoff > 1) {
66 if (!(mp = folder_realloc (mp, 1, mp->hghoff)))
67 adios (NULL, "unable to allocate folder storage");
70 mp->msgflags |= ALLOW_NEW; /* allow the "new" sequence */
73 * If we have been give a valid message name, then use that.
74 * Else, if we are given the "use" option, then use the
75 * current message. Else, use special sequence "new".
77 if (!m_convert (mp, msg && *msg ? msg : use ? "cur" : "new"))
82 adios (NULL, "only one message draft at a time!");
84 snprintf (buffer, sizeof(buffer), "%s/%s", mp->foldpath, m_name (mp->lowsel));
87 seq_setcur (mp, mp->lowsel);/* set current message for folder */
88 seq_save (mp); /* synchronize message sequences */
89 folder_free (mp); /* free folder/message structure */