]>
diplodocus.org Git - nmh/blob - sbr/m_draft.c
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.
17 m_draft (char *folder
, char *msg
, int use
, int *isdf
)
20 register struct msgs
*mp
;
22 static char buffer
[BUFSIZ
];
24 if (*isdf
== -1 || folder
== NULL
|| *folder
== '\0') {
25 if (*isdf
== -1 || (cp
= context_find ("Draft-Folder")) == NULL
) {
27 return m_maildir (msg
&& *msg
? msg
: draft
);
29 folder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
30 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
35 chdir (m_maildir (""));
36 strncpy (buffer
, m_maildir (folder
), sizeof(buffer
));
37 if (stat (buffer
, &st
) == -1) {
39 adios (buffer
, "error on folder");
40 cp
= concat ("Create folder \"", buffer
, "\"? ", NULL
);
44 if (!makedir (buffer
))
45 adios (NULL
, "unable to create folder %s", buffer
);
48 if (chdir (buffer
) == -1)
49 adios (buffer
, "unable to change directory to");
51 if (!(mp
= folder_read (folder
)))
52 adios (NULL
, "unable to read folder %s", folder
);
55 * Make sure we have enough message status space for all
56 * the message numbers from 1 to "new", since we might
57 * select an empty slot. If we add more space at the
58 * end, go ahead and add 10 additional slots.
60 if (mp
->hghmsg
>= mp
->hghoff
) {
61 if (!(mp
= folder_realloc (mp
, 1, mp
->hghmsg
+ 10)))
62 adios (NULL
, "unable to allocate folder storage");
63 } else if (mp
->lowoff
> 1) {
64 if (!(mp
= folder_realloc (mp
, 1, mp
->hghoff
)))
65 adios (NULL
, "unable to allocate folder storage");
68 mp
->msgflags
|= ALLOW_NEW
; /* allow the "new" sequence */
71 * If we have been give a valid message name, then use that.
72 * Else, if we are given the "use" option, then use the
73 * current message. Else, use special sequence "new".
75 if (!m_convert (mp
, msg
&& *msg
? msg
: use
? "cur" : "new"))
80 adios (NULL
, "only one message draft at a time!");
82 snprintf (buffer
, sizeof(buffer
), "%s/%s", mp
->foldpath
, m_name (mp
->lowsel
));
85 seq_setcur (mp
, mp
->lowsel
);/* set current message for folder */
86 seq_save (mp
); /* synchronize message sequences */
87 folder_free (mp
); /* free folder/message structure */