- int i, j, mode;
- char *msgnam;
- char f1[BUFSIZ], f2[BUFSIZ], f3[BUFSIZ];
- FILE *in, *out;
- struct stat st;
- struct msgs *mp;
-
- if ((in = fopen (msgnam = m_name (msgnum), "r")) == NULL)
- adios (msgnam, "unable to read message");
-
- mode = fstat (fileno(in), &st) != NOTOK ? (st.st_mode & 0777) : m_gmprot();
- mp = *mpp;
-
- /*
- * See if we have enough space in the folder
- * structure for all the new messages.
- */
- if ((mp->hghmsg + numburst > mp->hghoff) &&
- !(mp = folder_realloc (mp, mp->lowoff, mp->hghmsg + numburst)))
- adios (NULL, "unable to allocate folder storage");
- *mpp = mp;
-
- j = mp->hghmsg; /* old value */
- mp->hghmsg += numburst;
- mp->nummsg += numburst;
-
- /*
- * If this is not the highest SELECTED message, then
- * increment mp->hghsel by numburst, since the highest
- * SELECTED is about to be slid down by that amount.
- */
- if (msgnum < mp->hghsel)
- mp->hghsel += numburst;
-
- /*
- * If -inplace is given, renumber the messages after the
- * source message, to make room for each of the messages
- * contained within the digest.
- */
- if (inplace) {
- for (i = mp->hghmsg; j > msgnum; i--, j--) {
- strncpy (f1, m_name (i), sizeof(f1));
- strncpy (f2, m_name (j), sizeof(f2));
- if (does_exist (mp, j)) {
- if (verbosw)
- printf ("message %d becomes message %d\n", j, i);
-
- if (rename (f2, f1) == NOTOK)
- admonish (f1, "unable to rename %s to", f2);
- copy_msg_flags (mp, i, j);
- clear_msg_flags (mp, j);
+ int i, j, mode;
+ char *msgnam;
+ char destfil[BUFSIZ];
+ FILE *in, *out;
+ struct stat st;
+ struct msgs *mp;
+
+ if ((in = fopen(msgnam = m_name(msgnum), "r")) == NULL)
+ adios(EX_IOERR, msgnam, "unable to read message");
+
+ mode = fstat(fileno(in), &st) != NOTOK ?
+ (int)(st.st_mode & 0777) : m_gmprot();
+ mp = *mpp;
+
+ /*
+ ** Ensure we have enough space in the folder
+ ** structure for all the new messages.
+ */
+ if ((mp->hghmsg + numburst > mp->hghoff) && !(mp = folder_realloc(mp,
+ mp->lowoff, mp->hghmsg + numburst)))
+ adios(EX_OSERR, NULL, "unable to allocate folder storage");
+ *mpp = mp;
+
+ /*
+ ** At this point, there is an array of numburst smsgs, each
+ ** element of which contains the starting and stopping offsets
+ ** (seeks) of the message in the digest. Go through the message
+ ** numbers. Ignore smsgs[0], which is the table of contents.
+ */
+ for (j=1, i=mp->hghmsg+1; j<=numburst; j++, i++) {
+ snprintf(destfil, sizeof destfil, "%s/%d", maildir, i);
+ if (!(out = fopen(destfil, "w"))) {
+ adios(EX_IOERR, destfil, "unable to open");
+ }
+ if (verbosw) {
+ printf("message %d of digest %d becomes message %d\n",
+ j, msgnum, i);
+ }
+ chmod(destfil, mode);
+ fseek(in, smsgs[j].s_start, SEEK_SET);
+ cpybrst(in, out, msgnam, destfil,
+ (int) (smsgs[j].s_stop - smsgs[j].s_start));
+ fclose(out);
+ mp->hghmsg++;
+ mp->nummsg++;
+ /*
+ ** Bursting each message is equivalent to adding a
+ ** new message from the point of view of the external hooks.
+ */
+ ext_hook("add-hook", destfil, NULL);
+ copy_msg_flags(mp, i, msgnum);