1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2000-2012 Jeffrey Stedfast
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * as published by the Free Software Foundation; either version 2.1
8 * of the License, or (at your option) any later version.
10 * This library 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 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
22 #ifndef __GMIME_FILTER_BEST_H__
23 #define __GMIME_FILTER_BEST_H__
25 #include <gmime/gmime-encodings.h>
26 #include <gmime/gmime-filter.h>
27 #include <gmime/gmime-charset.h>
28 #include <gmime/gmime-utils.h>
32 #define GMIME_TYPE_FILTER_BEST (g_mime_filter_best_get_type ())
33 #define GMIME_FILTER_BEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMIME_TYPE_FILTER_BEST, GMimeFilterBest))
34 #define GMIME_FILTER_BEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GMIME_TYPE_FILTER_BEST, GMimeFilterBestClass))
35 #define GMIME_IS_FILTER_BEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GMIME_TYPE_FILTER_BEST))
36 #define GMIME_IS_FILTER_BEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GMIME_TYPE_FILTER_BEST))
37 #define GMIME_FILTER_BEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GMIME_TYPE_FILTER_BEST, GMimeFilterBestClass))
39 typedef struct _GMimeFilterBest GMimeFilterBest;
40 typedef struct _GMimeFilterBestClass GMimeFilterBestClass;
43 * GMimeFilterBestFlags:
44 * @GMIME_FILTER_BEST_CHARSET: Enable best-charset detection.
45 * @GMIME_FILTER_BEST_ENCODING: Enable best-encoding detection.
47 * Bit flags to enable charset and/or encoding scanning to make
48 * educated guesses as to what the best charset and/or encodings to
49 * use for the content passed through the filter.
52 GMIME_FILTER_BEST_CHARSET = (1 << 0),
53 GMIME_FILTER_BEST_ENCODING = (1 << 1)
54 } GMimeFilterBestFlags;
59 * @parent_object: parent #GMimeFilter
60 * @flags: #GMimeFilterBestFlags
61 * @charset: #GMimeCharset state
62 * @count0: count of nul-bytes passed through the filter
63 * @count8: count of 8bit bytes passed through the filter
64 * @total: total number of bytes passed through the filter
65 * @maxline: the length of the longest line passed through the filter
66 * @linelen: current line length
67 * @frombuf: buffer for checking From_ lines
68 * @fromlen: length of bytes in @frombuf
69 * @hadfrom: %TRUE if any line started with "From "
70 * @startline: start line state
71 * @midline: mid-line state
73 * A filter for calculating the best encoding and/or charset to encode
74 * the data passed through it.
76 struct _GMimeFilterBest {
77 GMimeFilter parent_object;
79 GMimeFilterBestFlags flags;
81 /* for best charset detection */
84 /* for best encoding detection */
85 unsigned int count0; /* count of null bytes */
86 unsigned int count8; /* count of 8bit bytes */
87 unsigned int total; /* total octets */
89 unsigned int maxline; /* longest line length */
90 unsigned int linelen; /* current line length */
92 unsigned char frombuf[6];
93 unsigned int fromlen : 4;
94 unsigned int hadfrom : 1;
96 unsigned int startline : 1;
97 unsigned int midline : 1;
100 struct _GMimeFilterBestClass {
101 GMimeFilterClass parent_class;
106 GType g_mime_filter_best_get_type (void);
108 GMimeFilter *g_mime_filter_best_new (GMimeFilterBestFlags flags);
110 const char *g_mime_filter_best_charset (GMimeFilterBest *best);
112 GMimeContentEncoding g_mime_filter_best_encoding (GMimeFilterBest *best, GMimeEncodingConstraint constraint);
116 #endif /* __GMIME_FILTER_BEST_H__ */