]>
diplodocus.org Git - nmh/blob - sbr/m_draft.c
1f42a1a3ad50b985a85ef09fce28814989837f4f
1 /* m_draft.c -- construct the name of a draft message
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.
9 #include "seq_setcur.h"
12 #include "m_convert.h"
13 #include "folder_read.h"
14 #include "folder_realloc.h"
15 #include "folder_free.h"
16 #include "context_find.h"
20 #include "m_maildir.h"
24 /* Does not return NULL. */
26 m_draft (char *folder
, char *msg
, int use
, int *isdf
)
30 static char buffer
[BUFSIZ
];
32 if (*isdf
== -1 || folder
== NULL
|| *folder
== '\0') {
33 if (*isdf
== -1 || (cp
= context_find ("Draft-Folder")) == NULL
) {
35 return m_maildir (msg
&& *msg
? msg
: draft
);
38 folder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
39 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
43 if (chdir (m_maildir ("")) < 0) {
44 advise (m_maildir (""), "chdir");
46 strncpy (buffer
, m_maildir (folder
), sizeof(buffer
));
48 create_folder (buffer
, 0, done
);
50 if (chdir (buffer
) == -1)
51 adios (buffer
, "unable to change directory to");
53 if (!(mp
= folder_read (folder
, 1)))
54 die("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 die("unable to allocate folder storage");
65 } else if (mp
->lowoff
> 1) {
66 if (!(mp
= folder_realloc (mp
, 1, mp
->hghoff
)))
67 die("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 die("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 */