9 date 92.12.15.00.20.22; author jromine; state Exp;
14 date 92.11.04.00.53.48; author jromine; state Exp;
19 date 92.01.31.22.19.47; author jromine; state Exp;
24 date 92.01.31.22.19.33; author jromine; state Exp;
38 @/* packf.c - pack a folder (used to be called "pack") */
40 static char ident[] = "@@(#)$Id: packf.c,v 1.3 1992/11/04 00:53:48 jromine Exp jromine $";
44 #include "../h/dropsbr.h"
47 #include <sys/types.h>
55 static struct swit switches[] = {
70 static int md = NOTOK;
98 setlocale(LC_ALL, "");
100 invo_name = r1bindex (argv[0], '/');
101 if ((cp = m_find (invo_name)) != NULL) {
102 ap = brkstring (cp = getcpy (cp), " ", "\n");
103 ap = copyip (ap, arguments);
107 (void) copyip (argv + 1, ap);
112 while (cp = *argp++) {
114 switch (smatch (++cp, switches)) {
116 ambigsw (cp, switches);
119 adios (NULLCP, "-%s unknown", cp);
121 (void) sprintf (buf, "%s [+folder] [msgs] [switches]",
123 help (buf, switches);
128 adios (NULLCP, "only one file at a time!");
129 if (!(file = *argp++) || *file == '-')
130 adios (NULLCP, "missing argument to %s", argp[-2]);
133 if (*cp == '+' || *cp == '@@') {
135 adios (NULLCP, "only one folder at a time!");
136 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
146 file = path (file, TFILE);
147 if (stat (file, &st) == NOTOK) {
149 adios (file, "error on file");
150 cp = concat ("Create file \"", file, "\"? ", NULLCP);
156 if (!m_find ("path"))
157 free (path ("./", TFOLDER));
159 msgs[msgp++] = "all";
161 folder = m_getfolder ();
162 maildir = m_maildir (folder);
164 if (chdir (maildir) == NOTOK)
165 adios (maildir, "unable to change directory to ");
166 if (!(mp = m_gmsg (folder)))
167 adios (NULLCP, "unable to read folder %s", folder);
168 if (mp -> hghmsg == 0)
169 adios (NULLCP, "no messages in %s", folder);
171 for (msgnum = 0; msgnum < msgp; msgnum++)
172 if (!m_convert (mp, msgs[msgnum]))
176 if ((md = mbx_open (file, getuid (), getgid (), m_gmprot ())) == NOTOK)
177 adios (file, "unable to open");
179 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
180 if (mp -> msgstats[msgnum] & SELECTED) {
181 if ((fd = open (msgnam = m_name (msgnum), 0)) == NOTOK) {
182 admonish (msgnam, "unable to read message");
186 if (mbx_copy (file, md, fd, 1, NULLCP, 1) == NOTOK)
187 adios (file, "error writing to file");
191 (void) mbx_close (file, md);
193 m_replace (pfolder, folder);
194 if (mp -> hghsel != mp -> curmsg)
195 m_setcur (mp, mp -> lowsel);
207 (void) mbx_close (file, md);
221 static char ident[] = "@@(#)$Id: packf.c,v 1.2 1992/01/31 22:19:47 jromine Exp jromine $";
233 static char ident[] = "@@(#)$Id$";