2 ** folder_read.c -- initialize folder structure and read folder
4 ** This code is Copyright (c) 2002, by the authors of nmh. See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
16 ** 1) Create the folder/message structure
17 ** 2) Read the directory (folder) and temporarily
18 ** record the numbers of the messages we have seen.
19 ** 3) Then allocate the array for message attributes and
20 ** set the initial flags for all messages we've seen.
21 ** 4) Read and initialize the sequence information.
27 msgnumcmp(const struct dirent **d1, const struct dirent **d2)
31 l1 = strlen((*d1)->d_name);
32 l2 = strlen((*d2)->d_name);
39 return strcmp((*d1)->d_name, (*d2)->d_name);
43 msgfilter(const struct dirent *e)
46 /* For compatibility with nmh, ignore rmm backup files. */
47 if (e->d_name[0] == '.' || e->d_name[0] == ',' || e->d_name[0] == '#') {
50 for (i = 0; e->d_name[i]; i++) {
51 if ((i == 0 && e->d_name[i] == '0') || e->d_name[i] < '0' || e->d_name[i] > '9') {
60 folder_read(char *name)
68 name = mh_xstrdup(toabsdir(name));
70 if (stat(name, &st) == -1) {
75 /* Allocate the main structure for folder information */
76 mp = mh_xcalloc(1, sizeof(*mp));
80 if (access(name, W_OK) == -1)
83 mp->nummsg = scandir(name, &dp, msgfilter, msgnumcmp);
94 mp->lowmsg = m_atoi(dp[0]->d_name);
95 mp->hghmsg = m_atoi(dp[mp->nummsg-1]->d_name);
97 mp->lowoff = max(mp->lowmsg, 1);
98 mp->hghoff = mp->hghmsg + 100;
99 mp->msgstats = mh_xcalloc(MSGSTATSIZE(mp, mp->lowoff, mp->hghoff), 1);
100 for (i = 0; i < mp->nummsg; i++) {
101 set_exists(mp, m_atoi(dp[i]->d_name));
107 ** Read and initialize the sequence information.