2 * Copyright (C) 2000 Ximian Inc.
4 * Authors: Michael Zucchi <notzed@ximian.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU Lesser General Public
8 * License as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 #include "camel-mime-filter-index.h"
22 #include "camel-text-index.h"
24 static void camel_mime_filter_index_class_init (CamelMimeFilterIndexClass *klass);
25 static void camel_mime_filter_index_finalize (CamelObject *o);
27 static CamelMimeFilterClass *camel_mime_filter_index_parent;
30 camel_mime_filter_index_get_type (void)
32 static CamelType type = CAMEL_INVALID_TYPE;
34 if (type == CAMEL_INVALID_TYPE) {
35 type = camel_type_register (camel_mime_filter_get_type (), "CamelMimeFilterIndex",
36 sizeof (CamelMimeFilterIndex),
37 sizeof (CamelMimeFilterIndexClass),
38 (CamelObjectClassInitFunc) camel_mime_filter_index_class_init,
41 (CamelObjectFinalizeFunc) camel_mime_filter_index_finalize);
48 camel_mime_filter_index_finalize(CamelObject *o)
50 CamelMimeFilterIndex *f = (CamelMimeFilterIndex *)o;
53 camel_object_unref((CamelObject *)f->name);
54 camel_object_unref((CamelObject *)f->index);
58 complete(CamelMimeFilter *mf, char *in, size_t len, size_t prespace, char **out, size_t *outlenptr, size_t *outprespace)
60 CamelMimeFilterIndex *f = (CamelMimeFilterIndex *)mf;
62 if (f->index == NULL || f->name==NULL) {
66 camel_index_name_add_buffer(f->name, in, len);
67 camel_index_name_add_buffer(f->name, NULL, 0);
72 *outprespace = prespace;
76 filter(CamelMimeFilter *mf, char *in, size_t len, size_t prespace, char **out, size_t *outlenptr, size_t *outprespace)
78 CamelMimeFilterIndex *f = (CamelMimeFilterIndex *)mf;
80 if (f->index == NULL || f->name==NULL) {
84 camel_index_name_add_buffer(f->name, in, len);
89 *outprespace = prespace;
93 camel_mime_filter_index_class_init (CamelMimeFilterIndexClass *klass)
95 CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
97 camel_mime_filter_index_parent = CAMEL_MIME_FILTER_CLASS (camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
99 /*filter_class->reset = reset;*/
100 filter_class->filter = filter;
101 filter_class->complete = complete;
105 * camel_mime_filter_index_new:
107 * Create a new #CamelMimeFilterIndex object
109 * Returns a new #CamelMimeFilterIndex object
111 CamelMimeFilterIndex *
112 camel_mime_filter_index_new (void)
114 CamelMimeFilterIndex *new = CAMEL_MIME_FILTER_INDEX ( camel_object_new (camel_mime_filter_index_get_type ()));
120 * camel_mime_filter_index_new_index:
121 * @index: a #CamelIndex object
123 * Create a new #CamelMimeFilterIndex based on @index.
125 * Returns a new #CamelMimeFilterIndex object
127 CamelMimeFilterIndex *
128 camel_mime_filter_index_new_index (CamelIndex *index)
130 CamelMimeFilterIndex *new = camel_mime_filter_index_new();
135 camel_object_ref (index);
140 /* Set the match name for any indexed words */
144 * camel_mime_filter_index_set_name:
145 * @filter: a #CamelMimeFilterIndex object
146 * @name: a #CamelIndexName object
148 * Set the match name for any indexed words.
151 camel_mime_filter_index_set_name (CamelMimeFilterIndex *filter, CamelIndexName *name)
154 camel_object_unref (filter->name);
157 camel_object_ref (name);
162 * camel_mime_filter_index_set_index:
163 * @filter: a #CamelMimeFilterIndex object
164 * @index: a #CamelIndex object
166 * Set @index on @filter.
169 camel_mime_filter_index_set_index (CamelMimeFilterIndex *filter, CamelIndex *index)
173 size_t outlen, outspace;
175 camel_mime_filter_complete((CamelMimeFilter *)filter, "", 0, 0, &out, &outlen, &outspace);
176 camel_object_unref (index);
179 filter->index = index;
181 camel_object_ref (index);