--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * Copyright © 2006 Pierre Habouzit
+ */
+
+/*
+ * Copyright notice from original mutt:
+ * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "mem.h"
+#include "str.h"
+#include "list.h"
+
+LIST *mutt_copy_list(LIST *p) {
+ LIST *t, *r = NULL, *l = NULL;
+
+ for (; p; p = p->next) {
+ t = p_new(LIST, 1);
+ t->data = m_strdup(p->data);
+ t->next = NULL;
+ if (l) {
+ r->next = t;
+ r = r->next;
+ } else {
+ l = r = t;
+ }
+ }
+ return l;
+}
+
+LIST *mutt_add_list_n(LIST *head, const void *data, size_t len) {
+ LIST *tmp;
+
+ for (tmp = head; tmp && tmp->next; tmp = tmp->next);
+
+ if (tmp) {
+ tmp->next = p_new(LIST, 1);
+ tmp = tmp->next;
+ } else {
+ head = tmp = p_new(LIST, 1);
+ }
+
+ tmp->data = p_dup((const char *)data, len);
+ tmp->next = NULL;
+ return head;
+}
+
+void mutt_free_list(LIST **list) {
+ LIST *p;
+
+ if (list) {
+ while (*list) {
+ p = *list;
+ *list = (*list)->next;
+ p_delete(&p->data);
+ p_delete(&p);
+ }
+ }
+}