]>
diplodocus.org Git - nmh/blob - uip/rmm.c
3 * rmm.c -- remove a message(s)
11 * We allocate space for message names and ranges
12 * (msgs array) this number of elements at a time.
16 static struct swit switches
[] = {
30 main (int argc
, char **argv
)
32 int nummsgs
, maxmsgs
, msgnum
, unlink_msgs
= 0;
33 char *cp
, *maildir
, *folder
= NULL
;
34 char buf
[BUFSIZ
], **argp
;
35 char **arguments
, **msgs
;
39 setlocale(LC_ALL
, "");
41 invo_name
= r1bindex (argv
[0], '/');
43 /* read user profile/context */
46 arguments
= getarguments (invo_name
, argc
, argv
, 1);
50 * Allocate the initial space to record message
55 if (!(msgs
= (char **) malloc ((size_t) (maxmsgs
* sizeof(*msgs
)))))
56 adios (NULL
, "unable to allocate storage");
59 while ((cp
= *argp
++)) {
61 switch (smatch (++cp
, switches
)) {
63 ambigsw (cp
, switches
);
66 adios (NULL
, "-%s unknown\n", cp
);
69 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
71 print_help (buf
, switches
, 1);
74 print_version(invo_name
);
85 if (*cp
== '+' || *cp
== '@') {
87 adios (NULL
, "only one folder at a time!");
89 folder
= path (cp
+ 1, *cp
== '+' ? TFOLDER
: TSUBCWF
);
92 * Check if we need to allocate more space
93 * for message names/ranges.
95 if (nummsgs
>= maxmsgs
){
97 if (!(msgs
= (char **) realloc (msgs
,
98 (size_t) (maxmsgs
* sizeof(*msgs
)))))
99 adios (NULL
, "unable to reallocate msgs storage");
101 msgs
[nummsgs
++] = cp
;
105 if (!context_find ("path"))
106 free (path ("./", TFOLDER
));
108 msgs
[nummsgs
++] = "cur";
110 folder
= getfolder (1);
111 maildir
= m_maildir (folder
);
113 if (chdir (maildir
) == NOTOK
)
114 adios (maildir
, "unable to change directory to");
116 /* read folder and create message structure */
117 if (!(mp
= folder_read (folder
)))
118 adios (NULL
, "unable to read folder %s", folder
);
120 /* check for empty folder */
122 adios (NULL
, "no messages in %s", folder
);
124 /* parse all the message ranges/sequences and set SELECTED */
125 for (msgnum
= 0; msgnum
< nummsgs
; msgnum
++)
126 if (!m_convert (mp
, msgs
[msgnum
]))
128 seq_setprev (mp
); /* set the previous-sequence */
131 * This is hackish. If we are using a external rmmproc,
132 * then we need to update the current folder in the
133 * context so the external rmmproc will remove files
134 * from the correct directory. This should be moved to
138 context_replace (pfolder
, folder
);
143 /* "remove" the SELECTED messages */
144 folder_delmsgs (mp
, unlink_msgs
);
146 seq_save (mp
); /* synchronize message sequences */
147 context_replace (pfolder
, folder
); /* update current folder */
148 context_save (); /* save the context file */
149 folder_free (mp
); /* free folder structure */