+/*
+ * Merge two maildir lists according to the inode numbers.
+ */
+static struct maildir *maildir_merge_inode (struct maildir *left,
+ struct maildir *right)
+{
+ struct maildir *head;
+ struct maildir *tail;
+
+ if (left && right) {
+ if (left->inode < right->inode) {
+ head = left;
+ left = left->next;
+ }
+ else {
+ head = right;
+ right = right->next;
+ }
+ }
+ else {
+ if (left)
+ return left;
+ else
+ return right;
+ }
+
+ tail = head;
+
+ while (left && right) {
+ if (left->inode < right->inode) {
+ tail->next = left;
+ left = left->next;
+ }
+ else {
+ tail->next = right;
+ right = right->next;
+ }
+ tail = tail->next;
+ }
+
+ if (left) {
+ tail->next = left;
+ }
+ else {
+ tail->next = right;
+ }
+
+ return head;
+}
+
+/*
+ * Sort maildir list according to inode.
+ */
+static struct maildir *maildir_sort_inode (struct maildir *list)
+{
+ struct maildir *left = list;
+ struct maildir *right = list;
+
+ if (!list || !list->next) {
+ return list;
+ }
+
+ list = list->next;
+ while (list && list->next) {
+ right = right->next;
+ list = list->next->next;
+ }
+
+ list = right;
+ right = right->next;
+ list->next = 0;
+
+ left = maildir_sort_inode (left);
+ right = maildir_sort_inode (right);
+ return maildir_merge_inode (left, right);
+}
+
+#if USE_HCACHE
+static size_t maildir_hcache_keylen (const char *fn)
+{
+ const char *p = strchr (fn, ':');
+
+ return p ? (size_t) (p - fn) : mutt_strlen (fn);
+}
+#endif