]>
diplodocus.org Git - nmh/blob - uip/rmm.c
3 * rmm.c -- remove a message(s)
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
13 static struct swit switches
[] = {
27 main (int argc
, char **argv
)
29 int msgnum
, unlink_msgs
= 0;
30 char *cp
, *maildir
, *folder
= NULL
;
31 char buf
[BUFSIZ
], **argp
;
33 struct msgs_array msgs
= { 0, 0, NULL
};
37 setlocale(LC_ALL
, "");
39 invo_name
= r1bindex (argv
[0], '/');
41 /* read user profile/context */
44 arguments
= getarguments (invo_name
, argc
, argv
, 1);
48 while ((cp
= *argp
++)) {
50 switch (smatch (++cp
, switches
)) {
52 ambigsw (cp
, switches
);
55 adios (NULL
, "-%s unknown\n", cp
);
58 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
60 print_help (buf
, switches
, 1);
63 print_version(invo_name
);
74 if (*cp
== '+' || *cp
== '@') {
76 adios (NULL
, "only one folder at a time!");
78 folder
= pluspath (cp
);
80 app_msgarg(&msgs
, cp
);
83 if (!context_find ("path"))
84 free (path ("./", TFOLDER
));
86 app_msgarg(&msgs
, "cur");
88 folder
= getfolder (1);
89 maildir
= m_maildir (folder
);
91 if (chdir (maildir
) == NOTOK
)
92 adios (maildir
, "unable to change directory to");
94 /* read folder and create message structure */
95 if (!(mp
= folder_read (folder
)))
96 adios (NULL
, "unable to read folder %s", folder
);
98 /* check for empty folder */
100 adios (NULL
, "no messages in %s", folder
);
102 /* parse all the message ranges/sequences and set SELECTED */
103 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
104 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
106 seq_setprev (mp
); /* set the previous-sequence */
109 * This is hackish. If we are using a external rmmproc,
110 * then we need to update the current folder in the
111 * context so the external rmmproc will remove files
112 * from the correct directory. This should be moved to
116 context_replace (pfolder
, folder
);
121 /* "remove" the SELECTED messages */
122 folder_delmsgs (mp
, unlink_msgs
, 0);
124 seq_save (mp
); /* synchronize message sequences */
125 context_replace (pfolder
, folder
); /* update current folder */
126 context_save (); /* save the context file */
127 folder_free (mp
); /* free folder structure */