/* rmf.c - remove a folder */
static char ident
[] = "@(#)$Id: rmf.c,v 2.7 1992/12/15 00:20:22 jromine Exp $";
static struct swit switches
[] = {
invo_name
= r1bindex (argv
[0], '/');
if ((cp
= m_find (invo_name
)) != NULL
) {
ap
= brkstring (cp
= getcpy (cp
), " ", "\n");
ap
= copyip (ap
, arguments
);
(void) copyip (argv
+ 1, ap
);
switch (smatch (++cp
, switches
)) {
adios (NULLCP
, "-%s unknown", cp
);
(void) sprintf (buf
, "%s [+folder] [switches]", invo_name
);
if (*cp
== '+' || *cp
== '@') {
adios (NULLCP
, "only one folder at a time!");
folder
= path (cp
+ 1, *cp
== '+' ? TFOLDER
: TSUBCWF
);
adios (NULLCP
, "usage: %s [+folder] [switches]", invo_name
);
free (path ("./", TFOLDER
));
if (strcmp (m_mailpath (folder
), pwd ()) == 0)
adios (NULLCP
, "sorry, you can't remove the current working directory");
if (index (folder
, '/') && (*folder
!= '/') && (*folder
!= '.')) {
for (cp
= copy (folder
, newfolder
); cp
> newfolder
&& *cp
!= '/'; cp
--)
(void) strcpy (newfolder
, (cp
= m_find (inbox
)) ? cp
: defalt
);
(void) strcpy (newfolder
, (cp
= m_find (inbox
)) ? cp
: defalt
);
cp
= concat ("Remove folder \"", folder
, "\"? ", NULLCP
);
if (rmf (folder
) == OK
&& strcmp (m_find (pfolder
), newfolder
)) {
printf ("[+%s now current]\n", newfolder
);
m_replace (pfolder
, newfolder
);
register struct dirent
*dp
;
register struct direct
*dp
;
(void) m_delete (concat (current
, "-", m_mailpath (folder
), NULLCP
));
switch (i
= chdir (maildir
= m_maildir (folder
))) {
if (access (".", 2) != NOTOK
&& access ("..", 2) != NOTOK
)
break; /* fall otherwise */
(void) sprintf (cur
, "atr-%s-%s", current
, m_mailpath (folder
));
printf ("[+%s de-referenced]\n", folder
);
advise (NULLCP
, "you have no profile entry for the %s folder +%s",
i
== NOTOK
? "unreadable" : "read-only", folder
);
if ((dd
= opendir (".")) == NULL
)
adios (NULLCP
, "unable to read folder +%s", folder
);
while (dp
= readdir (dd
)) {
switch (dp
-> d_name
[0]) {
if (strcmp (dp
-> d_name
, ".") == 0
|| strcmp (dp
-> d_name
, "..") == 0)
continue; /* else fall */
if (m_atoi (dp
-> d_name
))
if (strcmp (dp
-> d_name
, current
) == 0)
if (strcmp (dp
-> d_name
, LINK
) == 0
|| strncmp (dp
-> d_name
, SBACKUP
, j
) == 0)
admonish (NULLCP
, "file \"%s/%s\" not deleted",
if (unlink (dp
-> d_name
) == NOTOK
) {
admonish (dp
-> d_name
, "unable to unlink %s:", folder
);
if (others
== 0 && remdir (maildir
))
advise (NULLCP
, "folder +%s not removed", folder
);
register struct node
*np
,
plen
= strlen (cp
= m_mailpath (folder
)) + 1;
for (np
= m_defs
, pp
= NULL
; np
; np
= np
-> n_next
)
if (ssequal ("atr-", np
-> n_name
)
&& (j
= strlen (np
-> n_name
) - plen
) > alen
&& *(np
-> n_name
+ j
) == '-'
&& strcmp (cp
, np
-> n_name
+ j
+ 1) == 0) {
admonish (NULLCP
, "bug: m_delete(key=\"%s\")", np
-> n_name
);
pp
-> n_next
= np
-> n_next
;