]>
diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/uip/rmf.c
1 /* rmf.c - remove a folder */
3 static char ident
[] = "@(#)$Id: rmf.c,v 2.7 1992/12/15 00:20:22 jromine Exp $";
7 #include "../h/local.h"
15 static struct swit switches
[] = {
48 setlocale(LC_ALL
, "");
50 invo_name
= r1bindex (argv
[0], '/');
51 if ((cp
= m_find (invo_name
)) != NULL
) {
52 ap
= brkstring (cp
= getcpy (cp
), " ", "\n");
53 ap
= copyip (ap
, arguments
);
57 (void) copyip (argv
+ 1, ap
);
62 while (cp
= *argp
++) {
64 switch (smatch (++cp
, switches
)) {
66 ambigsw (cp
, switches
);
69 adios (NULLCP
, "-%s unknown", cp
);
71 (void) sprintf (buf
, "%s [+folder] [switches]", invo_name
);
82 if (*cp
== '+' || *cp
== '@') {
84 adios (NULLCP
, "only one folder at a time!");
86 folder
= path (cp
+ 1, *cp
== '+' ? TFOLDER
: TSUBCWF
);
89 adios (NULLCP
, "usage: %s [+folder] [switches]", invo_name
);
95 free (path ("./", TFOLDER
));
97 folder
= m_getfolder ();
100 if (strcmp (m_mailpath (folder
), pwd ()) == 0)
101 adios (NULLCP
, "sorry, you can't remove the current working directory");
103 if (interactive
== -1)
104 interactive
= defolder
;
106 if (index (folder
, '/') && (*folder
!= '/') && (*folder
!= '.')) {
107 for (cp
= copy (folder
, newfolder
); cp
> newfolder
&& *cp
!= '/'; cp
--)
112 (void) strcpy (newfolder
, (cp
= m_find (inbox
)) ? cp
: defalt
);
115 (void) strcpy (newfolder
, (cp
= m_find (inbox
)) ? cp
: defalt
);
118 cp
= concat ("Remove folder \"", folder
, "\"? ", NULLCP
);
124 if (rmf (folder
) == OK
&& strcmp (m_find (pfolder
), newfolder
)) {
125 printf ("[+%s now current]\n", newfolder
);
126 m_replace (pfolder
, newfolder
);
135 static int rmf (folder
)
136 register char *folder
;
141 register char *maildir
;
144 register struct dirent
*dp
;
146 register struct direct
*dp
;
151 (void) m_delete (concat (current
, "-", m_mailpath (folder
), NULLCP
));
153 switch (i
= chdir (maildir
= m_maildir (folder
))) {
155 if (access (".", 2) != NOTOK
&& access ("..", 2) != NOTOK
)
156 break; /* fall otherwise */
159 (void) sprintf (cur
, "atr-%s-%s", current
, m_mailpath (folder
));
160 if (!m_delete (cur
)) {
161 printf ("[+%s de-referenced]\n", folder
);
164 advise (NULLCP
, "you have no profile entry for the %s folder +%s",
165 i
== NOTOK
? "unreadable" : "read-only", folder
);
169 if ((dd
= opendir (".")) == NULL
)
170 adios (NULLCP
, "unable to read folder +%s", folder
);
173 j
= strlen (SBACKUP
);
174 while (dp
= readdir (dd
)) {
175 switch (dp
-> d_name
[0]) {
177 if (strcmp (dp
-> d_name
, ".") == 0
178 || strcmp (dp
-> d_name
, "..") == 0)
179 continue; /* else fall */
192 if (m_atoi (dp
-> d_name
))
195 if (strcmp (dp
-> d_name
, current
) == 0)
198 if (strcmp (dp
-> d_name
, LINK
) == 0
199 || strncmp (dp
-> d_name
, SBACKUP
, j
) == 0)
202 admonish (NULLCP
, "file \"%s/%s\" not deleted",
203 folder
, dp
-> d_name
);
207 if (unlink (dp
-> d_name
) == NOTOK
) {
208 admonish (dp
-> d_name
, "unable to unlink %s:", folder
);
218 if (others
== 0 && remdir (maildir
))
221 advise (NULLCP
, "folder +%s not removed", folder
);
228 register char *folder
;
234 register struct node
*np
,
237 alen
= strlen ("atr-");
238 plen
= strlen (cp
= m_mailpath (folder
)) + 1;
241 for (np
= m_defs
, pp
= NULL
; np
; np
= np
-> n_next
)
242 if (ssequal ("atr-", np
-> n_name
)
243 && (j
= strlen (np
-> n_name
) - plen
) > alen
244 && *(np
-> n_name
+ j
) == '-'
245 && strcmp (cp
, np
-> n_name
+ j
+ 1) == 0) {
246 if (!np
-> n_context
)
247 admonish (NULLCP
, "bug: m_delete(key=\"%s\")", np
-> n_name
);
249 pp
-> n_next
= np
-> n_next
;
253 m_defs
= np
-> n_next
;