- }
-
- /*
- * This is a hack. If we are using an external rmmproc,
- * then save the current folder to the context file,
- * so the external rmmproc will remove files from the correct
- * directory. This should be moved to folder_delmsgs().
- */
- if (rmmproc) {
- context_replace (pfolder, folder);
- context_save ();
- fflush (stdout);
- }
-
- /* If -nolink, then "remove" messages from source folder.
- *
- * Note that folder_delmsgs does not call the delete hook
- * because the message has already been handled above.
- */
- if (!linkf) {
- folder_delmsgs (mp, unlink_msgs, 1);
- }
-
- clsfolds (folders, foldp);
-
- if (mp->hghsel != mp->curmsg
- && (mp->numsel != mp->nummsg || linkf))
- seq_setcur (mp, mp->hghsel);
- seq_save (mp); /* synchronize message sequences */
-
- context_replace (pfolder, folder); /* update current folder */
- context_save (); /* save the context file */
- folder_free (mp); /* free folder structure */
- done (0);
- return 1;
+
+ 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);
+ }
+ }
+
+ /*
+ ** This is a hack. If we are using an external rmmproc,
+ ** then save the current folder to the context file,
+ ** so the external rmmproc will remove files from the correct
+ ** directory. This should be moved to folder_delmsgs().
+ */
+ if (rmmproc) {
+ context_replace(pfolder, folder);
+ context_save();
+ fflush(stdout);
+ }
+
+ /*
+ ** If -nolink, then "remove" messages from source folder.
+ **
+ ** Note that folder_delmsgs does not call the delete hook
+ ** because the message has already been handled above.
+ */
+ if (!linkf) {
+ folder_delmsgs(mp, unlink_msgs, 1);
+ }
+
+ clsfolds(folders, foldp);
+
+ if (mp->hghsel != mp->curmsg &&
+ (mp->numsel != mp->nummsg || linkf))
+ seq_setcur(mp, mp->hghsel);
+ seq_save(mp); /* synchronize message sequences */
+
+ context_replace(pfolder, folder); /* update current folder */
+ context_save(); /* save the context file */
+ folder_free(mp); /* free folder structure */
+ done(0);
+ return 1;