]>
diplodocus.org Git - nmh/blob - uip/rmm.c
3 * rmm.c -- remove a message(s)
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
16 * We allocate space for message names and ranges
17 * (msgs array) this number of elements at a time.
21 static struct swit switches
[] = {
35 main (int argc
, char **argv
)
37 int nummsgs
, maxmsgs
, msgnum
, unlink_msgs
= 0;
38 char *cp
, *maildir
, *folder
= NULL
;
39 char buf
[BUFSIZ
], **argp
;
40 char **arguments
, **msgs
;
44 setlocale(LC_ALL
, "");
46 invo_name
= r1bindex (argv
[0], '/');
48 /* read user profile/context */
51 arguments
= getarguments (invo_name
, argc
, argv
, 1);
55 * Allocate the initial space to record message
60 msgs
= (char **) mh_xmalloc ((size_t) (maxmsgs
* sizeof(*msgs
)));
63 while ((cp
= *argp
++)) {
65 switch (smatch (++cp
, switches
)) {
67 ambigsw (cp
, switches
);
70 adios (NULL
, "-%s unknown\n", cp
);
73 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
75 print_help (buf
, switches
, 1);
78 print_version(invo_name
);
89 if (*cp
== '+' || *cp
== '@') {
91 adios (NULL
, "only one folder at a time!");
93 folder
= path (cp
+ 1, *cp
== '+' ? TFOLDER
: TSUBCWF
);
96 * Check if we need to allocate more space
97 * for message names/ranges.
99 if (nummsgs
>= maxmsgs
){
101 msgs
= (char **) mh_xrealloc (msgs
,
102 (size_t) (maxmsgs
* sizeof(*msgs
)));
104 msgs
[nummsgs
++] = cp
;
108 if (!context_find ("path"))
109 free (path ("./", TFOLDER
));
111 msgs
[nummsgs
++] = "cur";
113 folder
= getfolder (1);
114 maildir
= m_maildir (folder
);
116 if (chdir (maildir
) == NOTOK
)
117 adios (maildir
, "unable to change directory to");
119 /* read folder and create message structure */
120 if (!(mp
= folder_read (folder
)))
121 adios (NULL
, "unable to read folder %s", folder
);
123 /* check for empty folder */
125 adios (NULL
, "no messages in %s", folder
);
127 /* parse all the message ranges/sequences and set SELECTED */
128 for (msgnum
= 0; msgnum
< nummsgs
; msgnum
++)
129 if (!m_convert (mp
, msgs
[msgnum
]))
131 seq_setprev (mp
); /* set the previous-sequence */
134 * This is hackish. If we are using a external rmmproc,
135 * then we need to update the current folder in the
136 * context so the external rmmproc will remove files
137 * from the correct directory. This should be moved to
141 context_replace (pfolder
, folder
);
146 /* "remove" the SELECTED messages */
147 folder_delmsgs (mp
, unlink_msgs
, 0);
149 seq_save (mp
); /* synchronize message sequences */
150 context_replace (pfolder
, folder
); /* update current folder */
151 context_save (); /* save the context file */
152 folder_free (mp
); /* free folder structure */