* in a particular sequence.
*/
seqset_t *msgstats; /* msg status */
+
+ /*
+ * A FILE handle containing an open filehandle for the sequence file
+ * for this folder. If non-NULL, use it when the sequence file is
+ * written.
+ */
+ FILE *seqhandle;
+
+ /*
+ * The name of the public sequence file; required by lkfclose()
+ */
+ char *seqname;
};
/*
int folder_delmsgs (struct msgs *, int, int);
void folder_free (struct msgs *);
int folder_pack (struct msgs **, int);
-struct msgs *folder_read (char *);
+
+/*
+ * Read a MH folder structure and return an allocated "struct msgs"
+ * corresponding to the contents of the folder.
+ *
+ * Arguments include:
+ *
+ * name - Name of folder
+ * lockflag - If true, write-lock (and keep open) metadata files.
+ * See comments for seq_read() for more information.
+ */
+struct msgs *folder_read (char *name, int lockflag);
+
struct msgs *folder_realloc (struct msgs *, int, int);
int gans (char *, struct swit *);
char **getans (char *, struct swit *);
int seq_nameok (char *);
void seq_print (struct msgs *, char *);
void seq_printall (struct msgs *);
-void seq_read (struct msgs *);
+
+/*
+ * Read the sequence files for the folder referenced in the given
+ * struct msgs and populate the sequence entries in the struct msgs.
+ *
+ * Arguments:
+ *
+ * mp - Folder structure to add sequence entries to
+ * lockflag - If true, obtain a write lock on the sequence file.
+ * Additionally, the sequence file will remain open
+ * and a pointer to the filehandle will be stored in
+ * folder structure, where it will later be used by
+ * seq_save().
+ */
+void seq_read (struct msgs * mp, int lockflag);
void seq_save (struct msgs *);
void seq_setcur (struct msgs *, int);
void seq_setprev (struct msgs *);
for (i = 0; mp->msgattrs[i]; i++)
free (mp->msgattrs[i]);
+ /* Close/free the sequence file if it is open */
+
+ if (mp->seqhandle)
+ lkfclosedata (mp->seqhandle, mp->seqname);
+
+ if (mp->seqname)
+ free (mp->seqname);
+
free (mp->msgstats); /* free message status area */
free (mp); /* free main folder structure */
}
*/
struct msgs *
-folder_read (char *name)
+folder_read (char *name, int lockflag)
{
int msgnum, prefix_len, len, *mi;
struct msgs *mp;
mp->hghsel = 0;
mp->numsel = 0;
mp->nummsg = 0;
+ mp->seqhandle = NULL;
+ mp->seqname = NULL;
if (access (name, W_OK) == -1)
set_readonly (mp);
/*
* Read and initialize the sequence information.
*/
- seq_read (mp);
+ seq_read (mp, lockflag);
return mp;
}
if (chdir (buffer) == -1)
adios (buffer, "unable to change directory to");
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 1)))
adios (NULL, "unable to read folder %s", folder);
/*
* static prototypes
*/
static int seq_init (struct msgs *, char *, char *);
-static void seq_public (struct msgs *);
+static void seq_public (struct msgs *, int);
static void seq_private (struct msgs *);
*/
void
-seq_read (struct msgs *mp)
+seq_read (struct msgs *mp, int lockflag)
{
/*
* Initialize the list of sequence names. Go ahead and
return;
/* Initialize the public sequences */
- seq_public (mp);
+ seq_public (mp, lockflag);
/* Initialize the private sequences */
seq_private (mp);
*/
static void
-seq_public (struct msgs *mp)
+seq_public (struct msgs *mp, int lockflag)
{
int state;
char *cp, seqfile[PATH_MAX];
/* get filename of sequence file */
snprintf (seqfile, sizeof(seqfile), "%s/%s", mp->foldpath, mh_seq);
- if ((fp = lkfopendata (seqfile, "r")) == NULL)
+ if ((fp = lkfopendata (seqfile, lockflag ? "r+" : "r")) == NULL)
return;
/* Use m_getfld to scan sequence file */
}
continue;
- case BODY:
+ case BODY:
+ lkfclosedata (fp, seqfile);
adios (NULL, "no blank lines are permitted in %s", seqfile);
/* fall */
break;
default:
+ lkfclosedata (fp, seqfile);
adios (NULL, "%s is poorly formatted", seqfile);
}
break; /* break from for loop */
}
m_getfld_state_destroy (&gstate);
- lkfclosedata (fp, seqfile);
+ if (lockflag) {
+ mp->seqhandle = fp;
+ mp->seqname = getcpy(seqfile);
+ } else {
+ lkfclosedata (fp, seqfile);
+ }
}
sigset_t set, oset;
/* check if sequence information has changed */
- if (!(mp->msgflags & SEQMOD))
+ if (!(mp->msgflags & SEQMOD)) {
+ if (mp->seqhandle)
+ lkfclosedata (mp->seqhandle, mp->seqname);
return;
+ }
mp->msgflags &= ~SEQMOD;
fp = NULL;
* If that fails (probably because folder is
* readonly), then make sequence private.
*/
- if ((fp = lkfopendata (seqfile, "w")) == NULL
+
+ if (mp->seqhandle) {
+ fp = mp->seqhandle;
+ mp->seqhandle = NULL;
+ free(mp->seqname);
+ mp->seqname = NULL;
+ rewind(fp);
+ ftruncate(fileno(fp), 0);
+ } else if ((fp = lkfopendata (seqfile, "w")) == NULL
&& (unlink (seqfile) == -1 ||
(fp = lkfopendata (seqfile, "w")) == NULL)) {
admonish (attr, "unable to write");
adios (maildir, "unable to change directory to");
/* read folder and create message structure */
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 1)))
adios (NULL, "unable to read folder %s", folder);
/* check for empty folder */
adios (maildir, "unable to change directory to");
/* read folder and create message structure */
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 1)))
adios (NULL, "unable to read folder %s", folder);
/* check for empty folder */
adios (maildir, "unable to change directory to");
/* read folder and create message structure */
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 1)))
adios (NULL, "unable to read folder %s", folder);
/* check for empty folder */
if (!m_convert (mp, msg))
done (1);
seq_setprev (mp); /* set the previous-sequence */
+ seq_save (mp);
if (mp->numsel > 1)
adios (NULL, "only one message at a time!");
adios (maildir, "unable to change directory to");
/* read folder and create message structure */
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 1)))
adios (NULL, "unable to read folder %s", folder);
/* check for empty folder */
struct msgs *mp;
/* Read folder and create message structure */
- if (!(mp = folder_read (name))) {
+ if (!(mp = folder_read (name, 0))) {
/* Oops, error occurred. Record it and continue. */
AllocFolders(&folders, &nFoldersAlloced, nFolders + 1);
f = &folders[nFolders++];
if (chdir(maildir) < 0)
adios(maildir, "unable to change directory to");
- if (!(mp = folder_read(folder)))
+ if (!(mp = folder_read(folder, 1)))
adios(NULL, "unable to read folder %s", folder);
if (mp->nummsg == 0)
/*
* create message structure and get folder info
*/
- if (!(mp = folder_read (fold))) {
+ if (!(mp = folder_read (fold, 1))) {
admonish (NULL, "unable to read folder %s", fold);
return 0;
}
adios (maildir, "unable to change directory to");
/* read folder and create message structure */
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 1)))
adios (NULL, "unable to read folder %s", folder);
/* check for empty folder */
adios (maildir, "unable to change directory to");
/* read folder and create message structure */
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 0)))
adios (NULL, "unable to read folder %s", folder);
go_to_it:
adios (maildir, "unable to change directory to");
/* read folder and create message structure */
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 1)))
adios (NULL, "unable to read folder %s", folder);
/* print some general debugging info */
if (!folder)
folder = add (getfolder (1), NULL);
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 0)))
adios (NULL, "unable to read folder %s", folder);
for (ap = arguments; *ap; ap++) {
cp = *ap;
adios (maildir, "unable to change directory to");
/* read folder and create message structure */
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 0)))
adios (NULL, "unable to read folder %s", folder);
/* check for empty folder */
adios (maildir, "unable to change directory to");
/* read folder and create message structure */
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 1)))
adios (NULL, "unable to read folder %s", folder);
/* check for empty folder */
adios (maildir, "unable to change directory to");
/* read folder and create message structure */
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 1)))
adios (NULL, "unable to read folder %s", folder);
/*
adios (maildir, "unable to change directory to");
/* read folder and create message structure */
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 1)))
adios (NULL, "unable to read folder %s", folder);
/* check for empty folder */
adios (maildir, "unable to change directory to");
/* read folder and create message structure */
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 1)))
adios (NULL, "unable to read folder %s", folder);
/* check for empty folder */
struct msgs *mp;
/* Read the folder. */
- if ((mp = folder_read (folder))) {
+ if ((mp = folder_read (folder, 0))) {
/* Link file into folder */
msgnum = folder_addmsg (&mp, filename, 0, 0, 0, 0, (char *)0);
} else {
adios (maildir, "unable to change directory to");
/* read folder and create message structure */
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 1)))
adios (NULL, "unable to read folder %s", folder);
/* check for empty folder */
padios (maildir, "unable to change directory to");
/* read folder and create message structure */
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 0)))
padios (NULL, "unable to read folder %s", folder);
/* check for empty folder */
low = mp->hghmsg + 1;
folder_free (mp); /* free folder/message structure */
- if (!(mp = folder_read (fmsh)))
+ if (!(mp = folder_read (fmsh, 0)))
padios (NULL, "unable to re-read folder %s", fmsh);
hgh = mp->hghmsg;
adios (maildir, "unable to change directory to ");
/* read folder and create message structure */
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 1)))
adios (NULL, "unable to read folder %s", folder);
/* check for empty folder */
adios (maildir, "unable to change directory to");
/* read folder and create message structure */
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 0)))
adios (NULL, "unable to read folder %s", folder);
/* check for empty folder */
/*
* read folder and create message structure
*/
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 1)))
adios (NULL, "unable to read folder %s", folder);
/*
adios (maildir, "unable to change directory to");
/* read source folder and create message structure */
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 1)))
adios (NULL, "unable to read folder %s", folder);
/* check for empty folder */
if (chdir (nmaildir) == NOTOK)
adios (nmaildir, "unable to change directory to");
- if (!(mp = folder_read (fp->f_name)))
+ if (!(mp = folder_read (fp->f_name, 1)))
adios (NULL, "unable to read folder %s", fp->f_name);
mp->curmsg = 0;
adios (maildir, "unable to change directory to");
/* read folder and create message structure */
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 1)))
adios (NULL, "unable to read folder %s", folder);
/* check for empty folder */
adios (maildir, "unable to change directory to");
/* read folder and create message structure */
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 1)))
adios (NULL, "unable to read folder %s", folder);
/* check for empty folder */
adios (maildir, "unable to change directory to");
/* read folder and create message structure */
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 1)))
adios (NULL, "unable to read folder %s", folder);
/* check for empty folder */
adios (maildir, "unable to change directory to");
/* read folder and create message structure */
- if (!(mp = folder_read (dfolder)))
+ if (!(mp = folder_read (dfolder, 1)))
adios (NULL, "unable to read folder %s", dfolder);
/* check for empty folder */
admonish (maildir, "unable to change directory to");
return;
}
- if (!(mp = folder_read (folder))) {
+ if (!(mp = folder_read (folder, 0))) {
if (debugsw)
admonish (NULL, "unable to read folder %s", folder);
return;
adios (maildir, "unable to change directory to");
/* read folder and create message structure */
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 1)))
adios (NULL, "unable to read folder %s", folder);
/* check for empty folder */
adios (maildir, "unable to change directory to");
/* read folder and create message structure */
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 1)))
adios (NULL, "unable to read folder %s", folder);
/* check for empty folder */