- }
-
- if (!context_find ("path"))
- free (path ("./", TFOLDER));
- if (!nummsgs)
- msgs[nummsgs++] = "all";
- if (!datesw)
- datesw = "date";
- if (!folder)
- folder = getfolder (1);
- 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)))
- 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 < nummsgs; msgnum++)
- if (!m_convert (mp, msgs[msgnum]))
- done (1);
- seq_setprev (mp); /* set the previous sequence */
-
- if ((nmsgs = read_hdrs (mp, datesw)) <= 0)
- adios (NULL, "no messages to sort");
-
- /*
- * sort a list of pointers to our "messages to be sorted".
- */
- dlist = (struct smsg **) malloc ((nmsgs+1) * sizeof(*dlist));
- if (! dlist)
- adios (NULL, "couldn't allocate sort memory");
- for (i = 0; i < nmsgs; i++)
- dlist[i] = &smsgs[i];
- dlist[nmsgs] = 0;
-
- if (verbose) { /* announce what we're doing */
- if (subjsort)
- printf ("sorting by %s-major %s-minor\n",
- submajor ? subjsort : datesw,
- submajor ? datesw : subjsort);
- else
- printf ("sorting by datefield %s\n", datesw);
- }
-
- /* first sort by date, or by subject-major, date-minor */
- qsort ((char *) dlist, nmsgs, sizeof(*dlist),
- (qsort_comp) (submajor && subjsort ? txtsort : dsort));
-
- /*
- * if we're sorting on subject, we need another list
- * in subject order, then a merge pass to collate the
- * two sorts.
- */
- if (!submajor && subjsort) { /* already date sorted */
- struct smsg **slist, **flist;
- register struct smsg ***il, **fp, **dp;
-
- slist = (struct smsg **) malloc ((nmsgs+1) * sizeof(*slist));
- if (! slist)
- adios (NULL, "couldn't allocate sort memory");
- memcpy((char *)slist, (char *)dlist, (nmsgs+1)*sizeof(*slist));
- qsort((char *)slist, nmsgs, sizeof(*slist), (qsort_comp) subsort);
+
+ if (!msgs.size)
+ app_msgarg(&msgs, seq_all);
+ if (!datesw)
+ datesw = "date";
+ if (!folder)
+ folder = getcurfol();
+ maildir = toabsdir(folder);
+
+ if (chdir(maildir) == NOTOK)
+ adios(maildir, "unable to change directory to");
+
+ /* read 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 all the message ranges/sequences 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 */
+
+ if ((nmsgs = read_hdrs(mp, datesw)) <= 0)
+ adios(NULL, "no messages to sort");