9 date 92.12.15.00.20.22; author jromine; state Exp;
14 date 92.11.04.01.00.16; author jromine; state Exp;
19 date 92.05.19.21.05.09; author jromine; state Exp;
24 date 92.02.04.00.03.28; author jromine; state Exp;
29 date 90.11.05.12.22.03; author mh; state Exp;
34 date 90.04.05.14.57.11; author sources; state Exp;
39 date 90.02.06.13.30.19; author sources; state Exp;
44 date 89.11.17.15.58.10; author sources; state Exp;
49 date 89.06.26.14.36.40; author sources; state Exp;
63 @/* rmf.c - remove a folder */
65 static char ident[] = "@@(#)$Id: rmf.c,v 2.6 1992/11/04 01:00:16 jromine Exp jromine $";
69 #include "../h/local.h"
77 static struct swit switches[] = {
110 setlocale(LC_ALL, "");
112 invo_name = r1bindex (argv[0], '/');
113 if ((cp = m_find (invo_name)) != NULL) {
114 ap = brkstring (cp = getcpy (cp), " ", "\n");
115 ap = copyip (ap, arguments);
119 (void) copyip (argv + 1, ap);
124 while (cp = *argp++) {
126 switch (smatch (++cp, switches)) {
128 ambigsw (cp, switches);
131 adios (NULLCP, "-%s unknown", cp);
133 (void) sprintf (buf, "%s [+folder] [switches]", invo_name);
134 help (buf, switches);
144 if (*cp == '+' || *cp == '@@') {
146 adios (NULLCP, "only one folder at a time!");
148 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
151 adios (NULLCP, "usage: %s [+folder] [switches]", invo_name);
156 if (!m_find ("path"))
157 free (path ("./", TFOLDER));
159 folder = m_getfolder ();
162 if (strcmp (m_mailpath (folder), pwd ()) == 0)
163 adios (NULLCP, "sorry, you can't remove the current working directory");
165 if (interactive == -1)
166 interactive = defolder;
168 if (index (folder, '/') && (*folder != '/') && (*folder != '.')) {
169 for (cp = copy (folder, newfolder); cp > newfolder && *cp != '/'; cp--)
174 (void) strcpy (newfolder, (cp = m_find (inbox)) ? cp : defalt);
177 (void) strcpy (newfolder, (cp = m_find (inbox)) ? cp : defalt);
180 cp = concat ("Remove folder \"", folder, "\"? ", NULLCP);
186 if (rmf (folder) == OK && strcmp (m_find (pfolder), newfolder)) {
187 printf ("[+%s now current]\n", newfolder);
188 m_replace (pfolder, newfolder);
197 static int rmf (folder)
198 register char *folder;
203 register char *maildir;
206 register struct dirent *dp;
208 register struct direct *dp;
213 (void) m_delete (concat (current, "-", m_mailpath (folder), NULLCP));
215 switch (i = chdir (maildir = m_maildir (folder))) {
217 if (access (".", 2) != NOTOK && access ("..", 2) != NOTOK)
218 break; /* fall otherwise */
221 (void) sprintf (cur, "atr-%s-%s", current, m_mailpath (folder));
222 if (!m_delete (cur)) {
223 printf ("[+%s de-referenced]\n", folder);
226 advise (NULLCP, "you have no profile entry for the %s folder +%s",
227 i == NOTOK ? "unreadable" : "read-only", folder);
231 if ((dd = opendir (".")) == NULL)
232 adios (NULLCP, "unable to read folder +%s", folder);
235 j = strlen (SBACKUP);
236 while (dp = readdir (dd)) {
237 switch (dp -> d_name[0]) {
239 if (strcmp (dp -> d_name, ".") == 0
240 || strcmp (dp -> d_name, "..") == 0)
241 continue; /* else fall */
254 if (m_atoi (dp -> d_name))
257 if (strcmp (dp -> d_name, current) == 0)
260 if (strcmp (dp -> d_name, LINK) == 0
261 || strncmp (dp -> d_name, SBACKUP, j) == 0)
264 admonish (NULLCP, "file \"%s/%s\" not deleted",
265 folder, dp -> d_name);
269 if (unlink (dp -> d_name) == NOTOK) {
270 admonish (dp -> d_name, "unable to unlink %s:", folder);
280 if (others == 0 && remdir (maildir))
283 advise (NULLCP, "folder +%s not removed", folder);
290 register char *folder;
296 register struct node *np,
299 alen = strlen ("atr-");
300 plen = strlen (cp = m_mailpath (folder)) + 1;
303 for (np = m_defs, pp = NULL; np; np = np -> n_next)
304 if (ssequal ("atr-", np -> n_name)
305 && (j = strlen (np -> n_name) - plen) > alen
306 && *(np -> n_name + j) == '-'
307 && strcmp (cp, np -> n_name + j + 1) == 0) {
308 if (!np -> n_context)
309 admonish (NULLCP, "bug: m_delete(key=\"%s\")", np -> n_name);
311 pp -> n_next = np -> n_next;
315 m_defs = np -> n_next;
331 static char ident[] = "@@(#)$Id: rmf.c,v 2.5 1992/05/19 21:05:09 jromine Exp jromine $";
361 static char ident[] = "@@(#)$Id: rmf.c,v 2.4 1992/02/04 00:03:28 jromine Exp jromine $";
374 static char ident[] = "@@(#)$Id: rmf.c,v 2.3 1990/11/05 12:22:03 mh Exp jromine $";
391 static char ident[] = "@@(#)$Id: rmf.c,v 2.2 90/04/05 14:57:11 sources Exp Locker: mh $";
394 (void) strcpy (newfolder, defalt);
397 (void) strcpy (newfolder, defalt);
408 static char ident[] = "@@(#)$Id:$";
426 @changes for SUN40 shared libraries and NNTP under bbc