- if (*cp == '+' || *cp == '@') {
- if (foldp > NFOLDERS)
- adios (NULL, "only %d folders allowed!", NFOLDERS);
- folders[foldp++].f_name =
- pluspath (cp);
- } else
- app_msgarg(&msgs, cp);
- }
-
- if (!context_find ("path"))
- free (path ("./", TFOLDER));
- if (foldp == 0)
- adios (NULL, "no folder specified");
-
-#ifdef WHATNOW
- if (!msgs.size && !foldp && !filep && (cp = getenv ("mhdraft")) && *cp)
- files[filep++] = cp;
-#endif /* WHATNOW */
-
- /*
- * We are refiling a file to the folders
- */
- if (filep > 0) {
- if (folder || msgs.size)
- adios (NULL, "use -file or some messages, not both");
- opnfolds (folders, foldp);
- for (i = 0; i < filep; i++)
- if (m_file (files[i], folders, foldp, preserve, 0))
- done (1);
- /* If -nolink, then "remove" files */
- if (!linkf)
- remove_files (filep, filevec);
- done (0);
- }
-
- if (!msgs.size)
- app_msgarg(&msgs, "cur");
- if (!folder)
- folder = getfolder (1);
- strncpy (maildir, m_maildir (folder), sizeof(maildir));
-
- if (chdir (maildir) == NOTOK)
- adios (maildir, "unable to change directory to");
-
- /* read source folder and create message structure */
- if (!(mp = folder_read (folder)))
- adios (NULL, "unable to read folder %s", folder);
-
- /* check for empty folder */
- if (mp->nummsg == 0)
- adios (NULL, "no messages in %s", folder);
-
- /* parse the message range/sequence/name and set SELECTED */
- for (msgnum = 0; msgnum < msgs.size; msgnum++)
- if (!m_convert (mp, msgs.msgs[msgnum]))
- done (1);
- seq_setprev (mp); /* set the previous-sequence */
-
- /* create folder structures for each destination folder */
- opnfolds (folders, foldp);
-
- /* Link all the selected messages into destination folders.
- *
- * This causes the add hook to be run for messages that are
- * linked into another folder. The refile hook is run for
- * messages that are moved to another folder.
- */
- for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
- if (is_selected (mp, msgnum)) {
- cp = getcpy (m_name (msgnum));
- if (m_file (cp, folders, foldp, preserve, !linkf))
- done (1);
- free (cp);
+
+ if (foldp == 0)
+ adios(EX_USAGE, NULL, "no folder specified");
+
+ if (filep > 0) {
+ /*
+ ** We are refiling one or more files (-file) to the folders
+ */
+ if (msgs.size) {
+ adios(EX_USAGE, NULL, "use -file or msgs, not both");
+ }
+ if (folder) {
+ adios(EX_USAGE, NULL, "use -file or -src, not both");
+ }
+ opnfolds(folders, foldp);
+ for (i = 0; i < filep; i++) {
+ if (m_file(files[i], folders, foldp, 0)) {
+ exit(EX_IOERR);
+ }
+ }
+ /* If -nolink, then unlink files */
+ if (!linkf) {
+ int i;
+ char **files = filevec;
+
+ for (i = 0; i < filep; i++) {
+ if (unlink(files[i]) == NOTOK) {
+ admonish(files[i], "unable to unlink");
+ }
+ }
+ }
+ exit(EX_OK);