+2000-04-27 NotZed <NotZed@HelixCode.com>
+
+ * camel-news-address.c: Class to represent news addresses -
+ currently empty, and not built.
+
+ * camel-internet-address.h: Class to represent internet (email)
+ addresses.
+
+ * camel-address.h: Abstract class to represent (lists of)
+ addresses.
+
2000-04-27 Dan Winship <danw@helixcode.com>
* camel-mime-part.c (write_to_stream): Revert previous change. I
camel-mime-filter-charset.c \
camel-mime-filter-index.c \
camel-stream-filter.c \
+ camel-address.c \
+ camel-internet-address.c \
$(pthread_SRC)
libcamelinclude_HEADERS = \
camel-mime-filter-charset.h \
camel-mime-filter-index.h \
camel-stream-filter.h \
+ camel-address.h \
+ camel-internet-address.h \
$(pthread_HDR)
libcamel_extra_sources = \
--- /dev/null
+/*
+ * Copyright (C) 2000 Helix Code Inc.
+ *
+ * Authors: Michael Zucchi <notzed@helixcode.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "camel-address.h"
+
+
+static void camel_address_class_init (CamelAddressClass *klass);
+static void camel_address_init (CamelAddress *obj);
+static void camel_address_finalise (GtkObject *obj);
+
+static GtkObjectClass *camel_address_parent;
+
+enum SIGNALS {
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+guint
+camel_address_get_type (void)
+{
+ static guint type = 0;
+
+ if (!type) {
+ GtkTypeInfo type_info = {
+ "CamelAddress",
+ sizeof (CamelAddress),
+ sizeof (CamelAddressClass),
+ (GtkClassInitFunc) camel_address_class_init,
+ (GtkObjectInitFunc) camel_address_init,
+ (GtkArgSetFunc) NULL,
+ (GtkArgGetFunc) NULL
+ };
+
+ type = gtk_type_unique (gtk_object_get_type (), &type_info);
+ }
+
+ return type;
+}
+
+static void
+camel_address_class_init (CamelAddressClass *klass)
+{
+ GtkObjectClass *object_class = (GtkObjectClass *) klass;
+
+ camel_address_parent = gtk_type_class (gtk_object_get_type ());
+
+ object_class->finalize = camel_address_finalise;
+
+ gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);
+}
+
+static void
+camel_address_init (CamelAddress *obj)
+{
+ obj->addresses = g_ptr_array_new();
+}
+
+static void
+camel_address_finalise (GtkObject *obj)
+{
+ camel_address_remove((CamelAddress *)obj, -1);
+
+ ((GtkObjectClass *)(camel_address_parent))->finalize((GtkObject *)obj);
+}
+
+/**
+ * camel_address_new:
+ *
+ * Create a new CamelAddress object.
+ *
+ * Return value: A new CamelAddress widget.
+ **/
+CamelAddress *
+camel_address_new (void)
+{
+ CamelAddress *new = CAMEL_ADDRESS ( gtk_type_new (camel_address_get_type ()));
+ return new;
+}
+
+
+/**
+ * camel_address_decode:
+ * @a: An address.
+ * @raw: Raw address description.
+ *
+ * Construct a new address from a raw address field.
+ *
+ * Return value: Returns the number of addresses found,
+ * or -1 if the addresses could not be parsed fully.
+ **/
+int
+camel_address_decode (CamelAddress *a, const char *raw)
+{
+ g_return_val_if_fail(IS_CAMEL_ADDRESS(a), -1);
+
+ return ((CamelAddressClass *)((GtkObject *)a)->klass)->decode(a, raw);
+}
+
+/**
+ * camel_address_encode:
+ * @a:
+ *
+ * Encode an address in a format suitable for a raw header.
+ *
+ * Return value: The encoded address.
+ **/
+char *
+camel_address_encode (CamelAddress *a)
+{
+ g_return_val_if_fail(IS_CAMEL_ADDRESS(a), NULL);
+
+ return ((CamelAddressClass *)((GtkObject *)a)->klass)->encode(a);
+}
+
+/**
+ * camel_address_remove:
+ * @a:
+ * @index: The address to remove, use -1 to remove all address.
+ *
+ * Remove an address by index, or all addresses.
+ **/
+void
+camel_address_remove (CamelAddress *a, int index)
+{
+ g_return_if_fail(IS_CAMEL_ADDRESS(a));
+
+ if (index == -1) {
+ for (index=a->addresses->len; index>-1; index--)
+ ((CamelAddressClass *)((GtkObject *)a)->klass)->remove(a, index);
+ } else {
+ ((CamelAddressClass *)((GtkObject *)a)->klass)->remove(a, index);
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2000 Helix Code Inc.
+ *
+ * Authors: Michael Zucchi <notzed@helixcode.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef _CAMEL_ADDRESS_H
+#define _CAMEL_ADDRESS_H
+
+#include <gtk/gtk.h>
+
+#define CAMEL_ADDRESS(obj) GTK_CHECK_CAST (obj, camel_address_get_type (), CamelAddress)
+#define CAMEL_ADDRESS_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, camel_address_get_type (), CamelAddressClass)
+#define IS_CAMEL_ADDRESS(obj) GTK_CHECK_TYPE (obj, camel_address_get_type ())
+
+typedef struct _CamelAddress CamelAddress;
+typedef struct _CamelAddressClass CamelAddressClass;
+
+struct _CamelAddress {
+ GtkObject parent;
+
+ GPtrArray *addresses;
+
+ struct _CamelAddressPrivate *priv;
+};
+
+struct _CamelAddressClass {
+ GtkObjectClass parent_class;
+
+ int (*decode) (CamelAddress *, const char *raw);
+ char *(*encode) (CamelAddress *);
+
+ void (*remove) (CamelAddress *, int index);
+};
+
+guint camel_address_get_type (void);
+CamelAddress *camel_address_new (void);
+
+int camel_address_decode (CamelAddress *, const char *);
+char *camel_address_encode (CamelAddress *);
+
+void camel_address_remove (CamelAddress *, int index);
+
+#endif /* ! _CAMEL_ADDRESS_H */
--- /dev/null
+/*
+ * Copyright (C) 2000 Helix Code Inc.
+ *
+ * Authors: Michael Zucchi <notzed@helixcode.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "camel-mime-utils.h"
+#include "camel-internet-address.h"
+
+struct _address {
+ char *name;
+ char *address;
+};
+
+static int internet_decode (CamelAddress *, const char *raw);
+static char * internet_encode (CamelAddress *);
+static void internet_remove (CamelAddress *, int index);
+
+static void camel_internet_address_class_init (CamelInternetAddressClass *klass);
+static void camel_internet_address_init (CamelInternetAddress *obj);
+
+static CamelAddressClass *camel_internet_address_parent;
+
+enum SIGNALS {
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+guint
+camel_internet_address_get_type (void)
+{
+ static guint type = 0;
+
+ if (!type) {
+ GtkTypeInfo type_info = {
+ "CamelInternetAddress",
+ sizeof (CamelInternetAddress),
+ sizeof (CamelInternetAddressClass),
+ (GtkClassInitFunc) camel_internet_address_class_init,
+ (GtkObjectInitFunc) camel_internet_address_init,
+ (GtkArgSetFunc) NULL,
+ (GtkArgGetFunc) NULL
+ };
+
+ type = gtk_type_unique (camel_address_get_type (), &type_info);
+ }
+
+ return type;
+}
+
+static void
+camel_internet_address_class_init (CamelInternetAddressClass *klass)
+{
+ GtkObjectClass *object_class = (GtkObjectClass *) klass;
+ CamelAddressClass *address = (CamelAddressClass *) klass;
+
+ camel_internet_address_parent = gtk_type_class (camel_address_get_type ());
+
+ address->decode = internet_decode;
+ address->encode = internet_encode;
+ address->remove = internet_remove;
+
+ gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);
+}
+
+static void
+camel_internet_address_init (CamelInternetAddress *obj)
+{
+}
+
+static int
+internet_decode (CamelAddress *a, const char *raw)
+{
+ struct _header_address *ha, *n;
+
+ /* Should probably use its own decoder or something */
+ ha = header_address_decode(raw);
+ if (ha) {
+ n = ha;
+ while (n) {
+ if (n->type == HEADER_ADDRESS_NAME) {
+ camel_internet_address_add((CamelInternetAddress *)a, n->name, n->v.addr);
+ } else if (n->type == HEADER_ADDRESS_GROUP) {
+ struct _header_address *g = n->v.members;
+ while (g) {
+ if (g->type == HEADER_ADDRESS_NAME)
+ camel_internet_address_add((CamelInternetAddress *)a, g->name, g->v.addr);
+ /* otherwise, its an error, infact */
+ g = g->next;
+ }
+ }
+ n = n->next;
+ }
+ header_address_unref(ha);
+ }
+ return 0;
+}
+
+static char * internet_encode (CamelAddress *a)
+{
+ int i;
+ GString *out;
+ char *ret;
+
+ if (a->addresses->len == 0)
+ return NULL;
+
+ out = g_string_new("");
+
+ for (i=0;i<a->addresses->len;i++) {
+ struct _address *addr = g_ptr_array_index( a->addresses, i );
+ char *name = header_encode_string(addr->name);
+
+ if (i!=0)
+ g_string_append(out, ", ");
+
+ if (name) {
+ g_string_sprintfa(out, "%s ", name);
+ g_free(name);
+ }
+ g_string_sprintfa(out, "<%s>", addr->address);
+ }
+ g_string_free(out, FALSE);
+ ret = out->str;
+ return ret;
+}
+
+static void internet_remove (CamelAddress *a, int index)
+{
+ struct _address *addr;
+
+ if (index <0 || index >= a->addresses->len)
+ return;
+
+ addr = g_ptr_array_index( a->addresses, index);
+ g_free(addr->name);
+ g_free(addr->address);
+ g_free(addr);
+ g_ptr_array_remove_index( a->addresses, index);
+}
+
+/**
+ * camel_internet_address_new:
+ *
+ * Create a new CamelInternetAddress object.
+ *
+ * Return value: A new CamelInternetAddress object.
+ **/
+CamelInternetAddress *
+camel_internet_address_new (void)
+{
+ CamelInternetAddress *new = CAMEL_INTERNET_ADDRESS ( gtk_type_new (camel_internet_address_get_type ()));
+ return new;
+}
+
+/**
+ * camel_internet_address_add:
+ * @a:
+ * @name:
+ * @address:
+ *
+ * Add a new internet address to the address object.
+ *
+ * Return value: Index of added entry.
+ **/
+int
+camel_internet_address_add (CamelInternetAddress *a, const char *name, const char *address)
+{
+ struct _address *new;
+ int index;
+
+ g_return_val_if_fail(IS_CAMEL_INTERNET_ADDRESS(a), -1);
+
+ new = g_malloc(sizeof(*new));
+ new->name = g_strdup(name);
+ new->address = g_strdup(address);
+ index = ((CamelAddress *)a)->addresses->len;
+ g_ptr_array_add(((CamelAddress *)a)->addresses, new);
+
+ return index;
+}
+
+/**
+ * camel_internet_address_get:
+ * @a:
+ * @index:
+ * @namep: Holder for the returned name, or NULL, if not required.
+ * @addressp: Holder for the returned address, or NULL, if not required.
+ *
+ * Get the address at @index.
+ *
+ * Return value: TRUE if such an address exists, or FALSE otherwise.
+ **/
+gboolean
+camel_internet_address_get (CamelInternetAddress *a, int index, const char **namep, const char **addressp)
+{
+ struct _address *addr;
+
+ g_return_val_if_fail(IS_CAMEL_INTERNET_ADDRESS(a), -1);
+ g_return_val_if_fail(index >= 0, -1);
+
+ if (index >= ((CamelAddress *)a)->addresses->len)
+ return FALSE;
+
+ addr = g_ptr_array_index( ((CamelAddress *)a)->addresses, index);
+ if (namep)
+ *namep = addr->name;
+ if (addressp)
+ *addressp = addr->address;
+ return TRUE;
+}
+
+/**
+ * camel_internet_address_find_name:
+ * @a:
+ * @name:
+ * @addressp: Holder for address part, or NULL, if not required.
+ *
+ * Find address by real name.
+ *
+ * Return value: The index of the address matching the name, or -1
+ * if no match was found.
+ **/
+int
+camel_internet_address_find_name(CamelInternetAddress *a, const char *name, const char **addressp)
+{
+ struct _address *addr;
+ int i, len;
+
+ g_return_val_if_fail(IS_CAMEL_INTERNET_ADDRESS(a), -1);
+
+ len = ((CamelAddress *)a)->addresses->len;
+ for (i=0;i<len;i++) {
+ addr = g_ptr_array_index( ((CamelAddress *)a)->addresses, i );
+ if (!strcmp(addr->name, name)) {
+ if (addressp)
+ *addressp = addr->address;
+ return i;
+ }
+ }
+ return -1;
+}
+
+/**
+ * camel_internet_address_find_address:
+ * @a:
+ * @address:
+ * @namep: Return for the matching name, or NULL, if not required.
+ *
+ * Find an address by address.
+ *
+ * Return value: The index of the address, or -1 if not found.
+ **/
+int
+camel_internet_address_find_address(CamelInternetAddress *a, const char *address, const char **namep)
+{
+ struct _address *addr;
+ int i, len;
+
+ g_return_val_if_fail(IS_CAMEL_INTERNET_ADDRESS(a), -1);
+
+ len = ((CamelAddress *)a)->addresses->len;
+ for (i=0;i<len;i++) {
+ addr = g_ptr_array_index( ((CamelAddress *)a)->addresses, i );
+ if (!strcmp(addr->address, address)) {
+ if (namep)
+ *namep = addr->name;
+ return i;
+ }
+ }
+ return -1;
+}
--- /dev/null
+/*
+ * Copyright (C) 2000 Helix Code Inc.
+ *
+ * Authors: Michael Zucchi <notzed@helixcode.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef _CAMEL_INTERNET_ADDRESS_H
+#define _CAMEL_INTERNET_ADDRESS_H
+
+#include <gtk/gtk.h>
+#include <camel/camel-address.h>
+
+#define CAMEL_INTERNET_ADDRESS(obj) GTK_CHECK_CAST (obj, camel_internet_address_get_type (), CamelInternetAddress)
+#define CAMEL_INTERNET_ADDRESS_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, camel_internet_address_get_type (), CamelInternetAddressClass)
+#define IS_CAMEL_INTERNET_ADDRESS(obj) GTK_CHECK_TYPE (obj, camel_internet_address_get_type ())
+
+typedef struct _CamelInternetAddress CamelInternetAddress;
+typedef struct _CamelInternetAddressClass CamelInternetAddressClass;
+
+struct _CamelInternetAddress {
+ CamelAddress parent;
+
+ struct _CamelInternetAddressPrivate *priv;
+};
+
+struct _CamelInternetAddressClass {
+ CamelAddressClass parent_class;
+};
+
+guint camel_internet_address_get_type (void);
+CamelInternetAddress *camel_internet_address_new (void);
+
+int camel_internet_address_add (CamelInternetAddress *, const char *, const char *);
+gboolean camel_internet_address_get (CamelInternetAddress *, int, const char **, const char **);
+
+int camel_internet_address_find_name(CamelInternetAddress *, const char *, const char **);
+int camel_internet_address_find_address(CamelInternetAddress *, const char *, const char **);
+
+#endif /* ! _CAMEL_INTERNET_ADDRESS_H */
--- /dev/null
+/*
+ * Copyright (C) 2000 Helix Code Inc.
+ *
+ * Authors:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "camel-news-address.h"
+
+
+static void camel_news_address_class_init (CamelNewsAddressClass *klass);
+static void camel_news_address_init (CamelNewsAddress *obj);
+
+static CamelAddressClass *camel_news_address_parent;
+
+enum SIGNALS {
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+guint
+camel_news_address_get_type (void)
+{
+ static guint type = 0;
+
+ if (!type) {
+ GtkTypeInfo type_info = {
+ "CamelNewsAddress",
+ sizeof (CamelNewsAddress),
+ sizeof (CamelNewsAddressClass),
+ (GtkClassInitFunc) camel_news_address_class_init,
+ (GtkObjectInitFunc) camel_news_address_init,
+ (GtkArgSetFunc) NULL,
+ (GtkArgGetFunc) NULL
+ };
+
+ type = gtk_type_unique (camel_address_get_type (), &type_info);
+ }
+
+ return type;
+}
+
+static void
+camel_news_address_class_init (CamelNewsAddressClass *klass)
+{
+ GtkObjectClass *object_class = (GtkObjectClass *) klass;
+
+ camel_news_address_parent = gtk_type_class (camel_address_get_type ());
+
+ gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);
+}
+
+static void
+camel_news_address_init (CamelNewsAddress *obj)
+{
+}
+
+/**
+ * camel_news_address_new:
+ *
+ * Create a new CamelNewsAddress object.
+ *
+ * Return value: A new CamelNewsAddress widget.
+ **/
+CamelNewsAddress *
+camel_news_address_new (void)
+{
+ CamelNewsAddress *new = CAMEL_NEWS_ADDRESS ( gtk_type_new (camel_news_address_get_type ()));
+ return new;
+}
--- /dev/null
+/*
+ * Copyright (C) 2000 Helix Code Inc.
+ *
+ * Authors:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef _CAMEL_NEWS_ADDRESS_H
+#define _CAMEL_NEWS_ADDRESS_H
+
+#include <gtk/gtk.h>
+
+#define CAMEL_NEWS_ADDRESS(obj) GTK_CHECK_CAST (obj, camel_news_address_get_type (), CamelNewsAddress)
+#define CAMEL_NEWS_ADDRESS_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, camel_news_address_get_type (), CamelNewsAddressClass)
+#define IS_CAMEL_NEWS_ADDRESS(obj) GTK_CHECK_TYPE (obj, camel_news_address_get_type ())
+
+typedef struct _CamelNewsAddress CamelNewsAddress;
+typedef struct _CamelNewsAddressClass CamelNewsAddressClass;
+
+struct _CamelNewsAddress {
+ CamelAddress parent;
+
+ struct _CamelNewsAddressPrivate *priv;
+};
+
+struct _CamelNewsAddressClass {
+ CamelAddressClass parent_class;
+};
+
+guint camel_news_address_get_type (void);
+CamelNewsAddress *camel_news_address_new (void);
+
+#endif /* ! _CAMEL_NEWS_ADDRESS_H */