1 /* packf.c - pack a folder (used to be called "pack") */
3 static char ident[] = "@(#)$Id: packf.c,v 1.4 1992/12/15 00:20:22 jromine Exp $";
7 #include "../h/dropsbr.h"
10 #include <sys/types.h>
18 static struct swit switches[] = {
33 static int md = NOTOK;
61 setlocale(LC_ALL, "");
63 invo_name = r1bindex (argv[0], '/');
64 if ((cp = m_find (invo_name)) != NULL) {
65 ap = brkstring (cp = getcpy (cp), " ", "\n");
66 ap = copyip (ap, arguments);
70 (void) copyip (argv + 1, ap);
75 while (cp = *argp++) {
77 switch (smatch (++cp, switches)) {
79 ambigsw (cp, switches);
82 adios (NULLCP, "-%s unknown", cp);
84 (void) sprintf (buf, "%s [+folder] [msgs] [switches]",
91 adios (NULLCP, "only one file at a time!");
92 if (!(file = *argp++) || *file == '-')
93 adios (NULLCP, "missing argument to %s", argp[-2]);
96 if (*cp == '+' || *cp == '@') {
98 adios (NULLCP, "only one folder at a time!");
99 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
109 file = path (file, TFILE);
110 if (stat (file, &st) == NOTOK) {
112 adios (file, "error on file");
113 cp = concat ("Create file \"", file, "\"? ", NULLCP);
119 if (!m_find ("path"))
120 free (path ("./", TFOLDER));
122 msgs[msgp++] = "all";
124 folder = m_getfolder ();
125 maildir = m_maildir (folder);
127 if (chdir (maildir) == NOTOK)
128 adios (maildir, "unable to change directory to ");
129 if (!(mp = m_gmsg (folder)))
130 adios (NULLCP, "unable to read folder %s", folder);
131 if (mp -> hghmsg == 0)
132 adios (NULLCP, "no messages in %s", folder);
134 for (msgnum = 0; msgnum < msgp; msgnum++)
135 if (!m_convert (mp, msgs[msgnum]))
139 if ((md = mbx_open (file, getuid (), getgid (), m_gmprot ())) == NOTOK)
140 adios (file, "unable to open");
142 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
143 if (mp -> msgstats[msgnum] & SELECTED) {
144 if ((fd = open (msgnam = m_name (msgnum), 0)) == NOTOK) {
145 admonish (msgnam, "unable to read message");
149 if (mbx_copy (file, md, fd, 1, NULLCP, 1) == NOTOK)
150 adios (file, "error writing to file");
154 (void) mbx_close (file, md);
156 m_replace (pfolder, folder);
157 if (mp -> hghsel != mp -> curmsg)
158 m_setcur (mp, mp -> lowsel);
170 (void) mbx_close (file, md);