3 * seq_save.c -- 1) synchronize sequences
4 * -- 2) save public sequences
10 #include <h/signals.h>
14 * 1. If sequence is public and folder is readonly,
15 * then change it to be private
16 * 2a. If sequence is public, then add it to the sequences file
17 * in folder (name specified by mh-sequences profile entry).
18 * 2b. If sequence is private, then add it to the
23 seq_save (struct msgs *mp)
26 char flags, *cp, attr[BUFSIZ], seqfile[PATH_MAX];
30 /* sanity check - check that context has been read */
32 adios (NULL, "oops, context hasn't been read yet");
34 /* check if sequence information has changed */
35 if (!(mp->msgflags & SEQMOD))
37 mp->msgflags &= ~SEQMOD;
40 flags = mp->msgflags; /* record folder flags */
43 * If no mh-sequences file is defined, or if a mh-sequences file
44 * is defined but empty (*mh_seq == '\0'), then pretend folder
45 * is readonly. This will force all sequences to be private.
47 if (mh_seq == NULL || *mh_seq == '\0')
50 snprintf (seqfile, sizeof(seqfile), "%s/%s", mp->foldpath, mh_seq);
52 for (i = 0; mp->msgattrs[i]; i++) {
53 snprintf (attr, sizeof(attr), "atr-%s-%s", mp->msgattrs[i], mp->foldpath);
55 /* get space separated list of sequence ranges */
56 if (!(cp = seq_list(mp, mp->msgattrs[i]))) {
57 context_del (attr); /* delete sequence from context */
61 if (is_readonly(mp) || is_seq_private(mp, i)) {
66 context_replace (attr, cp); /* update sequence in context */
71 context_del (attr); /* delete sequence from context */
75 * Attempt to open file for public sequences.
76 * If that fails (probably because folder is
77 * readonly), then make sequence private.
79 if ((fp = fopen (seqfile, "w")) == NULL
80 && (unlink (seqfile) == -1 ||
81 (fp = fopen (seqfile, "w")) == NULL)) {
82 admonish (attr, "unable to write");
86 /* block a few signals */
88 sigaddset(&set, SIGHUP);
89 sigaddset(&set, SIGINT);
90 sigaddset(&set, SIGQUIT);
91 sigaddset(&set, SIGTERM);
92 SIGPROCMASK (SIG_BLOCK, &set, &oset);
94 fprintf (fp, "%s: %s\n", mp->msgattrs[i], cp);
100 SIGPROCMASK (SIG_SETMASK, &oset, &set); /* reset signal mask */
103 * If folder is not readonly, and we didn't save any
104 * public sequences, then remove that file.
106 if (!is_readonly(mp))
111 * Reset folder flag, since we may be
112 * pretending that folder is readonly.
114 mp->msgflags = flags;