diff options
author | Dan Winship <danw@src.gnome.org> | 2001-05-17 02:23:15 +0800 |
---|---|---|
committer | Dan Winship <danw@src.gnome.org> | 2001-05-17 02:23:15 +0800 |
commit | 71002d1544cdbcf825377602dd738c15f910b93b (patch) | |
tree | 46f8f339b9e69f2e170a57b0fd9a09cfbff5eca1 /camel | |
parent | 7e5b838da2848ea29a502813d917cee022cbdb35 (diff) | |
download | gsoc2013-evolution-71002d1544cdbcf825377602dd738c15f910b93b.tar gsoc2013-evolution-71002d1544cdbcf825377602dd738c15f910b93b.tar.gz gsoc2013-evolution-71002d1544cdbcf825377602dd738c15f910b93b.tar.bz2 gsoc2013-evolution-71002d1544cdbcf825377602dd738c15f910b93b.tar.lz gsoc2013-evolution-71002d1544cdbcf825377602dd738c15f910b93b.tar.xz gsoc2013-evolution-71002d1544cdbcf825377602dd738c15f910b93b.tar.zst gsoc2013-evolution-71002d1544cdbcf825377602dd738c15f910b93b.zip |
New function to return an array of all headers.
* camel-medium.c (camel_medium_get_headers): New function to
return an array of all headers.
(camel_medium_free_headers): And free them.
* camel-mime-part.c (get_headers, free_headers): Implement this
for CamelMimePart. (Works for CamelMimeMessage too.)
svn path=/trunk/; revision=9849
Diffstat (limited to 'camel')
-rw-r--r-- | camel/ChangeLog | 9 | ||||
-rw-r--r-- | camel/camel-medium.c | 56 | ||||
-rw-r--r-- | camel/camel-medium.h | 13 | ||||
-rw-r--r-- | camel/camel-mime-part.c | 32 |
4 files changed, 108 insertions, 2 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index be49f88dd1..f491fd6aee 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,12 @@ +2001-05-16 Dan Winship <danw@ximian.com> + + * camel-medium.c (camel_medium_get_headers): New function to + return an array of all headers. + (camel_medium_free_headers): And free them. + + * camel-mime-part.c (get_headers, free_headers): Implement this + for CamelMimePart. (Works for CamelMimeMessage too.) + 2001-05-15 Jeffrey Stedfast <fejj@ximian.com> * camel-smime-context.c (camel_smime_context_finalise): Don't diff --git a/camel/camel-medium.c b/camel/camel-medium.c index a54e5ab721..5baa35e7dc 100644 --- a/camel/camel-medium.c +++ b/camel/camel-medium.c @@ -46,6 +46,9 @@ static void set_header (CamelMedium *medium, const gchar *header_name, const voi static void remove_header (CamelMedium *medium, const gchar *header_name); static const void *get_header (CamelMedium *medium, const gchar *header_name); +static GArray *get_headers (CamelMedium *medium); +static void free_headers (CamelMedium *medium, GArray *headers); + static CamelDataWrapper *get_content_object (CamelMedium *medium); static void set_content_object (CamelMedium *medium, CamelDataWrapper *content); @@ -66,6 +69,9 @@ camel_medium_class_init (CamelMediumClass *camel_medium_class) camel_medium_class->remove_header = remove_header; camel_medium_class->get_header = get_header; + camel_medium_class->get_headers = get_headers; + camel_medium_class->free_headers = free_headers; + camel_medium_class->set_content_object = set_content_object; camel_medium_class->get_content_object = get_content_object; } @@ -220,6 +226,56 @@ camel_medium_get_header(CamelMedium *medium, const char *header_name) } +static GArray * +get_headers(CamelMedium *medium) +{ + g_warning("No %s::get_headers implemented", camel_type_to_name(CAMEL_OBJECT_GET_TYPE(medium))); + return NULL; +} + +/** + * camel_medium_get_headers: + * @medium: a medium + * + * Returns an array of all header name/value pairs (as + * CamelMediumHeader structures). The values will be decoded + * to UTF-8 for any headers that are recognized by Camel. The + * caller should not modify the returned data. + * + * Return value: the array of headers, which must be freed with + * camel_medium_free_headers(). + **/ +GArray * +camel_medium_get_headers(CamelMedium *medium) +{ + g_return_val_if_fail (CAMEL_IS_MEDIUM (medium), NULL); + + return CM_CLASS (medium)->get_headers (medium); +} + +static void +free_headers (CamelMedium *medium, GArray *headers) +{ + g_warning("No %s::free_headers implemented", camel_type_to_name(CAMEL_OBJECT_GET_TYPE(medium))); +} + +/** + * camel_medium_free_headers: + * @medium: a medium + * @headers: an array of headers returned from camel_medium_get_headers() + * + * Frees @headers + **/ +void +camel_medium_free_headers (CamelMedium *medium, GArray *headers) +{ + g_return_if_fail (CAMEL_IS_MEDIUM (medium)); + g_return_if_fail (headers != NULL); + + CM_CLASS (medium)->free_headers (medium, headers); +} + + static CamelDataWrapper * get_content_object(CamelMedium *medium) { diff --git a/camel/camel-medium.h b/camel/camel-medium.h index 9ce548ba1d..40ee17675d 100644 --- a/camel/camel-medium.h +++ b/camel/camel-medium.h @@ -42,6 +42,11 @@ extern "C" { #define CAMEL_IS_MEDIUM(o) (CAMEL_CHECK_TYPE((o), CAMEL_MEDIUM_TYPE)) +typedef struct { + const char *name; + const char *value; +} CamelMediumHeader; + struct _CamelMedium { CamelDataWrapper parent_object; @@ -54,8 +59,6 @@ struct _CamelMedium }; - - typedef struct { CamelDataWrapperClass parent_class; @@ -65,6 +68,9 @@ typedef struct { void (*remove_header) (CamelMedium *medium, const gchar *header_name); const void * (*get_header) (CamelMedium *medium, const gchar *header_name); + GArray * (*get_headers) (CamelMedium *medium); + void (*free_headers) (CamelMedium *medium, GArray *headers); + CamelDataWrapper * (*get_content_object) (CamelMedium *medium); void (*set_content_object) (CamelMedium *medium, CamelDataWrapper *content); @@ -79,6 +85,9 @@ void camel_medium_set_header (CamelMedium *medium, const gchar *header_name, con void camel_medium_remove_header (CamelMedium *medium, const gchar *header_name); const void *camel_medium_get_header (CamelMedium *medium, const gchar *header_name); +GArray *camel_medium_get_headers (CamelMedium *medium); +void camel_medium_free_headers (CamelMedium *medium, GArray *headers); + /* accessor methods */ CamelDataWrapper *camel_medium_get_content_object (CamelMedium *medium); void camel_medium_set_content_object (CamelMedium *medium, diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c index 956e0c1554..bc06f8147f 100644 --- a/camel/camel-mime-part.c +++ b/camel/camel-mime-part.c @@ -76,6 +76,8 @@ static void add_header (CamelMedium *medium, con static void set_header (CamelMedium *medium, const char *header_name, const void *header_value); static void remove_header (CamelMedium *medium, const char *header_name); static const void *get_header (CamelMedium *medium, const char *header_name); +static GArray *get_headers (CamelMedium *medium); +static void free_headers (CamelMedium *medium, GArray *headers); static void set_content_object (CamelMedium *medium, CamelDataWrapper *content); @@ -127,6 +129,8 @@ camel_mime_part_class_init (CamelMimePartClass *camel_mime_part_class) camel_medium_class->set_header = set_header; camel_medium_class->get_header = get_header; camel_medium_class->remove_header = remove_header; + camel_medium_class->get_headers = get_headers; + camel_medium_class->free_headers = free_headers; camel_medium_class->set_content_object = set_content_object; camel_data_wrapper_class->write_to_stream = write_to_stream; @@ -282,6 +286,34 @@ get_header (CamelMedium *medium, const char *header_name) return header_raw_find(&part->headers, header_name, NULL); } +static GArray * +get_headers (CamelMedium *medium) +{ + CamelMimePart *part = (CamelMimePart *)medium; + GArray *headers; + CamelMediumHeader header; + struct _header_raw *h; + + headers = g_array_new (FALSE, FALSE, sizeof (CamelMediumHeader)); + for (h = part->headers; h; h = h->next) { + header.name = h->name; + header.value = header_decode_string (h->value); + g_array_append_val (headers, header); + } + + return headers; +} + +static void +free_headers (CamelMedium *medium, GArray *gheaders) +{ + CamelMediumHeader *headers = (CamelMediumHeader *)gheaders->data; + int i; + + for (i = 0; i < gheaders->len; i++) + g_free ((gpointer)headers[i].value); + g_array_free (gheaders, TRUE); +} /* **** Content-Description */ void |