]>
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 static struct swit switches
[] = {
29 main (int argc
, char **argv
)
31 int msgnum
, unlink_msgs
= 0;
32 char *cp
, *maildir
, *folder
= NULL
;
33 char buf
[BUFSIZ
], **argp
;
35 struct msgs_array msgs
= { 0, 0, NULL
};
39 setlocale(LC_ALL
, "");
41 invo_name
= r1bindex (argv
[0], '/');
43 /* read user profile/context */
46 arguments
= getarguments (invo_name
, argc
, argv
, 1);
50 while ((cp
= *argp
++)) {
52 switch (smatch (++cp
, switches
)) {
54 ambigsw (cp
, switches
);
57 adios (NULL
, "-%s unknown\n", cp
);
60 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
62 print_help (buf
, switches
, 1);
65 print_version(invo_name
);
76 if (*cp
== '+' || *cp
== '@') {
78 adios (NULL
, "only one folder at a time!");
80 folder
= pluspath (cp
);
82 app_msgarg(&msgs
, cp
);
85 if (!context_find ("path"))
86 free (path ("./", TFOLDER
));
88 app_msgarg(&msgs
, "cur");
90 folder
= getfolder (1);
91 maildir
= m_maildir (folder
);
93 if (chdir (maildir
) == NOTOK
)
94 adios (maildir
, "unable to change directory to");
96 /* read folder and create message structure */
97 if (!(mp
= folder_read (folder
)))
98 adios (NULL
, "unable to read folder %s", folder
);
100 /* check for empty folder */
102 adios (NULL
, "no messages in %s", folder
);
104 /* parse all the message ranges/sequences and set SELECTED */
105 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
106 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
108 seq_setprev (mp
); /* set the previous-sequence */
111 * This is hackish. If we are using a external rmmproc,
112 * then we need to update the current folder in the
113 * context so the external rmmproc will remove files
114 * from the correct directory. This should be moved to
118 context_replace (pfolder
, folder
);
123 /* "remove" the SELECTED messages */
124 folder_delmsgs (mp
, unlink_msgs
, 0);
126 seq_save (mp
); /* synchronize message sequences */
127 context_replace (pfolder
, folder
); /* update current folder */
128 context_save (); /* save the context file */
129 folder_free (mp
); /* free folder structure */