[gmime: 3/6] Rewrote GMimeReferences to use a GPtrArray



commit 31834dc89402c41379a4b94c25d7a50523b106a7
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date:   Tue Mar 28 09:45:17 2017 -0400

    Rewrote GMimeReferences to use a GPtrArray

 docs/reference/gmime-docs.sgml    |    2 +
 docs/reference/gmime-sections.txt |   33 +++--
 gmime/Makefile.am                 |    2 +
 gmime/gmime-header.c              |   21 ++--
 gmime/gmime-parse-utils.c         |   94 +++++++++++++
 gmime/gmime-parse-utils.h         |    9 ++
 gmime/gmime-references.c          |  253 ++++++++++++++++++++++++++++++++++
 gmime/gmime-references.h          |   65 +++++++++
 gmime/gmime-utils.c               |  270 -------------------------------------
 gmime/gmime-utils.h               |   30 ----
 10 files changed, 456 insertions(+), 323 deletions(-)
---
diff --git a/docs/reference/gmime-docs.sgml b/docs/reference/gmime-docs.sgml
index e06ef8e..9d10270 100644
--- a/docs/reference/gmime-docs.sgml
+++ b/docs/reference/gmime-docs.sgml
@@ -30,6 +30,7 @@
 <!ENTITY gmime-charset SYSTEM "xml/gmime-charset.xml">
 <!ENTITY gmime-iconv SYSTEM "xml/gmime-iconv.xml">
 <!ENTITY gmime-iconv-utils SYSTEM "xml/gmime-iconv-utils.xml">
+<!ENTITY GMimeReferences SYSTEM "xml/gmime-references.xml">
 <!ENTITY GMimeStream SYSTEM "xml/gmime-stream.xml">
 <!ENTITY GMimeStreamBuffer SYSTEM "xml/gmime-stream-buffer.xml">
 <!ENTITY GMimeStreamCat SYSTEM "xml/gmime-stream-cat.xml">
@@ -178,6 +179,7 @@ string utilities, file utilities, a main loop abstraction, and so on.
     &gmime-iconv-utils;
     &gmime-encodings;
     &gmime-utils;
+    &GMimeReferences;
     &GMimeFormatOptions;
   </part>
 
diff --git a/docs/reference/gmime-sections.txt b/docs/reference/gmime-sections.txt
index 3bd6a19..e438ad8 100644
--- a/docs/reference/gmime-sections.txt
+++ b/docs/reference/gmime-sections.txt
@@ -1076,19 +1076,32 @@ GMimeTextPartClass
 </SECTION>
 
 <SECTION>
+<FILE>gmime-references</FILE>
+GMimeReferences
+g_mime_references_new
+g_mime_references_free
+g_mime_references_copy
+g_mime_references_parse
+g_mime_references_length
+g_mime_references_append
+g_mime_references_clear
+g_mime_references_get_message_id
+g_mime_references_set_message_id
+
+<SUBSECTION Private>
+g_mime_references_get_type
+
+<SUBSECTION Standard>
+GMIME_TYPE_REFERENCES
+</SECTION>
+
+<SECTION>
 <FILE>gmime-utils</FILE>
 GMimeReferences
 g_mime_utils_header_decode_date
 g_mime_utils_header_format_date
 g_mime_utils_generate_message_id
 g_mime_utils_decode_message_id
-g_mime_references_get_message_id
-g_mime_references_get_next
-g_mime_references_decode
-g_mime_references_append
-g_mime_references_clear
-g_mime_references_copy
-g_mime_references_free
 g_mime_utils_header_printf
 g_mime_utils_quote_string
 g_mime_utils_unquote_string
@@ -1101,12 +1114,6 @@ g_mime_utils_header_decode_phrase
 g_mime_utils_header_encode_phrase
 g_mime_utils_structured_header_fold
 g_mime_utils_unstructured_header_fold
-
-<SUBSECTION Private>
-g_mime_references_get_type
-
-<SUBSECTION Standard>
-GMIME_TYPE_REFERENCES
 </SECTION>
 
 <SECTION>
diff --git a/gmime/Makefile.am b/gmime/Makefile.am
index cb88f0c..bf25ad3 100644
--- a/gmime/Makefile.am
+++ b/gmime/Makefile.am
@@ -66,6 +66,7 @@ libgmime_3_0_la_SOURCES =             \
        gmime-part.c                    \
        gmime-part-iter.c               \
        gmime-pkcs7-context.c           \
+       gmime-references.c              \
        gmime-signature.c               \
        gmime-stream.c                  \
        gmime-stream-buffer.c           \
@@ -126,6 +127,7 @@ gmimeinclude_HEADERS =                      \
        gmime-part.h                    \
        gmime-part-iter.h               \
        gmime-pkcs7-context.h           \
+       gmime-references.h              \
        gmime-signature.h               \
        gmime-stream.h                  \
        gmime-stream-buffer.h           \
diff --git a/gmime/gmime-header.c b/gmime/gmime-header.c
index 7b409bd..aa8bcb4 100644
--- a/gmime/gmime-header.c
+++ b/gmime/gmime-header.c
@@ -31,6 +31,7 @@
 #include "gmime-parse-utils.h"
 #include "gmime-stream-mem.h"
 #include "internet-address.h"
+#include "gmime-references.h"
 #include "gmime-internal.h"
 #include "gmime-common.h"
 #include "gmime-header.h"
@@ -497,22 +498,24 @@ g_mime_header_format_message_id (GMimeHeader *header, GMimeFormatOptions *option
 char *
 g_mime_header_format_references (GMimeHeader *header, GMimeFormatOptions *options, const char *value, const 
char *charset)
 {
-       GMimeReferences *references, *reference;
-       const char *newline;
+       const char *newline, *msgid;
+       GMimeReferences *refs;
        guint cur, len, n;
        GString *str;
+       int count, i;
        
        /* Note: we don't want to break in the middle of msgid tokens as
           it seems to break a lot of clients (and servers) */
        newline = g_mime_format_options_get_newline (options);
-       references = g_mime_references_decode (value);
+       refs = g_mime_references_parse (value);
        str = g_string_new (header->raw_name);
        g_string_append_c (str, ':');
        cur = n = str->len;
        
-       reference = references;
-       while (reference != NULL) {
-               len = strlen (reference->msgid);
+       count = g_mime_references_length (refs);
+       for (i = 0; i < count; i++) {
+               msgid = g_mime_references_get_message_id (refs, i);
+               len = strlen (msgid);
                if (cur > 1 && cur + len + 3 >= GMIME_FOLD_LEN) {
                        g_string_append (str, newline);
                        g_string_append_c (str, '\t');
@@ -523,14 +526,12 @@ g_mime_header_format_references (GMimeHeader *header, GMimeFormatOptions *option
                }
                
                g_string_append_c (str, '<');
-               g_string_append_len (str, reference->msgid, len);
+               g_string_append_len (str, msgid, len);
                g_string_append_c (str, '>');
                cur += len + 2;
-               
-               reference = reference->next;
        }
        
-       g_mime_references_clear (&references);
+       g_mime_references_free (refs);
        
        g_string_append (str, newline);
        
diff --git a/gmime/gmime-parse-utils.c b/gmime/gmime-parse-utils.c
index 44d5289..43c6f70 100644
--- a/gmime/gmime-parse-utils.c
+++ b/gmime/gmime-parse-utils.c
@@ -446,3 +446,97 @@ g_mime_decode_domain (const char **in, GString *domain)
        
        return domain->len > initial;
 }
+
+
+char *
+g_mime_decode_addrspec (const char **in)
+{
+       const char *word, *inptr;
+       GString *addrspec;
+       char *str;
+       
+       skip_cfws (in);
+       inptr = *in;
+       
+       if (!(word = decode_word (&inptr))) {
+               w(g_warning ("No local-part in addr-spec: %s", *in));
+               return NULL;
+       }
+       
+       addrspec = g_string_new ("");
+       g_string_append_len (addrspec, word, (size_t) (inptr - word));
+       
+       /* get the rest of the local-part */
+       skip_cfws (&inptr);
+       while (*inptr == '.') {
+               g_string_append_c (addrspec, *inptr++);
+               if ((word = decode_word (&inptr))) {
+                       g_string_append_len (addrspec, word, (size_t) (inptr - word));
+                       skip_cfws (&inptr);
+               } else {
+                       w(g_warning ("Invalid local-part in addr-spec: %s", *in));
+                       goto exception;
+               }
+       }
+       
+       /* we should be at the '@' now... */
+       if (*inptr++ != '@') {
+               w(g_warning ("Invalid addr-spec; missing '@': %s", *in));
+               goto exception;
+       }
+       
+       g_string_append_c (addrspec, '@');
+       if (!decode_domain (&inptr, addrspec)) {
+               w(g_warning ("No domain in addr-spec: %s", *in));
+               goto exception;
+       }
+       
+       str = addrspec->str;
+       g_string_free (addrspec, FALSE);
+       
+       *in = inptr;
+       
+       return str;
+       
+ exception:
+       
+       g_string_free (addrspec, TRUE);
+       
+       return NULL;
+}
+
+char *
+g_mime_decode_msgid (const char **in)
+{
+       const char *inptr = *in;
+       char *msgid = NULL;
+       
+       skip_cfws (&inptr);
+       if (*inptr != '<') {
+               w(g_warning ("Invalid msg-id; missing '<': %s", *in));
+       } else {
+               inptr++;
+       }
+       
+       skip_cfws (&inptr);
+       if ((msgid = decode_addrspec (&inptr))) {
+               skip_cfws (&inptr);
+               if (*inptr != '>') {
+                       w(g_warning ("Invalid msg-id; missing '>': %s", *in));
+               } else {
+                       inptr++;
+               }
+               
+               *in = inptr;
+       } else {
+               w(g_warning ("Invalid msg-id; missing addr-spec: %s", *in));
+               *in = inptr;
+               while (*inptr && *inptr != '>')
+                       inptr++;
+               
+               msgid = g_strndup (*in, (size_t) (inptr - *in));
+               *in = inptr;
+       }
+       
+       return msgid;
+}
diff --git a/gmime/gmime-parse-utils.h b/gmime/gmime-parse-utils.h
index 14e7ae6..caee9df 100644
--- a/gmime/gmime-parse-utils.h
+++ b/gmime/gmime-parse-utils.h
@@ -22,6 +22,8 @@
 #ifndef __GMIME_PARSE_UTILS_H__
 #define __GMIME_PARSE_UTILS_H__
 
+#include <glib.h>
+
 G_BEGIN_DECLS
 
 G_GNUC_INTERNAL gboolean g_mime_parse_content_type (const char **in, char **type, char **subtype);
@@ -51,6 +53,13 @@ G_GNUC_INTERNAL const char *g_mime_decode_word (const char **in);
 G_GNUC_INTERNAL gboolean g_mime_decode_domain (const char **in, GString *domain);
 #define decode_domain(in, domain) g_mime_decode_domain (in, domain)
 
+
+G_GNUC_INTERNAL char *g_mime_decode_addrspec (const char **in);
+#define decode_addrspec(in) g_mime_decode_addrspec (in)
+
+G_GNUC_INTERNAL char *g_mime_decode_msgid (const char **in);
+#define decode_msgid(in) g_mime_decode_msgid (in)
+
 G_END_DECLS
 
 #endif /* __GMIME_PARSE_UTILS_H__ */
diff --git a/gmime/gmime-references.c b/gmime/gmime-references.c
new file mode 100644
index 0000000..6689bab
--- /dev/null
+++ b/gmime/gmime-references.c
@@ -0,0 +1,253 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*  GMime
+ *  Copyright (C) 2000-2017 Jeffrey Stedfast
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1
+ *  of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+ *  02110-1301, USA.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "gmime-table-private.h"
+#include "gmime-parse-utils.h"
+#include "gmime-references.h"
+
+
+#ifdef ENABLE_WARNINGS
+#define w(x) x
+#else
+#define w(x)
+#endif /* ENABLE_WARNINGS */
+
+
+/**
+ * SECTION: gmime-references
+ * @title: GMimeReferences
+ * @short_description: a list of Message-Ids
+ * @see_also:
+ *
+ * A list of Message-Ids as found in a References or In-Reply-To header.
+ **/
+
+G_DEFINE_BOXED_TYPE (GMimeReferences, g_mime_references, g_mime_references_copy, g_mime_references_free);
+
+
+/**
+ * g_mime_references_new:
+ *
+ * Creates a new #GMimeReferences.
+ *
+ * Returns: a new #GMimeReferences.
+ **/
+GMimeReferences *
+g_mime_references_new (void)
+{
+       GMimeReferences *refs;
+       
+       refs = g_malloc (sizeof (GMimeReferences));
+       refs->array = g_ptr_array_new ();
+       
+       return refs;
+}
+
+
+/**
+ * g_mime_references_free:
+ * @refs: a #GMimeReferences list
+ *
+ * Frees the #GMimeReferences list.
+ **/
+void
+g_mime_references_free (GMimeReferences *refs)
+{
+       guint i;
+       
+       g_return_if_fail (refs != NULL);
+       
+       for (i = 0; i < refs->array->len; i++)
+               g_free (refs->array->pdata[i]);
+       
+       g_ptr_array_free (refs->array, TRUE);
+       g_free (refs);
+}
+
+
+/**
+ * g_mime_references_parse:
+ * @text: string containing a list of msg-ids
+ *
+ * Decodes a list of msg-ids as in the References and/or In-Reply-To
+ * headers defined in rfc822.
+ *
+ * Returns: a new #GMimeReferences containing the parsed message ids.
+ **/
+GMimeReferences *
+g_mime_references_decode (const char *text)
+{
+       const char *word, *inptr = text;
+       GMimeReferences *refs;
+       char *msgid;
+       
+       g_return_val_if_fail (text != NULL, NULL);
+       
+       refs = g_mime_references_new ();
+       
+       while (*inptr) {
+               skip_cfws (&inptr);
+               if (*inptr == '<') {
+                       /* looks like a msg-id */
+                       if ((msgid = decode_msgid (&inptr))) {
+                               g_mime_references_append (refs, msgid);
+                               g_free (msgid);
+                       } else {
+                               w(g_warning ("Invalid References header: %s", inptr));
+                               break;
+                       }
+               } else if (*inptr) {
+                       /* looks like part of a phrase */
+                       if (!(word = decode_word (&inptr))) {
+                               w(g_warning ("Invalid References header: %s", inptr));
+                               break;
+                       }
+               }
+       }
+       
+       return refs;
+}
+
+
+/**
+ * g_mime_references_copy:
+ * @refs: the list of references to copy
+ *
+ * Copies a #GMimeReferences list.
+ *
+ * Returns: a new #GMimeRewferencxes list that contains
+ * an identical list of items as @refs.
+ **/
+GMimeReferences *
+g_mime_references_copy (GMimeReferences *refs)
+{
+       GMimeReferences *copy;
+       guint i;
+       
+       g_return_val_if_fail (refs != NULL, NULL);
+       
+       copy = g_mime_references_new ();
+       for (i = 0; i < refs->array->len; i++)
+               g_mime_references_append (copy, refs->array->pdata[i]);
+       
+       return copy;
+}
+
+
+/**
+ * g_mime_references_length:
+ * @refs: a #GMimeReferences
+ *
+ * Gets the length of the #GMimeReferences list.
+ *
+ * Returns: the number of message ids in the list.
+ **/
+int
+g_mime_references_length (GMimeReferences *refs)
+{
+       g_return_val_if_fail (refs != NULL, 0);
+       
+       return refs->array->len;
+}
+
+
+/**
+ * g_mime_references_append:
+ * @refs: a #GMimeReferences
+ * @msgid: a message-id string
+ *
+ * Appends a reference to msgid to the list of references.
+ **/
+void
+g_mime_references_append (GMimeReferences *refs, const char *msgid)
+{
+       g_return_if_fail (refs != NULL);
+       g_return_if_fail (msgid != NULL);
+       
+       g_ptr_array_add (refs->array, g_strdup (msgid));
+}
+
+
+/**
+ * g_mime_references_clear:
+ * @refs: a #GMimeReferences
+ *
+ * Clears the #GMimeReferences list.
+ **/
+void
+g_mime_references_clear (GMimeReferences *refs)
+{
+       guint i;
+       
+       g_return_if_fail (refs != NULL);
+       
+       for (i = 0; i < refs->array->len; i++)
+               g_free (refs->array->pdata[i]);
+       
+       g_ptr_array_set_size (refs->array, 0);
+}
+
+
+/**
+ * g_mime_references_get_message_id:
+ * @ref: a #GMimeReferences
+ * @index: the index of the message id
+ *
+ * Gets the specified Message-Id reference from the #GMimeReferences.
+ *
+ * Returns: the Message-Id reference from the #GMimeReferences.
+ **/
+const char *
+g_mime_references_get_message_id (GMimeReferences *refs, int index)
+{
+       g_return_val_if_fail (refs != NULL, NULL);
+       g_return_val_if_fail (index < 0, NULL);
+       g_return_val_if_fail (index >= refs->array->len, NULL);
+       
+       return refs->array->pdata[index];
+}
+
+
+/**
+ * g_mime_references_set_message_id:
+ * @ref: a #GMimeReferences
+ * @index: the index of the message id
+ * @msgid: the message id
+ *
+ * Sets the specified Message-Id reference from the #GMimeReferences.
+ **/
+void
+g_mime_references_set_message_id (GMimeReferences *refs, int index, const char *msgid)
+{
+       char *buf;
+       
+       g_return_if_fail (refs != NULL);
+       g_return_if_fail (index < 0);
+       g_return_if_fail (index >= refs->array->len);
+       
+       buf = g_strdup (msgid);
+       g_free (refs->array->pdata[index]);
+       refs->array->pdata[index] = buf;
+}
diff --git a/gmime/gmime-references.h b/gmime/gmime-references.h
new file mode 100644
index 0000000..34c9383
--- /dev/null
+++ b/gmime/gmime-references.h
@@ -0,0 +1,65 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*  GMime
+ *  Copyright (C) 2000-2017 Jeffrey Stedfast
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1
+ *  of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+ *  02110-1301, USA.
+ */
+
+
+#ifndef __GMIME_REFERENCES_H__
+#define __GMIME_REFERENCES_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GMIME_TYPE_REFERENCES (gmime_references_get_type ())
+
+typedef struct _GMimeReferences GMimeReferences;
+
+/**
+ * GMimeReferences:
+ * @array: the array of message-id references
+ *
+ * A List of references, as per the References or In-Reply-To header
+ * fields.
+ **/
+struct _GMimeReferences {
+       GPtrArray *array;
+};
+
+
+GType g_mime_references_get_type (void) G_GNUC_CONST;
+
+GMimeReferences *g_mime_references_new (void);
+void g_mime_references_free (GMimeReferences *refs);
+
+GMimeReferences *g_mime_references_parse (const char *text);
+
+GMimeReferences *g_mime_references_copy (GMimeReferences *refs);
+
+int g_mime_references_length (GMimeReferences *refs);
+
+void g_mime_references_append (GMimeReferences *refs, const char *msgid);
+void g_mime_references_clear (GMimeReferences *refs);
+
+const char *g_mime_references_get_message_id (GMimeReferences *refs, int index);
+void g_mime_references_set_message_id (GMimeReferences *refs, int index, const char *msgid);
+
+G_END_DECLS
+
+#endif /* __GMIME_REFERENCES_H__ */
diff --git a/gmime/gmime-utils.c b/gmime/gmime-utils.c
index 3461ba1..6e53575 100644
--- a/gmime/gmime-utils.c
+++ b/gmime/gmime-utils.c
@@ -866,99 +866,6 @@ g_mime_utils_generate_message_id (const char *fqdn)
        return g_string_free (msgid, FALSE);
 }
 
-static char *
-decode_addrspec (const char **in)
-{
-       const char *word, *inptr;
-       GString *addrspec;
-       char *str;
-       
-       skip_cfws (in);
-       inptr = *in;
-       
-       if (!(word = decode_word (&inptr))) {
-               w(g_warning ("No local-part in addr-spec: %s", *in));
-               return NULL;
-       }
-       
-       addrspec = g_string_new ("");
-       g_string_append_len (addrspec, word, (size_t) (inptr - word));
-       
-       /* get the rest of the local-part */
-       skip_cfws (&inptr);
-       while (*inptr == '.') {
-               g_string_append_c (addrspec, *inptr++);
-               if ((word = decode_word (&inptr))) {
-                       g_string_append_len (addrspec, word, (size_t) (inptr - word));
-                       skip_cfws (&inptr);
-               } else {
-                       w(g_warning ("Invalid local-part in addr-spec: %s", *in));
-                       goto exception;
-               }
-       }
-       
-       /* we should be at the '@' now... */
-       if (*inptr++ != '@') {
-               w(g_warning ("Invalid addr-spec; missing '@': %s", *in));
-               goto exception;
-       }
-       
-       g_string_append_c (addrspec, '@');
-       if (!decode_domain (&inptr, addrspec)) {
-               w(g_warning ("No domain in addr-spec: %s", *in));
-               goto exception;
-       }
-       
-       str = addrspec->str;
-       g_string_free (addrspec, FALSE);
-       
-       *in = inptr;
-       
-       return str;
-       
- exception:
-       
-       g_string_free (addrspec, TRUE);
-       
-       return NULL;
-}
-
-static char *
-decode_msgid (const char **in)
-{
-       const char *inptr = *in;
-       char *msgid = NULL;
-       
-       skip_cfws (&inptr);
-       if (*inptr != '<') {
-               w(g_warning ("Invalid msg-id; missing '<': %s", *in));
-       } else {
-               inptr++;
-       }
-       
-       skip_cfws (&inptr);
-       if ((msgid = decode_addrspec (&inptr))) {
-               skip_cfws (&inptr);
-               if (*inptr != '>') {
-                       w(g_warning ("Invalid msg-id; missing '>': %s", *in));
-               } else {
-                       inptr++;
-               }
-               
-               *in = inptr;
-       } else {
-               w(g_warning ("Invalid msg-id; missing addr-spec: %s", *in));
-               *in = inptr;
-               while (*inptr && *inptr != '>')
-                       inptr++;
-               
-               msgid = g_strndup (*in, (size_t) (inptr - *in));
-               *in = inptr;
-       }
-       
-       return msgid;
-}
-
 
 /**
  * g_mime_utils_decode_message_id:
@@ -976,183 +883,6 @@ g_mime_utils_decode_message_id (const char *message_id)
        return decode_msgid (&message_id);
 }
 
-
-G_DEFINE_BOXED_TYPE (GMimeReferences, g_mime_references, g_mime_references_copy, g_mime_references_free);
-
-
-/**
- * g_mime_references_decode:
- * @text: string containing a list of msg-ids
- *
- * Decodes a list of msg-ids as in the References and/or In-Reply-To
- * headers defined in rfc822.
- *
- * Returns: a list of referenced msg-ids.
- **/
-GMimeReferences *
-g_mime_references_decode (const char *text)
-{
-       GMimeReferences refs, *tail, *ref;
-       const char *word, *inptr = text;
-       char *msgid;
-       
-       g_return_val_if_fail (text != NULL, NULL);
-       
-       tail = (GMimeReferences *) &refs;
-       refs.next = NULL;
-       
-       while (*inptr) {
-               skip_cfws (&inptr);
-               if (*inptr == '<') {
-                       /* looks like a msg-id */
-                       if ((msgid = decode_msgid (&inptr))) {
-                               ref = g_new (GMimeReferences, 1);
-                               ref->next = NULL;
-                               ref->msgid = msgid;
-                               tail->next = ref;
-                               tail = ref;
-                       } else {
-                               w(g_warning ("Invalid References header: %s", inptr));
-                               break;
-                       }
-               } else if (*inptr) {
-                       /* looks like part of a phrase */
-                       if (!(word = decode_word (&inptr))) {
-                               w(g_warning ("Invalid References header: %s", inptr));
-                               break;
-                       }
-               }
-       }
-       
-       return refs.next;
-}
-
-
-/**
- * g_mime_references_copy:
- * @references: the list of references to copy
- *
- * Copies a #GMimeReferences linked list.
- *
- * Returns: a newly allocated linked list that contains
- * an identical list of items as @references.
- **/
-GMimeReferences *
-g_mime_references_copy (GMimeReferences *references)
-{
-       GMimeReferences *ref, *node, *copy = NULL;
-       
-       ref = references;
-       while (ref != NULL) {
-               if (copy == NULL) {
-                       copy = node = g_new (GMimeReferences, 1);
-               } else {
-                       node->next = g_new (GMimeReferences, 1);
-                       node = node->next;
-               }
-               
-               node->msgid = g_strdup (ref->msgid);
-               node->next = NULL;
-               
-               ref = ref->next;
-       }
-       
-       return copy;
-}
-
-
-/**
- * g_mime_references_append:
- * @refs: the address of a #GMimeReferences list
- * @msgid: a message-id string
- *
- * Appends a reference to msgid to the list of references.
- **/
-void
-g_mime_references_append (GMimeReferences **refs, const char *msgid)
-{
-       GMimeReferences *ref;
-       
-       g_return_if_fail (refs != NULL);
-       g_return_if_fail (msgid != NULL);
-       
-       ref = (GMimeReferences *) refs;
-       while (ref->next)
-               ref = ref->next;
-       
-       ref->next = g_new (GMimeReferences, 1);
-       ref->next->msgid = g_strdup (msgid);
-       ref->next->next = NULL;
-}
-
-
-/**
- * g_mime_references_free:
- * @refs: a #GMimeReferences list
- *
- * Frees the #GMimeReferences list.
- **/
-void
-g_mime_references_free (GMimeReferences *refs)
-{
-       GMimeReferences *ref, *next;
-       
-       ref = refs;
-       while (ref) {
-               next = ref->next;
-               g_free (ref->msgid);
-               g_free (ref);
-               ref = next;
-       }
-}
-
-
-/**
- * g_mime_references_clear:
- * @refs: address of a #GMimeReferences list
- *
- * Clears the #GMimeReferences list and resets it to %NULL.
- **/
-void
-g_mime_references_clear (GMimeReferences **refs)
-{
-       g_return_if_fail (refs != NULL);
-       
-       g_mime_references_free (*refs);
-       *refs = NULL;
-}
-
-
-/**
- * g_mime_references_get_next:
- * @ref: a #GMimeReferences list
- *
- * Advances to the next reference node in the #GMimeReferences list.
- *
- * Returns: the next reference node in the #GMimeReferences list.
- **/
-const GMimeReferences *
-g_mime_references_get_next (const GMimeReferences *ref)
-{
-       return ref ? ref->next : NULL;
-}
-
-
-/**
- * g_mime_references_get_message_id:
- * @ref: a #GMimeReferences list
- *
- * Gets the Message-Id reference from the #GMimeReferences node.
- *
- * Returns: the Message-Id reference from the #GMimeReferences node.
- **/
-const char *
-g_mime_references_get_message_id (const GMimeReferences *ref)
-{
-       return ref ? ref->msgid : NULL;
-}
-
-
 static gboolean
 need_quotes (const char *string)
 {
diff --git a/gmime/gmime-utils.h b/gmime/gmime-utils.h
index 8bcfc1f..c2517af 100644
--- a/gmime/gmime-utils.h
+++ b/gmime/gmime-utils.h
@@ -23,8 +23,6 @@
 #define __GMIME_UTILS_H__
 
 #include <glib.h>
-#include <glib-object.h>
-#include <time.h>
 #include <stdarg.h>
 
 #include <gmime/gmime-format-options.h>
@@ -33,24 +31,6 @@
 
 G_BEGIN_DECLS
 
-#define GMIME_TYPE_REFERENCES (gmime_references_get_type ())
-
-typedef struct _GMimeReferences GMimeReferences;
-
-/**
- * GMimeReferences:
- * @next: Pointer to the next reference.
- * @msgid: Reference message-id.
- *
- * A List of references, as per the References or In-Reply-To header
- * fields.
- **/
-struct _GMimeReferences {
-       GMimeReferences *next;
-       char *msgid;
-};
-
-
 GDateTime *g_mime_utils_header_decode_date (const char *str);
 char *g_mime_utils_header_format_date (GDateTime *date);
 
@@ -59,16 +39,6 @@ char *g_mime_utils_generate_message_id (const char *fqdn);
 /* decode a message-id */
 char *g_mime_utils_decode_message_id (const char *message_id);
 
-/* decode a References or In-Reply-To header */
-GType g_mime_references_get_type (void) G_GNUC_CONST;
-GMimeReferences *g_mime_references_decode (const char *text);
-GMimeReferences *g_mime_references_copy (GMimeReferences *references);
-void g_mime_references_append (GMimeReferences **refs, const char *msgid);
-void g_mime_references_clear (GMimeReferences **refs);
-void g_mime_references_free (GMimeReferences *refs);
-const GMimeReferences *g_mime_references_get_next (const GMimeReferences *ref);
-const char *g_mime_references_get_message_id (const GMimeReferences *ref);
-
 char  *g_mime_utils_structured_header_fold (GMimeParserOptions *options, GMimeFormatOptions *format, const 
char *header);
 char  *g_mime_utils_unstructured_header_fold (GMimeParserOptions *options, GMimeFormatOptions *format, const 
char *header);
 char  *g_mime_utils_header_printf (GMimeParserOptions *options, GMimeFormatOptions *format, const char 
*text, ...) G_GNUC_PRINTF (3, 4);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]