- /*
- * Scan to the end of this message range
- */
- for (++i; i <= mp->hghmsg && does_exist(mp, i) && in_sequence(mp, seqnum, i);
- ++i)
- ;
-
- if (i - j > 1) {
- sprintf(bp, "-%s", m_name(i - 1));
- bp += strlen(bp);
+ /* If the folder is empty, just return NULL */
+ if (mp->nummsg == 0)
+ return NULL;
+
+ /* Get the index of the sequence */
+ if ((seqnum = seq_getnum(mp, seqname)) == -1)
+ return NULL;
+
+ bp = buffer;
+
+ for (i = mp->lowoff; i <= mp->hghoff; ++i) {
+ /* If message isn't in the sequence, then continue */
+ if (!in_sequence(mp, seqnum, i))
+ continue;
+
+ /*
+ ** See if we need to enlarge buffer. Since we don't know
+ ** exactly how many character this particular message range
+ ** will need, we enlarge the buffer if we are within
+ ** 50 characters of the end.
+ */
+ if (bp - buffer > len - 50) {
+ char *newbuf;
+
+ len += MAXBUFFER;
+ newbuf = mh_xrealloc(buffer, len);
+ bp = newbuf + (bp - buffer);
+ buffer = newbuf;
+ }
+
+ /*
+ ** If this is not the first message range in
+ ** the list, first add a space.
+ */
+ if (bp > buffer)
+ *bp++ = ' ';
+
+ sprintf(bp, "%s", m_name(i));
+ bp += strlen(bp);
+ j = i; /* Remember beginning of message range */
+
+ /*
+ ** Scan to the end of this message range
+ */
+ for (++i; i <= mp->hghoff && in_sequence(mp, seqnum, i); ++i)
+ ;
+
+ if (i - j > 1) {
+ sprintf(bp, "-%s", m_name(i - 1));
+ bp += strlen(bp);
+ }