]> diplodocus.org Git - nmh/blob - sbr/m_draft.c
uip/flist.c: Make locally defined and used functions static.
[nmh] / sbr / m_draft.c
1 /* m_draft.c -- construct the name of a draft message
2 *
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
6 */
7
8 #include <h/mh.h>
9 #include <h/utils.h>
10
11
12 char *
13 m_draft (char *folder, char *msg, int use, int *isdf)
14 {
15 char *cp;
16 struct msgs *mp;
17 static char buffer[BUFSIZ];
18
19 if (*isdf == -1 || folder == NULL || *folder == '\0') {
20 if (*isdf == -1 || (cp = context_find ("Draft-Folder")) == NULL) {
21 *isdf = 0;
22 return m_maildir (msg && *msg ? msg : draft);
23 }
24
25 folder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp,
26 *cp != '@' ? TFOLDER : TSUBCWF);
27 }
28 *isdf = 1;
29
30 if (chdir (m_maildir ("")) < 0) {
31 advise (m_maildir (""), "chdir");
32 }
33 strncpy (buffer, m_maildir (folder), sizeof(buffer));
34
35 create_folder (buffer, 0, done);
36
37 if (chdir (buffer) == -1)
38 adios (buffer, "unable to change directory to");
39
40 if (!(mp = folder_read (folder, 1)))
41 adios (NULL, "unable to read folder %s", folder);
42
43 /*
44 * Make sure we have enough message status space for all
45 * the message numbers from 1 to "new", since we might
46 * select an empty slot. If we add more space at the
47 * end, go ahead and add 10 additional slots.
48 */
49 if (mp->hghmsg >= mp->hghoff) {
50 if (!(mp = folder_realloc (mp, 1, mp->hghmsg + 10)))
51 adios (NULL, "unable to allocate folder storage");
52 } else if (mp->lowoff > 1) {
53 if (!(mp = folder_realloc (mp, 1, mp->hghoff)))
54 adios (NULL, "unable to allocate folder storage");
55 }
56
57 mp->msgflags |= ALLOW_NEW; /* allow the "new" sequence */
58
59 /*
60 * If we have been give a valid message name, then use that.
61 * Else, if we are given the "use" option, then use the
62 * current message. Else, use special sequence "new".
63 */
64 if (!m_convert (mp, msg && *msg ? msg : use ? "cur" : "new"))
65 done (1);
66 seq_setprev (mp);
67
68 if (mp->numsel > 1)
69 adios (NULL, "only one message draft at a time!");
70
71 snprintf (buffer, sizeof(buffer), "%s/%s", mp->foldpath, m_name (mp->lowsel));
72 cp = buffer;
73
74 seq_setcur (mp, mp->lowsel);/* set current message for folder */
75 seq_save (mp); /* synchronize message sequences */
76 folder_free (mp); /* free folder/message structure */
77
78 return cp;
79 }