9 date 92.10.20.22.46.29; author jromine; state Exp;
14 date 92.05.12.22.11.10; author jromine; state Exp;
19 date 92.02.11.21.32.04; author jromine; state Exp;
24 date 92.02.05.06.40.22; author jromine; state Exp;
29 date 92.02.03.16.35.10; author jromine; state Exp;
34 date 90.04.05.15.30.20; author sources; state Exp;
39 date 90.04.05.14.43.48; author sources; state Exp;
44 date 90.03.20.15.57.29; author sources; state Exp;
49 date 90.02.06.13.08.58; author sources; state Exp;
54 date 90.02.01.14.07.33; author sources; state Exp;
59 date 89.11.17.15.57.24; author sources; state Exp;
64 date 89.06.26.14.31.47; author sources; state Exp;
78 @/* m_gmsg.c - read a folder */
80 static char ident[] = "@@(#)$Id: m_gmsg.c,v 2.9 1992/05/12 22:11:10 jromine Exp jromine $";
84 #include "../h/local.h"
88 #define NINFO (MAXFOLDER / 5) /* PLEASE be non-trivial... */
95 static struct info *head;
98 static int m_setatr();
101 struct msgs *m_gmsg (name)
110 register struct info *rover,
116 register struct msgs *mp;
118 register struct dirent *dp;
121 register struct direct *dp;
126 if ((dd = opendir (name = m_mailpath (name))) == NULL) {
130 (void) fstat (dd -> dd_fd, &st);
132 mp = (struct msgs *) malloc (MHSIZE (mp, 0, 0));
134 adios (NULLCP, "unable to allocate folder storage");
135 mp -> lowmsg = mp -> hghmsg = mp -> nummsg = 0;
137 mp -> lowsel = mp -> hghsel = mp -> numsel = 0;
138 mp -> foldpath = name;
140 if (st.st_uid != getuid () || access (name, 02) == NOTOK)
141 mp -> msgflags |= READONLY;
145 j = strlen (SBACKUP);
147 if ((head = (struct info *)
148 malloc ((unsigned) ((len = NINFO) * sizeof *head))) == NULL)
149 adios (NULLCP, "unable to allocate info storage");
150 tail = (rover = head) + len;
152 while (dp = readdir (dd))
153 if (i = m_atoi (dp -> d_name)) {
155 register int curlen = tail - head;
157 if ((tail = (struct info *) realloc ((char *) head,
158 (unsigned) ((len += NINFO) * sizeof *head)))
160 adios (NULLCP, "unable to allocate info storage");
162 rover = tail + curlen, head = tail, tail += len;
164 if (i > mp -> hghmsg)
167 if (mp -> lowmsg == 0 || i < mp -> lowmsg)
170 rover -> stats = EXISTS;
172 rover -> stats &= ~DELETED;
177 switch (dp -> d_name[0]) {
183 if ((i = m_atoi (dp -> d_name + 1)) {
184 register struct info *l;
186 for (l = head; l < rover; l++)
187 if (l -> msgno == i) {
188 if (!(l -> stats & EXISTS))
189 l -> stats |= DELETED;
209 if (strcmp (dp -> d_name, current) == 0) {
214 if (strcmp (dp -> d_name, LINK) == 0
215 || strncmp (dp -> d_name, SBACKUP, j) == 0)
217 mp -> msgflags |= OTHERS;
226 (void) sprintf (buffer, "%s-%s", current, name);
227 if (cp = m_find (buffer)) {
229 (void) m_delete(buffer);
233 if (mp -> curmsg == 0 && cur && (fd = open (current, 0)) != NOTOK) {
234 if ((i = read (fd, buffer, sizeof buffer)) > 0) {
235 if (cp = index (buffer, '\n'))
237 if ((i = m_atoi (buffer)) > 0)
242 if (cur && !(mp -> msgflags & READONLY)){ /* sneaky... */
243 (void) sprintf (buffer, "%s/%s", name, current);
244 (void) unlink (buffer);
251 mp -> lowoff = mp -> lowmsg;
253 mp -> hghoff = mp -> hghmsg + 1;/* for "new" in m_convert */
256 realloc ((char *) mp, MHSIZE (mp, mp -> lowoff, mp -> hghoff));
258 adios (NULLCP, "unable to allocate folder storage");
260 for (i = mp -> lowmsg; i <= mp -> hghmsg; i++)
261 mp -> msgstats[i] = 0;
263 mp -> msgstats = (int *)
264 calloc ((unsigned) 1, MHSIZEX (mp, mp -> lowmsg, mp -> hghmsg));
265 if (mp -> msgstats == NULL)
266 adios (NULLCP, "unable to allocate messages storage");
267 mp -> msgstats = (mp -> msgbase = mp -> msgstats) - mp -> lowoff;
268 if (mp -> msgstats < (int *)0) /* non portable */
269 adios (NULLCP, "m_gmsg() botch -- you lose big");
271 for (tail = head; tail < rover; tail++)
272 mp -> msgstats[tail -> msgno] = tail -> stats;
281 register struct msgs *mp;
292 register struct node *np;
297 mp -> msgattrs[i = 0] = getcpy (current);
298 mp -> msgattrs[++i] = '\0';
299 mp -> attrstats = 0; /* initially, all public */
302 if (mh_seq == '\0' || *mh_seq == '\0')
305 (void) sprintf (field, "%s/%s", mp -> foldpath, mh_seq);
306 if (fp = fopen (field, "r")) {
307 for (state = FLD;;) {
308 switch (state = m_getfld (state, name, field, sizeof field, fp)) {
311 (void) m_setatr (mp, getcpy (name), trimcpy (field));
319 "no blank lines are permitted in %s/%s",
320 mp -> foldpath, mh_seq);/* fall */
326 adios (NULLCP, "%s/%s is poorly formatted",
327 mp -> foldpath, mh_seq);
335 alen = strlen ("atr-");
336 plen = strlen (mp -> foldpath) + 1;
338 for (np = m_defs; np; np = np -> n_next)
339 if (ssequal ("atr-", np -> n_name)
340 && (j = strlen (np -> n_name) - plen) > alen
341 && *(np -> n_name + j) == '-'
342 && strcmp (mp -> foldpath, np -> n_name + j + 1) == 0) {
343 cp = getcpy (np -> n_name + alen);
344 *(cp + j - alen) = '\0';
345 if ((i = m_setatr (mp, cp, getcpy (np -> n_field))) != NOTOK)
346 mp -> attrstats |= 1 << (bits + i);/* private */
352 static int m_setatr (mp, name, field)
353 register struct msgs *mp;
366 hack = strcmp (current, name) == 0;/* hack... */
367 /* if we're going to use UNSEEN, it should be set here! */
369 for (i = 0; mp -> msgattrs[i]; i++)
370 if (strcmp (mp -> msgattrs[i], name) == 0) {
371 for (j = mp -> lowmsg; j <= mp -> hghmsg; j++)
372 mp -> msgstats[j] &= ~(1 << (bits + i));
381 if (mp -> msgattrs[i] == NULL) {
382 mp -> msgattrs[i] = name;
383 mp -> msgattrs[i + 1] = NULL;
388 for (ap = brkstring (field, " ", "\n");
391 if (cp = index (*ap, '-'))
393 if ((j = m_atoi (*ap)) > 0) {
395 if (hack && j >= mp -> lowmsg && j <= mp -> hghmsg
396 && (mp -> msgstats[j] & EXISTS))
398 #else /* not notdef */
401 #endif /* not notdef */
402 for (k = cp ? m_atoi (cp) : j; j <= k; j++)
403 if (j >= mp -> lowmsg && j <= mp -> hghmsg
404 && (mp -> msgstats[j] & EXISTS))
405 mp -> msgstats[j] |= 1 << (bits + i);
422 static char ident[] = "@@(#)$Id: m_gmsg.c,v 2.8 1992/02/11 21:32:04 jromine Exp jromine $";
431 @put sequences in an "int"
436 static char ident[] = "@@(#)$Id: m_gmsg.c,v 2.7 1992/02/05 06:40:22 jromine Exp $";
452 mp -> msgflags = NULL;
488 mp -> msgattrs[++i] = NULL;
491 if (mh_seq == NULL || *mh_seq == NULL)
494 *(cp + j - alen) = NULL;
514 static char ident[] = "@@(#)$Id: m_gmsg.c,v 2.6 1992/02/03 16:35:10 jromine Exp jromine $";
518 char pad[sizeof (int) - sizeof (short)];
521 mp -> msgstats = (short *)
524 if (mp -> msgstats < (short *)0) /* non portable */
535 static char ident[] = "@@(#)$Id: m_gmsg.c,v 2.5 1990/04/05 15:30:20 sources Exp jromine $";
547 static char ident[] = "@@(#)$Id:$";
550 mp = (struct msgs *) malloc (MSIZE (mp, 0, 0));
553 realloc ((char *) mp, MSIZE (mp, mp -> lowoff, mp -> hghoff));
556 calloc ((unsigned) 1, MSIZEX (mp, mp -> lowmsg, mp -> hghmsg));
567 static char ident[] = "$Id:";
587 if (mp -> msgstats < 0)
593 @increase message sequence buffer size by factor of 2. I hope this
594 is worth it, since it'll make things bigger.
603 @changes for SUN40 shared libraries and NNTP under bbc