gmime r1397 - in trunk: . docs/reference gmime mono tests tools
- From: fejj svn gnome org
- To: svn-commits-list gnome org
- Subject: gmime r1397 - in trunk: . docs/reference gmime mono tests tools
- Date: Sat, 16 Aug 2008 05:57:41 +0000 (UTC)
Author: fejj
Date: Sat Aug 16 05:57:40 2008
New Revision: 1397
URL: http://svn.gnome.org/viewvc/gmime?rev=1397&view=rev
Log:
2008-08-16 Jeffrey Stedfast <fejj novell com>
* mono/InternetAddressList.cs: Rewritten to be more awesome. Now
implements IList.
* tools/gmime-port-2-2-to-2-4.sh: Updated.
* gmime/gmime-message.c: Updated for InternetAddressList API
changes.
* gmime/internet-address.c: Completely reworked the
InternetAddressList API.
(internet_address_list_parse_string): Renamed from
internet_address_parse_string().
Added:
trunk/mono/InternetAddress.custom
Modified:
trunk/ChangeLog
trunk/docs/reference/gmime-sections.txt
trunk/gmime/gmime-message.c
trunk/gmime/internet-address.c
trunk/gmime/internet-address.h
trunk/mono/GMime.metadata
trunk/mono/InternetAddressList.cs
trunk/mono/Makefile.am
trunk/mono/gmime-api.raw
trunk/tests/test-mime.c
trunk/tools/gmime-port-2-2-to-2-4.sh
Modified: trunk/docs/reference/gmime-sections.txt
==============================================================================
--- trunk/docs/reference/gmime-sections.txt (original)
+++ trunk/docs/reference/gmime-sections.txt Sat Aug 16 05:57:40 2008
@@ -949,16 +949,22 @@
internet_address_set_group
internet_address_add_member
internet_address_get_members
-internet_address_list_prepend
-internet_address_list_append
-internet_address_list_concat
-internet_address_list_length
+internet_address_to_string
+internet_address_list_new
internet_address_list_destroy
-internet_address_list_next
+internet_address_list_length
+internet_address_list_clear
+internet_address_list_add
+internet_address_list_concat
+internet_address_list_insert
+internet_address_list_remove
+internet_address_list_remove_at
+internet_address_list_contains
+internet_address_list_index_of
internet_address_list_get_address
-internet_address_parse_string
-internet_address_to_string
+internet_address_list_set_address
internet_address_list_to_string
+internet_address_list_parse_string
internet_address_list_writer
</SECTION>
Modified: trunk/gmime/gmime-message.c
==============================================================================
--- trunk/gmime/gmime-message.c (original)
+++ trunk/gmime/gmime-message.c Sat Aug 16 05:57:40 2008
@@ -581,7 +581,7 @@
str = g_string_new (name);
g_string_append (str, ": ");
- if (value && (addrlist = internet_address_parse_string (value))) {
+ if (value && (addrlist = internet_address_list_parse_string (value))) {
internet_address_list_writer (addrlist, str);
internet_address_list_destroy (addrlist);
}
@@ -634,13 +634,13 @@
switch (i) {
case HEADER_FROM:
g_free (message->from);
- addrlist = internet_address_parse_string (value);
+ addrlist = internet_address_list_parse_string (value);
message->from = internet_address_list_to_string (addrlist, FALSE);
internet_address_list_destroy (addrlist);
break;
case HEADER_REPLY_TO:
g_free (message->reply_to);
- addrlist = internet_address_parse_string (value);
+ addrlist = internet_address_list_parse_string (value);
message->reply_to = internet_address_list_to_string (addrlist, FALSE);
internet_address_list_destroy (addrlist);
break;
@@ -954,7 +954,7 @@
g_free (message->from);
- addrlist = internet_address_parse_string (sender);
+ addrlist = internet_address_list_parse_string (sender);
message->from = internet_address_list_to_string (addrlist, FALSE);
encoded = internet_address_list_to_string (addrlist, TRUE);
internet_address_list_destroy (addrlist);
@@ -1060,7 +1060,7 @@
recipients = g_hash_table_lookup (message->recipients, recipient_types[type]);
g_hash_table_remove (message->recipients, recipient_types[type]);
- recipients = internet_address_list_append (recipients, ia);
+ internet_address_list_add (recipients, ia);
internet_address_unref (ia);
g_hash_table_insert (message->recipients, (char *) recipient_types[type], recipients);
@@ -1076,8 +1076,8 @@
recipients = g_hash_table_lookup (message->recipients, recipient_types[type]);
g_hash_table_remove (message->recipients, recipient_types[type]);
- if ((addrlist = internet_address_parse_string (str))) {
- recipients = internet_address_list_concat (recipients, addrlist);
+ if ((addrlist = internet_address_list_parse_string (str))) {
+ internet_address_list_concat (recipients, addrlist);
internet_address_list_destroy (addrlist);
}
@@ -1134,31 +1134,24 @@
* Gets the complete list of recipients for @message.
*
* Returns: a newly allocated #InternetAddressList containing all
- * recipients of the message.
+ * recipients of the message or %NULL if no recipients are set.
**/
InternetAddressList *
g_mime_message_get_all_recipients (GMimeMessage *message)
{
- InternetAddressList *list, *tail, *node, *recipients;
+ InternetAddressList *recipients, *list = NULL;
guint i;
g_return_val_if_fail (GMIME_IS_MESSAGE (message), NULL);
- list = NULL;
- tail = (InternetAddressList *) &list;
-
for (i = 0; i < G_N_ELEMENTS (recipient_types); i++) {
- recipients = g_hash_table_lookup (message->recipients, recipient_types[i]);
- while (recipients != NULL) {
- internet_address_ref (recipients->address);
- node = g_new (InternetAddressList, 1);
- node->address = recipients->address;
- node->next = NULL;
- tail->next = node;
- tail = node;
-
- recipients = recipients->next;
- }
+ if (!(recipients = g_hash_table_lookup (message->recipients, recipient_types[i])))
+ continue;
+
+ if (list == NULL)
+ list = internet_address_list_new ();
+
+ internet_address_list_concat (list, recipients);
}
return list;
Modified: trunk/gmime/internet-address.c
==============================================================================
--- trunk/gmime/internet-address.c (original)
+++ trunk/gmime/internet-address.c Sat Aug 16 05:57:40 2008
@@ -55,6 +55,11 @@
**/
+struct _InternetAddressList {
+ GPtrArray *array;
+};
+
+
/**
* internet_address_new:
*
@@ -171,6 +176,7 @@
InternetAddress *ia;
ia = internet_address_new ();
+ ia->value.members = internet_address_list_new ();
ia->type = INTERNET_ADDRESS_GROUP;
if (name) {
ia->name = g_mime_utils_header_decode_phrase (name);
@@ -255,7 +261,10 @@
g_return_if_fail (member != NULL);
ia->type = INTERNET_ADDRESS_GROUP;
- ia->value.members = internet_address_list_append (ia->value.members, member);
+ if (ia->value.members == NULL)
+ ia->value.members = internet_address_list_new ();
+
+ internet_address_list_add (ia->value.members, member);
}
@@ -332,181 +341,321 @@
}
+
/**
- * internet_address_list_prepend:
- * @list: a list of internet addresses
- * @ia: internet address to prepend
+ * internet_address_list_new:
*
- * Prepends the internet address @ia to the list of internet addresses
- * pointed to by @list.
+ * Creates a new #InternetAddressList.
*
- * Returns: the resultant list.
+ * Returns: a new #InternetAddressList.
**/
InternetAddressList *
-internet_address_list_prepend (InternetAddressList *list, InternetAddress *ia)
+internet_address_list_new (void)
{
- InternetAddressList *node;
+ InternetAddressList *list;
- g_return_val_if_fail (ia != NULL, NULL);
+ list = g_new (InternetAddressList, 1);
+ list->array = g_ptr_array_new ();
- internet_address_ref (ia);
- node = g_new (InternetAddressList, 1);
- node->address = ia;
- node->next = list;
+ return list;
+}
+
+
+/**
+ * internet_address_list_destroy:
+ * @list: a #InternetAddressList
+ *
+ * Destroys the list of #InternetAddress objects.
+ **/
+void
+internet_address_list_destroy (InternetAddressList *list)
+{
+ guint i;
+
+ if (list == NULL)
+ return;
- return node;
+ for (i = 0; i < list->array->len; i++)
+ internet_address_unref (list->array->pdata[i]);
+
+ g_ptr_array_free (list->array, TRUE);
+ g_free (list);
}
/**
- * internet_address_list_append:
- * @list: a list of internet addresses
- * @ia: internet address to append
+ * internet_address_list_length:
+ * @list: a #InternetAddressList
*
- * Appends the internet address to the list of internet addresses
- * pointed to by @list.
+ * Gets the length of the list.
*
- * Returns: the resultant list.
+ * Returns: the number of #InternetAddress objects in the list.
**/
-InternetAddressList *
-internet_address_list_append (InternetAddressList *list, InternetAddress *ia)
+int
+internet_address_list_length (const InternetAddressList *list)
{
- InternetAddressList *node, *n;
+ g_return_val_if_fail (list != NULL, -1);
- g_return_val_if_fail (ia != NULL, NULL);
+ return list->array->len;
+}
+
+
+/**
+ * internet_address_list_clear:
+ * @list: a #InternetAddressList
+ *
+ * Clears the list of addresses.
+ **/
+void
+internet_address_list_clear (InternetAddressList *list)
+{
+ guint i;
- internet_address_ref (ia);
- node = g_new (InternetAddressList, 1);
- node->next = NULL;
- node->address = ia;
+ g_return_if_fail (list != NULL);
- if (list == NULL)
- return node;
+ for (i = 0; i < list->array->len; i++)
+ internet_address_unref (list->array->pdata[i]);
- n = list;
- while (n->next)
- n = n->next;
+ g_ptr_array_set_size (list->array, 0);
+}
+
+
+/**
+ * internet_address_list_add:
+ * @list: a #InternetAddressList
+ * @ia: a #InternetAddress
+ *
+ * Adds an #InternetAddress to the #InternetAddressList.
+ *
+ * Returns: the index of the added #InternetAddress.
+ **/
+int
+internet_address_list_add (InternetAddressList *list, InternetAddress *ia)
+{
+ g_return_val_if_fail (list != NULL, -1);
+ g_return_val_if_fail (ia != NULL, -1);
- n->next = node;
+ g_ptr_array_add (list->array, ia);
+ internet_address_ref (ia);
- return list;
+ return list->array->len - 1;
}
/**
* internet_address_list_concat:
- * @a: first list
- * @b: second list
- *
- * Concatenates a copy of list @b onto the end of list @a.
+ * @list: a #InternetAddressList
+ * @concat: a #InternetAddressList
*
- * Returns: the resulting list.
+ * Adds all of the addresses in @concat to @list.
**/
-InternetAddressList *
-internet_address_list_concat (InternetAddressList *a, InternetAddressList *b)
+void
+internet_address_list_concat (InternetAddressList *list, InternetAddressList *concat)
{
- InternetAddressList *node, *tail, *n;
+ InternetAddress *ia;
+ guint i;
- if (b == NULL)
- return a;
+ g_return_if_fail (concat != NULL);
+ g_return_if_fail (list != NULL);
- /* find the end of list a */
- if (a != NULL) {
- tail = a;
- while (tail->next)
- tail = tail->next;
- } else {
- tail = (InternetAddressList *) &a;
+ for (i = 0; i < concat->array->len; i++) {
+ ia = (InternetAddress *) concat->array->pdata[i];
+ g_ptr_array_add (list->array, ia);
+ internet_address_ref (ia);
}
+}
+
+
+/**
+ * internet_address_list_insert:
+ * @list: a #InternetAddressList
+ * @index: index to insert at
+ * @ia: a #InternetAddress
+ *
+ * Inserts an #InternetAddress into the #InternetAddressList at the
+ * specified index.
+ **/
+void
+internet_address_list_insert (InternetAddressList *list, int index, InternetAddress *ia)
+{
+ char *dest, *src;
+ size_t n;
- /* concat a copy of list b to list a */
- node = b;
- while (node) {
- internet_address_ref (node->address);
- n = g_new (InternetAddressList, 1);
- n->next = NULL;
- n->address = node->address;
- tail->next = n;
- tail = n;
-
- node = node->next;
+ g_return_if_fail (list != NULL);
+ g_return_if_fail (ia != NULL);
+ g_return_if_fail (index < 0);
+
+ internet_address_ref (ia);
+
+ if ((guint) index >= list->array->len) {
+ /* the easy case */
+ g_ptr_array_add (list->array, ia);
+ return;
}
- return a;
+ g_ptr_array_set_size (list->array, list->array->len + 1);
+
+ dest = ((char *) list->array->pdata) + (sizeof (void *) * (index + 1));
+ src = ((char *) list->array->pdata) + (sizeof (void *) * index);
+ n = list->array->len - index - 1;
+
+ g_memmove (dest, src, (sizeof (void *) * n));
+ list->array->pdata[index] = ia;
}
/**
- * internet_address_list_next:
- * @list: list of internet addresses
+ * internet_address_list_remove:
+ * @list: a #InternetAddressList
+ * @ia: a #InternetAddress
*
- * Advances to the next address node in the #InternetAddessList.
+ * Removes an #InternetAddress from the #InternetAddressList.
*
- * Returns: the next address node in the #InternetAddessList.
+ * Returns: %TRUE if the specified #InternetAddress was removed or
+ * %FALSE otherwise.
**/
-InternetAddressList *
-internet_address_list_next (const InternetAddressList *list)
+gboolean
+internet_address_list_remove (InternetAddressList *list, InternetAddress *ia)
{
- return list ? list->next : NULL;
+ int index;
+
+ g_return_val_if_fail (list != NULL, FALSE);
+ g_return_val_if_fail (ia != NULL, FALSE);
+
+ if ((index = internet_address_list_index_of (list, ia)) == -1)
+ return FALSE;
+
+ internet_address_list_remove_at (list, index);
+
+ return TRUE;
}
/**
- * internet_address_list_get_address:
- * @list: list of internet addresses
+ * internet_address_list_remove_at:
+ * @list: a #InternetAddressList
+ * @index: index to remove
*
- * Gets the #InternetAddress currently pointed to in @list.
+ * Removes an #InternetAddress from the #InternetAddressList at the
+ * specified index.
*
- * Returns: the #InternetAddress currently pointed to in @list.
+ * Returns: %TRUE if an #InternetAddress was removed or %FALSE
+ * otherwise.
**/
-InternetAddress *
-internet_address_list_get_address (const InternetAddressList *list)
+gboolean
+internet_address_list_remove_at (InternetAddressList *list, int index)
{
- return list ? list->address : NULL;
+ g_return_val_if_fail (list != NULL, FALSE);
+ g_return_val_if_fail (index < 0, FALSE);
+
+ if (index >= list->array->len)
+ return FALSE;
+
+ internet_address_unref (list->array->pdata[index]);
+
+ g_ptr_array_remove_index (list->array, index);
+
+ return TRUE;
}
+
/**
- * internet_address_list_length:
- * @list: list of internet addresses
+ * internet_address_list_contains:
+ * @list: a #InternetAddressList
+ * @ia: a #InternetAddress
+ *
+ * Checks whether or not the specified #InternetAddress is contained
+ * within the #InternetAddressList.
+ *
+ * Returns: %TRUE if the specified #InternetAddress is contained
+ * within the specified #InternetAddressList or %FALSE otherwise.
+ **/
+gboolean
+internet_address_list_contains (const InternetAddressList *list, const InternetAddress *ia)
+{
+ return internet_address_list_index_of (list, ia) != -1;
+}
+
+
+/**
+ * internet_address_list_index_of:
+ * @list: a #InternetAddressList
+ * @ia: a #InternetAddress
*
- * Calculates the length of the list of addresses.
+ * Gets the index of the specified #InternetAddress inside the
+ * #InternetAddressList.
*
- * Returns: the number of internet addresses in @list.
+ * Returns: the index of the requested #InternetAddress within the
+ * #InternetAddressList or %-1 if it is not contained within the
+ * #InternetAddressList.
**/
int
-internet_address_list_length (const InternetAddressList *list)
+internet_address_list_index_of (const InternetAddressList *list, const InternetAddress *ia)
{
- const InternetAddressList *node;
- int len = 0;
+ guint i;
+
+ g_return_val_if_fail (list != NULL, -1);
+ g_return_val_if_fail (ia != NULL, -1);
- node = list;
- while (node) {
- node = node->next;
- len++;
+ for (i = 0; i < list->array->len; i++) {
+ if (list->array->pdata[i] == ia)
+ return i;
}
- return len;
+ return -1;
}
/**
- * internet_address_list_destroy:
- * @list: address list
+ * internet_address_list_get_address:
+ * @list: a #InternetAddressList
+ * @index: index of #InternetAddress to get
+ *
+ * Gets the #InternetAddress at the specified index.
+ *
+ * Returns: the #InternetAddress at the specified index or %NULL if
+ * the index is out of range.
+ **/
+const InternetAddress *
+internet_address_list_get_address (const InternetAddressList *list, int index)
+{
+ g_return_val_if_fail (list != NULL, NULL);
+ g_return_val_if_fail (index < 0, NULL);
+
+ if ((guint) index >= list->array->len)
+ return NULL;
+
+ return list->array->pdata[index];
+}
+
+
+/**
+ * internet_address_list_set_address:
+ * @list: a #InternetAddressList
+ * @index: index of #InternetAddress to set
+ * @ia: a #InternetAddress
*
- * Destroys the list of internet addresses.
+ * Sets the #InternetAddress at the specified index to @ia.
**/
void
-internet_address_list_destroy (InternetAddressList *list)
+internet_address_list_set_address (InternetAddressList *list, int index, InternetAddress *ia)
{
- InternetAddressList *node, *next;
+ g_return_if_fail (list != NULL);
+ g_return_if_fail (ia != NULL);
+ g_return_if_fail (index < 0);
- node = list;
- while (node) {
- next = node->next;
- internet_address_unref (node->address);
- g_free (node);
- node = next;
+ if ((guint) index > list->array->len)
+ return;
+
+ if ((guint) index == list->array->len) {
+ internet_address_list_add (list, ia);
+ return;
}
+
+ internet_address_ref (ia);
+
+ internet_address_unref (list->array->pdata[index]);
+ list->array->pdata[index] = ia;
}
@@ -681,15 +830,15 @@
static void
_internet_address_list_to_string (const InternetAddressList *list, guint32 flags, size_t *linelen, GString *string)
{
- while (list) {
- _internet_address_to_string (list->address, flags, linelen, string);
+ guint i;
+
+ for (i = 0; i < list->array->len; i++) {
+ _internet_address_to_string (list->array->pdata[i], flags, linelen, string);
- if (list->next) {
+ if (i < list->array->len) {
g_string_append (string, ", ");
*linelen += 2;
}
-
- list = list->next;
}
}
@@ -960,23 +1109,16 @@
decode_lwsp (&inptr);
if (*inptr == ':') {
- /* this is a group */
- InternetAddressList *group = NULL, *tail;
-
- tail = (InternetAddressList *) &group;
-
- inptr++;
addr = internet_address_new_group (name->str);
+ inptr++;
decode_lwsp (&inptr);
while (*inptr && *inptr != ';') {
InternetAddress *member;
if ((member = decode_mailbox (&inptr))) {
- tail->next = g_new (InternetAddressList, 1);
- tail = tail->next;
- tail->next = NULL;
- tail->address = member;
+ internet_address_add_member (addr, member);
+ internet_address_unref (member);
}
decode_lwsp (&inptr);
@@ -984,10 +1126,8 @@
inptr++;
decode_lwsp (&inptr);
if ((member = decode_mailbox (&inptr))) {
- tail->next = g_new (InternetAddressList, 1);
- tail = tail->next;
- tail->next = NULL;
- tail->address = member;
+ internet_address_add_member (addr, member);
+ internet_address_unref (member);
}
decode_lwsp (&inptr);
@@ -1000,8 +1140,6 @@
w(g_warning ("Invalid group spec, missing closing ';': %.*s",
inptr - start, start));
- internet_address_set_group (addr, group);
-
*in = inptr;
} else {
/* this is a mailbox */
@@ -1015,35 +1153,31 @@
/**
- * internet_address_parse_string:
+ * internet_address_list_parse_string:
* @str: a string containing internet addresses
*
* Construct a list of internet addresses from the given string.
*
- * Returns: a linked list of internet addresses. *Must* be free'd by
- * the caller.
+ * Returns: a #InternetAddressList or %NULL if the input string does
+ * not contain any addresses.
**/
InternetAddressList *
-internet_address_parse_string (const char *str)
+internet_address_list_parse_string (const char *str)
{
- InternetAddressList *node, *tail, *addrlist = NULL;
+ InternetAddressList *addrlist;
const char *inptr = str;
- tail = (InternetAddressList *) &addrlist;
+ addrlist = internet_address_list_new ();
while (inptr && *inptr) {
InternetAddress *addr;
const char *start;
start = inptr;
- addr = decode_address (&inptr);
- if (addr) {
- node = g_new (InternetAddressList, 1);
- node->next = NULL;
- node->address = addr;
- tail->next = node;
- tail = node;
+ if ((addr = decode_address (&inptr))) {
+ internet_address_list_add (addrlist, addr);
+ internet_address_unref (addr);
} else {
w(g_warning ("Invalid or incomplete address: %.*s",
inptr - start, start));
@@ -1060,5 +1194,10 @@
}
}
+ if (addrlist->array->len == 0) {
+ internet_address_list_destroy (addrlist);
+ addrlist = NULL;
+ }
+
return addrlist;
}
Modified: trunk/gmime/internet-address.h
==============================================================================
--- trunk/gmime/internet-address.h (original)
+++ trunk/gmime/internet-address.h Sat Aug 16 05:57:40 2008
@@ -42,6 +42,15 @@
} InternetAddressType;
typedef struct _InternetAddress InternetAddress;
+
+
+/**
+ * InternetAddressList:
+ * @next: Pointer to the next item in the list.
+ * @address: The #InternetAddress.
+ *
+ * A collection of #InternetAddresses.
+ **/
typedef struct _InternetAddressList InternetAddressList;
@@ -64,19 +73,6 @@
};
-/**
- * InternetAddressList:
- * @next: Pointer to the next item in the list.
- * @address: The #InternetAddress.
- *
- * A list of #InternetAddress structures.
- **/
-struct _InternetAddressList {
- struct _InternetAddressList *next;
- InternetAddress *address;
-};
-
-
InternetAddress *internet_address_new (void);
InternetAddress *internet_address_new_name (const char *name, const char *addr);
InternetAddress *internet_address_new_group (const char *name);
@@ -94,15 +90,26 @@
const char *internet_address_get_addr (InternetAddress *ia);
const InternetAddressList *internet_address_get_members (InternetAddress *ia);
-InternetAddressList *internet_address_list_prepend (InternetAddressList *list, InternetAddress *ia);
-InternetAddressList *internet_address_list_append (InternetAddressList *list, InternetAddress *ia);
-InternetAddressList *internet_address_list_concat (InternetAddressList *a, InternetAddressList *b);
-InternetAddressList *internet_address_list_next (const InternetAddressList *list);
-InternetAddress *internet_address_list_get_address (const InternetAddressList *list);
-int internet_address_list_length (const InternetAddressList *list);
+InternetAddressList *internet_address_list_new (void);
void internet_address_list_destroy (InternetAddressList *list);
-InternetAddressList *internet_address_parse_string (const char *str);
+int internet_address_list_length (const InternetAddressList *list);
+
+void internet_address_list_clear (InternetAddressList *list);
+
+int internet_address_list_add (InternetAddressList *list, InternetAddress *ia);
+void internet_address_list_concat (InternetAddressList *list, InternetAddressList *concat);
+void internet_address_list_insert (InternetAddressList *list, int index, InternetAddress *ia);
+gboolean internet_address_list_remove (InternetAddressList *list, InternetAddress *ia);
+gboolean internet_address_list_remove_at (InternetAddressList *list, int index);
+
+gboolean internet_address_list_contains (const InternetAddressList *list, const InternetAddress *ia);
+int internet_address_list_index_of (const InternetAddressList *list, const InternetAddress *ia);
+
+const InternetAddress *internet_address_list_get_address (const InternetAddressList *list, int index);
+void internet_address_list_set_address (InternetAddressList *list, int index, InternetAddress *ia);
+
+InternetAddressList *internet_address_list_parse_string (const char *str);
char *internet_address_to_string (const InternetAddress *ia, gboolean encode);
char *internet_address_list_to_string (const InternetAddressList *list, gboolean encode);
Modified: trunk/mono/GMime.metadata
==============================================================================
--- trunk/mono/GMime.metadata (original)
+++ trunk/mono/GMime.metadata Sat Aug 16 05:57:40 2008
@@ -145,12 +145,13 @@
<remove-node path="/api/namespace/struct[ cname='InternetAddress']/field[ cname='type']"/>
<!-- InternetAddressList -->
- <!-- We implement this class by hand, hide it. -->
- <attr path="/api/namespace/struct[ cname='InternetAddressList']" name="hidden">true</attr>
+ <!-- We implement this class by hand, remove it. -->
+ <remove-node path="/api/namespace/struct[ cname='InternetAddressList']"/>
<!-- Message -->
<attr path="/api/namespace/object[ cname='GMimeMessage']/method[ name='GetMimePart']/return-type" name="owned">true</attr>
<!-- We implement these properties by hand, hide them. -->
+ <remove-node path="/api/namespace/object[ cname='GMimeMessage']/method[ cname='g_mime_message_get_recipients']"/>
<remove-node path="/api/namespace/object[ cname='GMimeMessage']/method[ cname='g_mime_message_get_date']"/>
<remove-node path="/api/namespace/object[ cname='GMimeMessage']/method[ cname='g_mime_message_set_date']"/>
Added: trunk/mono/InternetAddress.custom
==============================================================================
--- (empty file)
+++ trunk/mono/InternetAddress.custom Sat Aug 16 05:57:40 2008
@@ -0,0 +1,4 @@
+public override string ToString ()
+{
+ return ToString (false);
+}
Modified: trunk/mono/InternetAddressList.cs
==============================================================================
--- trunk/mono/InternetAddressList.cs (original)
+++ trunk/mono/InternetAddressList.cs Sat Aug 16 05:57:40 2008
@@ -3,74 +3,304 @@
using System.Runtime.InteropServices;
namespace GMime {
- public class InternetAddressList : ArrayList, IDisposable {
- bool needs_destroy;
+ public class InternetAddressList : IDisposable, IList {
IntPtr list;
-
+
+#region Native Methods
[DllImport("gmime")]
- static extern IntPtr internet_address_list_next (IntPtr raw);
-
+ static extern IntPtr internet_address_list_new ();
+
[DllImport("gmime")]
- static extern IntPtr internet_address_list_get_address (IntPtr raw);
-
+ static extern void internet_address_list_destroy (IntPtr list);
+
[DllImport("gmime")]
- static extern void internet_address_list_destroy (IntPtr raw);
-
- public InternetAddressList (IntPtr list, bool needs_destroy)
+ static extern int internet_address_list_length (IntPtr list);
+
+ [DllImport("gmime")]
+ static extern void internet_address_list_clear (IntPtr list);
+
+ [DllImport("gmime")]
+ static extern int internet_address_list_add (IntPtr list, IntPtr ia);
+
+ //[DllImport("gmime")]
+ //static extern void internet_address_list_concat (IntPtr list, IntPtr concat);
+
+ [DllImport("gmime")]
+ static extern void internet_address_list_insert (IntPtr list, int index, IntPtr concat);
+
+ [DllImport("gmime")]
+ static extern bool internet_address_list_remove (IntPtr list, IntPtr ia);
+
+ [DllImport("gmime")]
+ static extern bool internet_address_list_remove_at (IntPtr list, int index);
+
+ [DllImport("gmime")]
+ static extern bool internet_address_list_contains (IntPtr list, IntPtr ia);
+
+ [DllImport("gmime")]
+ static extern int internet_address_list_index_of (IntPtr list, IntPtr ia);
+
+ [DllImport("gmime")]
+ static extern IntPtr internet_address_list_get_address (IntPtr list, int index);
+
+ [DllImport("gmime")]
+ static extern void internet_address_list_set_address (IntPtr list, int index, IntPtr ia);
+
+ [DllImport("gmime")]
+ static extern IntPtr internet_address_list_to_string (IntPtr list, bool encode);
+
+ [DllImport("gmime")]
+ static extern IntPtr internet_address_list_parse_string (IntPtr str);
+
+ [DllImport("gmime")]
+ static extern void internet_address_ref (IntPtr raw);
+#endregion
+
+ public InternetAddressList () : this (internet_address_list_new ())
{
- this.needs_destroy = needs_destroy;
- this.list = list;
- while (list != IntPtr.Zero) {
- IntPtr ia = internet_address_list_get_address (list);
-
- InternetAddress addr = new InternetAddress (ia);
- Add (addr);
-
- list = internet_address_list_next (list);
- }
}
-
- public InternetAddressList (IntPtr list) : this (list, false) { }
-
- ~InternetAddressList ()
+
+ public InternetAddressList (IntPtr raw)
{
- Dispose ();
+ list = raw;
}
-
+
public void Dispose ()
{
- if (needs_destroy) {
+ if (list != IntPtr.Zero)
internet_address_list_destroy (list);
- needs_destroy = false;
- list = IntPtr.Zero;
+
+ list = IntPtr.Zero;
+ }
+
+ Exception CannotAdd (object value)
+ {
+ if (value == null)
+ return new ArgumentNullException ("value");
+
+ string message = String.Format ("Cannot add objects of type '{0}' to an InternetAddressList.",
+ value.GetType ().ToString ());
+
+ return new InvalidOperationException (message);
+ }
+
+ Exception CannotInsert (object value)
+ {
+ if (value == null)
+ return new ArgumentNullException ("value");
+
+ string message = String.Format ("Cannot insert objects of type '{0}' into an InternetAddressList.",
+ value.GetType ().ToString ());
+
+ return new InvalidOperationException (message);
+ }
+
+ Exception CannotRemove (object value)
+ {
+ if (value == null)
+ return new ArgumentNullException ("value");
+
+ string message = String.Format ("Cannot remove objects of type '{0}' from an InternetAddressList.",
+ value.GetType ().ToString ());
+
+ return new InvalidOperationException (message);
+ }
+
+ Exception CannotSet (object value)
+ {
+ if (value == null)
+ return new ArgumentNullException ("value");
+
+ string message = String.Format ("Cannot set objects of type '{0}' on an InternetAddressList.",
+ value.GetType ().ToString ());
+
+ return new InvalidOperationException (message);
+ }
+
+#region IList
+ public int Count {
+ get { return internet_address_list_length (list); }
+ }
+
+ public bool IsFixedSize {
+ get { return false; }
+ }
+
+ public bool IsReadOnly {
+ get { return false; }
+ }
+
+ public bool IsSynchronized {
+ get { return false; }
+ }
+
+ public object SyncRoot {
+ get { return this; }
+ }
+
+ public int Add (object value)
+ {
+ InternetAddress addr = value as InternetAddress;
+
+ if (addr == null)
+ throw CannotAdd (value);
+
+ return internet_address_list_add (list, addr.Handle);
+ }
+
+ public void Clear ()
+ {
+ internet_address_list_clear (list);
+ }
+
+ public bool Contains (object value)
+ {
+ InternetAddress addr = value as InternetAddress;
+
+ if (addr == null)
+ return false;
+
+ return internet_address_list_contains (list, addr.Handle);
+ }
+
+ public void CopyTo (Array array, int index)
+ {
+ if (array == null)
+ throw new ArgumentNullException ("array");
+
+ if (index < 0)
+ throw new ArgumentOutOfRangeException ("index");
+
+ int n = Count;
+
+ for (int i = 0; i < n; i++)
+ array.SetValue (((IList) this)[i], index + i);
+ }
+
+ public IEnumerator GetEnumerator ()
+ {
+ return new InternetAddressListIterator (this);
+ }
+
+ public int IndexOf (object value)
+ {
+ InternetAddress addr = value as InternetAddress;
+
+ if (addr == null)
+ return -1;
+
+ return internet_address_list_index_of (list, addr.Handle);
+ }
+
+ public void Insert (int index, object value)
+ {
+ InternetAddress addr = value as InternetAddress;
+
+ if (addr == null)
+ throw CannotInsert (value);
+
+ if (index < 0)
+ throw new ArgumentOutOfRangeException ("index");
+
+ internet_address_list_insert (list, index, addr.Handle);
+ }
+
+ public void Remove (object value)
+ {
+ InternetAddress addr = value as InternetAddress;
+
+ if (addr == null)
+ throw CannotRemove (value);
+
+ internet_address_list_remove (list, addr.Handle);
+ }
+
+ public void RemoveAt (int index)
+ {
+ if (index < 0 || index >= Count)
+ throw new ArgumentOutOfRangeException ("index");
+
+ internet_address_list_remove_at (list, index);
+ }
+
+ public object this[int index] {
+ get {
+ IntPtr raw = internet_address_list_get_address (list, index);
+ InternetAddress addr;
+
+ if (raw == IntPtr.Zero)
+ return null;
+
+ internet_address_ref (raw);
+
+ addr = new InternetAddress (raw);
+ addr.Owned = true;
+
+ return addr;
+ }
+
+ set {
+ InternetAddress addr = value as InternetAddress;
+
+ if (addr == null)
+ throw CannotSet (value);
+
+ internet_address_list_set_address (list, index, addr.Handle);
}
- GC.SuppressFinalize (this);
}
-
- [DllImport("gmime")]
- static extern IntPtr internet_address_parse_string (string list);
-
- public static InternetAddressList ParseString (string list)
+#endregion
+
+ public static InternetAddressList Parse (string str)
{
- IntPtr ret = internet_address_parse_string (list);
+ IntPtr native_str = GLib.Marshaller.StringToPtrGStrdup (str);
+ IntPtr raw = internet_address_list_parse_string (native_str);
+ InternetAddressList list = null;
+
+ if (raw != IntPtr.Zero)
+ list = new InternetAddressList (raw);
- return new InternetAddressList (ret, true);
+ GLib.Marshaller.Free (native_str);
+
+ return list;
}
-
- [DllImport("gmime")]
- static extern IntPtr internet_address_list_to_string (IntPtr list, bool encode);
-
+
public string ToString (bool encode)
{
- IntPtr str = internet_address_list_to_string (list, encode);
+ IntPtr raw = internet_address_list_to_string (list, encode);
- return GLib.Marshaller.PtrToStringGFree (str);
+ return GLib.Marshaller.PtrToStringGFree (raw);
}
-
+
public override string ToString ()
{
return ToString (false);
}
+
+ internal class InternetAddressListIterator : IEnumerator {
+ InternetAddressList list;
+ int index = -1;
+
+ public InternetAddressListIterator (InternetAddressList list)
+ {
+ this.list = list;
+ }
+
+ public object Current {
+ get { return list[index]; }
+ }
+
+ public void Reset ()
+ {
+ index = -1;
+ }
+
+ public bool MoveNext ()
+ {
+ index++;
+
+ return index < list.Count;
+ }
+ }
}
}
Modified: trunk/mono/Makefile.am
==============================================================================
--- trunk/mono/Makefile.am (original)
+++ trunk/mono/Makefile.am Sat Aug 16 05:57:40 2008
@@ -30,6 +30,7 @@
DataWrapper.custom \
Global.custom \
HeaderList.custom \
+ InternetAddress.custom \
Message.custom \
Object.custom \
Stream.custom
@@ -38,6 +39,7 @@
$(srcdir)/DataWrapper.custom \
$(srcdir)/Global.custom \
$(srcdir)/HeaderList.custom \
+ $(srcdir)/InternetAddress.custom\
$(srcdir)/Message.custom \
$(srcdir)/Object.custom \
$(srcdir)/Stream.custom
Modified: trunk/mono/gmime-api.raw
==============================================================================
--- trunk/mono/gmime-api.raw (original)
+++ trunk/mono/gmime-api.raw Sat Aug 16 05:57:40 2008
@@ -2480,12 +2480,6 @@
<parameter type="const-char*" name="addr" />
</parameters>
</constructor>
- <method name="ParseString" cname="internet_address_parse_string" shared="true">
- <return-type type="InternetAddressList*" />
- <parameters>
- <parameter type="const-char*" name="str" />
- </parameters>
- </method>
<method name="Ref" cname="internet_address_ref">
<return-type type="void" />
</method>
@@ -2518,35 +2512,75 @@
</method>
</struct>
<struct name="InternetAddressList" cname="InternetAddressList" opaque="true">
- <field name="Next" cname="next" type="struct-_InternetAddressList*" access="public" writeable="true" />
- <field name="Address" cname="address" type="InternetAddress*" access="public" writeable="true" />
- <method name="Append" cname="internet_address_list_append">
- <return-type type="InternetAddressList*" />
+ <method name="Add" cname="internet_address_list_add">
+ <return-type type="int" />
<parameters>
<parameter type="InternetAddress*" name="ia" />
</parameters>
</method>
+ <method name="Clear" cname="internet_address_list_clear">
+ <return-type type="void" />
+ </method>
<method name="Concat" cname="internet_address_list_concat">
- <return-type type="InternetAddressList*" />
+ <return-type type="void" />
+ <parameters>
+ <parameter type="InternetAddressList*" name="concat" />
+ </parameters>
+ </method>
+ <method name="Contains" cname="internet_address_list_contains">
+ <return-type type="gboolean" />
<parameters>
- <parameter type="InternetAddressList*" name="b" />
+ <parameter type="const-InternetAddress*" name="ia" />
</parameters>
</method>
<method name="Destroy" cname="internet_address_list_destroy">
<return-type type="void" />
</method>
<method name="GetAddress" cname="internet_address_list_get_address">
- <return-type type="InternetAddress*" />
+ <return-type type="const-InternetAddress*" />
+ <parameters>
+ <parameter type="int" name="index" />
+ </parameters>
+ </method>
+ <method name="IndexOf" cname="internet_address_list_index_of">
+ <return-type type="int" />
+ <parameters>
+ <parameter type="const-InternetAddress*" name="ia" />
+ </parameters>
+ </method>
+ <method name="Insert" cname="internet_address_list_insert">
+ <return-type type="void" />
+ <parameters>
+ <parameter type="int" name="index" />
+ <parameter type="InternetAddress*" name="ia" />
+ </parameters>
</method>
<method name="Length" cname="internet_address_list_length">
<return-type type="int" />
</method>
- <method name="Next" cname="internet_address_list_next">
+ <constructor cname="internet_address_list_new" />
+ <method name="ParseString" cname="internet_address_list_parse_string" shared="true">
<return-type type="InternetAddressList*" />
+ <parameters>
+ <parameter type="const-char*" name="str" />
+ </parameters>
</method>
- <method name="Prepend" cname="internet_address_list_prepend">
- <return-type type="InternetAddressList*" />
+ <method name="Remove" cname="internet_address_list_remove">
+ <return-type type="gboolean" />
+ <parameters>
+ <parameter type="InternetAddress*" name="ia" />
+ </parameters>
+ </method>
+ <method name="RemoveAt" cname="internet_address_list_remove_at">
+ <return-type type="gboolean" />
+ <parameters>
+ <parameter type="int" name="index" />
+ </parameters>
+ </method>
+ <method name="SetAddress" cname="internet_address_list_set_address">
+ <return-type type="void" />
<parameters>
+ <parameter type="int" name="index" />
<parameter type="InternetAddress*" name="ia" />
</parameters>
</method>
Modified: trunk/tests/test-mime.c
==============================================================================
--- trunk/tests/test-mime.c (original)
+++ trunk/tests/test-mime.c Sat Aug 16 05:57:40 2008
@@ -174,7 +174,7 @@
testsuite_check ("addrspec[%u]", i);
try {
- if (!(addrlist = internet_address_parse_string (addrspec[i].input)))
+ if (!(addrlist = internet_address_list_parse_string (addrspec[i].input)))
throw (exception_new ("could not parse addr-spec"));
str = internet_address_list_to_string (addrlist, FALSE);
Modified: trunk/tools/gmime-port-2-2-to-2-4.sh
==============================================================================
--- trunk/tools/gmime-port-2-2-to-2-4.sh (original)
+++ trunk/tools/gmime-port-2-2-to-2-4.sh Sat Aug 16 05:57:40 2008
@@ -85,6 +85,8 @@
-e "s/g_mime_object_ref/g_object_ref/g" \
-e "s/g_mime_stream_unref/g_object_unref/g" \
-e "s/g_mime_stream_ref/g_object_ref/g" \
+ -e "s/internet_address_parse_string/internet_address_list_parse_string/g" \
+ -e "s/internet_address_list_append/internet_address_list_add/g" \
< "$src" > "$src.tmp"
mv "$src.tmp" "$src"
done
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]