Initialize the gmime for upstream
[platform/upstream/gmime.git] / gmime / gmime.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*  GMime
3  *  Copyright (C) 2000-2012 Jeffrey Stedfast
4  *
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.
9  *
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.
14  *
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
18  *  02110-1301, USA.
19  */
20
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <time.h>
27
28 #ifdef ENABLE_SMIME
29 #include <gpgme.h>
30 #endif
31
32 #include "gmime.h"
33
34 #ifdef ENABLE_CRYPTOGRAPHY
35 #include "gmime-pkcs7-context.h"
36 #include "gmime-gpg-context.h"
37 #endif
38
39
40 /**
41  * SECTION: gmime
42  * @title: gmime
43  * @short_description: Initialization, shutdown and version-check routines
44  * @see_also:
45  *
46  * Initialization, shutdown, and version-check functions.
47  **/
48
49 extern gboolean _g_mime_enable_rfc2047_workarounds (void);
50
51 GQuark gmime_gpgme_error_quark;
52 GQuark gmime_error_quark;
53
54 const guint gmime_major_version = GMIME_MAJOR_VERSION;
55 const guint gmime_minor_version = GMIME_MINOR_VERSION;
56 const guint gmime_micro_version = GMIME_MICRO_VERSION;
57 const guint gmime_interface_age = GMIME_INTERFACE_AGE;
58 const guint gmime_binary_age = GMIME_BINARY_AGE;
59
60 static unsigned int initialized = 0;
61 static guint32 enable = 0;
62
63
64 /**
65  * g_mime_check_version:
66  * @major: Minimum major version
67  * @minor: Minimum minor version
68  * @micro: Minimum micro version
69  *
70  * Checks that the GMime library version meets the requirements of the
71  * required version.
72  *
73  * Returns: %TRUE if the requirement is met or %FALSE otherwise.
74  **/
75 gboolean
76 g_mime_check_version (guint major, guint minor, guint micro)
77 {
78         if (GMIME_MAJOR_VERSION > major)
79                 return TRUE;
80         
81         if (GMIME_MAJOR_VERSION == major && GMIME_MINOR_VERSION > minor)
82                 return TRUE;
83         
84         if (GMIME_MAJOR_VERSION == major && GMIME_MINOR_VERSION == minor && GMIME_MICRO_VERSION >= micro)
85                 return TRUE;
86         
87         return FALSE;
88 }
89
90
91 /**
92  * g_mime_init:
93  * @flags: initialization flags
94  *
95  * Initializes GMime.
96  *
97  * Note: Calls g_mime_charset_map_init() and g_mime_iconv_init() as
98  * well.
99  **/
100 void
101 g_mime_init (guint32 flags)
102 {
103         if (initialized++)
104                 return;
105         
106 #if defined (HAVE_TIMEZONE) || defined (HAVE__TIMEZONE)
107         /* initialize timezone */
108         tzset ();
109 #endif
110         
111         enable = flags;
112         
113         g_type_init ();
114         
115         g_mime_charset_map_init ();
116         
117         g_mime_iconv_init ();
118         
119 #ifdef ENABLE_SMIME
120         /* gpgme_check_version() initializes GpgMe */
121         gpgme_check_version (NULL);
122 #endif /* ENABLE_SMIME */
123         
124         gmime_gpgme_error_quark = g_quark_from_static_string ("gmime-gpgme");
125         gmime_error_quark = g_quark_from_static_string ("gmime");
126         
127         /* register our GObject types with the GType system */
128         g_mime_crypto_context_get_type ();
129         g_mime_decrypt_result_get_type ();
130         g_mime_certificate_list_get_type ();
131         g_mime_signature_list_get_type ();
132         g_mime_certificate_get_type ();
133         g_mime_signature_get_type ();
134 #ifdef ENABLE_CRYPTOGRAPHY
135         g_mime_gpg_context_get_type ();
136         g_mime_pkcs7_context_get_type ();
137 #endif
138         
139         g_mime_filter_get_type ();
140         g_mime_filter_basic_get_type ();
141         g_mime_filter_best_get_type ();
142         g_mime_filter_charset_get_type ();
143         g_mime_filter_crlf_get_type ();
144         g_mime_filter_enriched_get_type ();
145         g_mime_filter_from_get_type ();
146         g_mime_filter_gzip_get_type ();
147         g_mime_filter_html_get_type ();
148         g_mime_filter_md5_get_type ();
149         g_mime_filter_strip_get_type ();
150         g_mime_filter_windows_get_type ();
151         g_mime_filter_yenc_get_type ();
152         
153         g_mime_stream_get_type ();
154         g_mime_stream_buffer_get_type ();
155         g_mime_stream_cat_get_type ();
156         g_mime_stream_file_get_type ();
157         g_mime_stream_filter_get_type ();
158         g_mime_stream_fs_get_type ();
159         g_mime_stream_gio_get_type ();
160         g_mime_stream_mem_get_type ();
161         g_mime_stream_mmap_get_type ();
162         g_mime_stream_null_get_type ();
163         g_mime_stream_pipe_get_type ();
164         
165         g_mime_parser_get_type ();
166         g_mime_message_get_type ();
167         g_mime_data_wrapper_get_type ();
168         g_mime_content_type_get_type ();
169         g_mime_content_disposition_get_type ();
170         
171         internet_address_get_type ();
172         internet_address_list_get_type ();
173         internet_address_group_get_type ();
174         internet_address_mailbox_get_type ();
175         
176         /* register our default mime object types */
177         g_mime_object_type_registry_init ();
178         g_mime_object_register_type ("*", "*", g_mime_part_get_type ());
179         g_mime_object_register_type ("multipart", "*", g_mime_multipart_get_type ());
180         g_mime_object_register_type ("multipart", "encrypted", g_mime_multipart_encrypted_get_type ());
181         g_mime_object_register_type ("multipart", "signed", g_mime_multipart_signed_get_type ());
182         g_mime_object_register_type ("message", "rfc822", g_mime_message_part_get_type ());
183         g_mime_object_register_type ("message", "rfc2822", g_mime_message_part_get_type ());
184         g_mime_object_register_type ("message", "news", g_mime_message_part_get_type ());
185         g_mime_object_register_type ("message", "partial", g_mime_message_partial_get_type ());
186 }
187
188
189 /**
190  * g_mime_shutdown:
191  *
192  * Frees internally allocated tables created in g_mime_init(). Also
193  * calls g_mime_charset_map_shutdown() and g_mime_iconv_shutdown().
194  **/
195 void
196 g_mime_shutdown (void)
197 {
198         if (--initialized)
199                 return;
200         
201         g_mime_object_type_registry_shutdown ();
202         g_mime_charset_map_shutdown ();
203         g_mime_iconv_shutdown ();
204 }
205
206
207 gboolean
208 _g_mime_enable_rfc2047_workarounds (void)
209 {
210         return (enable & GMIME_ENABLE_RFC2047_WORKAROUNDS);
211 }