- maildir = m_maildir (folder);
-
- if (chdir (maildir) == NOTOK)
- adios (maildir, "unable to change directory to");
-
- /* read folder and create message structure */
- if (!(mp = folder_read (folder, 1)))
- adios (NULL, "unable to read folder %s", folder);
-
- /* check for empty folder */
- if (mp->nummsg == 0)
- adios (NULL, "no messages in %s", folder);
-
- /* parse all the message ranges/sequences and set SELECTED */
- for (msgnum = 0; msgnum < msgs.size; msgnum++)
- if (!m_convert (mp, msgs.msgs[msgnum]))
- done (1);
-
- /*
- * Set the SELECT_UNSEEN bit for all the SELECTED messages,
- * since we will use that as a tag to know which messages
- * to remove from the "unseen" sequence.
- */
- for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
- if (is_selected(mp, msgnum))
- set_unseen (mp, msgnum);
-
- seq_setprev (mp); /* set the Previous-Sequence */
- seq_setunseen (mp, 1); /* unset the Unseen-Sequence */
+ mh_managed_folders *mmfs;
+ if (!mh_managed_folders_open(&mmfs))
+ die("%s", mh_managed_folders_get_err_string(mmfs));
+ mh_folder *mhf;
+ if (!mh_folder_open(&mhf, folder, mmfs))
+ die("%s", mh_folder_get_err_string(mhf));
+ const struct msgs *const mp = mh_folder_select_and_chdir_and_mark_seen(&vec, mhf, msgs);
+ if (mp == NULL)
+ die("%s", mh_folder_get_err_string(mhf));