]>
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.
15 * We allocate space for message names and ranges
16 * (msgs array) this number of elements at a time.
20 static struct swit switches
[] = {
34 main (int argc
, char **argv
)
36 int nummsgs
, maxmsgs
, msgnum
, unlink_msgs
= 0;
37 char *cp
, *maildir
, *folder
= NULL
;
38 char buf
[BUFSIZ
], **argp
;
39 char **arguments
, **msgs
;
43 setlocale(LC_ALL
, "");
45 invo_name
= r1bindex (argv
[0], '/');
47 /* read user profile/context */
50 arguments
= getarguments (invo_name
, argc
, argv
, 1);
54 * Allocate the initial space to record message
59 if (!(msgs
= (char **) malloc ((size_t) (maxmsgs
* sizeof(*msgs
)))))
60 adios (NULL
, "unable to allocate storage");
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 if (!(msgs
= (char **) realloc (msgs
,
102 (size_t) (maxmsgs
* sizeof(*msgs
)))))
103 adios (NULL
, "unable to reallocate msgs storage");
105 msgs
[nummsgs
++] = cp
;
109 if (!context_find ("path"))
110 free (path ("./", TFOLDER
));
112 msgs
[nummsgs
++] = "cur";
114 folder
= getfolder (1);
115 maildir
= m_maildir (folder
);
117 if (chdir (maildir
) == NOTOK
)
118 adios (maildir
, "unable to change directory to");
120 /* read folder and create message structure */
121 if (!(mp
= folder_read (folder
)))
122 adios (NULL
, "unable to read folder %s", folder
);
124 /* check for empty folder */
126 adios (NULL
, "no messages in %s", folder
);
128 /* parse all the message ranges/sequences and set SELECTED */
129 for (msgnum
= 0; msgnum
< nummsgs
; msgnum
++)
130 if (!m_convert (mp
, msgs
[msgnum
]))
132 seq_setprev (mp
); /* set the previous-sequence */
135 * This is hackish. If we are using a external rmmproc,
136 * then we need to update the current folder in the
137 * context so the external rmmproc will remove files
138 * from the correct directory. This should be moved to
142 context_replace (pfolder
, folder
);
147 /* "remove" the SELECTED messages */
148 folder_delmsgs (mp
, unlink_msgs
, 0);
150 seq_save (mp
); /* synchronize message sequences */
151 context_replace (pfolder
, folder
); /* update current folder */
152 context_save (); /* save the context file */
153 folder_free (mp
); /* free folder structure */