No issues found
Tool | Failure ID | Location | Function | Message | Data |
---|---|---|---|---|---|
clang-analyzer | no-output-found | e-mail-part.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None | |
clang-analyzer | no-output-found | e-mail-part.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None |
1 /*
2 * e-mail-part.c
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with the program; if not, see <http://www.gnu.org/licenses/>
16 *
17 */
18
19 #include <camel/camel.h>
20
21 #include "e-mail-part.h"
22
23 /**
24 * EMailPart:
25 *
26 * The #EMailPart is a wrapper around #CamelMimePart which holds additional
27 * information about the mime part, like it's ID, encryption type etc.
28 *
29 * #EMailPart is not GObject-based, but has a simple reference counting.
30 *
31 * Each #EMailPart must have a unique ID. The ID is a dot-separated hierarchical
32 * description of the location of the part within the email message.
33 */
34
35 struct _EMailPartPrivate {
36 guint ref_cnt;
37 gsize instance_size;
38 GFreeFunc free_func;
39 };
40
41 static void
42 mail_part_free (EMailPart *part)
43 {
44 if (!part)
45 return;
46
47 if (part->part) {
48 g_object_unref (part->part);
49 part->part = NULL;
50 }
51
52 if (part->cid) {
53 g_free (part->cid);
54 part->cid = NULL;
55 }
56
57 if (part->mime_type) {
58 g_free (part->mime_type);
59 part->mime_type = NULL;
60 }
61
62 if (part->validity) {
63 camel_cipher_validity_free (part->validity);
64 part->validity = NULL;
65 }
66
67 if (part->validity_parent) {
68 camel_cipher_validity_free (part->validity_parent);
69 part->validity_parent = NULL;
70 }
71
72 if (part->priv->free_func) {
73 part->priv->free_func (part);
74 part->priv->free_func = NULL;
75 }
76
77 if (part->id) {
78 g_free (part->id);
79 part->id = NULL;
80 }
81
82 g_free (part->priv);
83 part->priv = NULL;
84
85 g_free (part);
86 }
87
88 /**
89 * e_mail_part_new:
90 * @part: (allow-none) a #CamelMimePart or %NULL
91 * @id: part ID
92 *
93 * Creates a new #EMailPart for given mime part.
94 *
95 * Return value: a new #EMailPart
96 */
97 EMailPart *
98 e_mail_part_new (CamelMimePart *part,
99 const gchar *id)
100 {
101 return e_mail_part_subclass_new (part, id, sizeof (EMailPart), NULL);
102 }
103
104 /**
105 * e_mail_part_new:
106 * @part: (allow-none) a #CamelMimePart or %NULL
107 * @id: part ID
108 * @size: Size of the EMailPart subclass
109 *
110 * Allocates a @size bytes representing an #EMailPart subclass.
111 *
112 * Return value: a new #EMailPart-based object
113 */
114 EMailPart *
115 e_mail_part_subclass_new (CamelMimePart *part,
116 const gchar *id,
117 gsize size,
118 GFreeFunc free_func)
119 {
120 EMailPart *mail_part;
121
122 g_return_val_if_fail (size >= sizeof (EMailPart), NULL);
123
124 mail_part = g_malloc0 (size);
125 mail_part->priv = g_new0 (EMailPartPrivate, 1);
126
127 mail_part->priv->ref_cnt = 1;
128 mail_part->priv->free_func = free_func;
129 mail_part->priv->instance_size = size;
130
131 if (part) {
132 mail_part->part = g_object_ref (part);
133 }
134
135 if (id) {
136 mail_part->id = g_strdup (id);
137 }
138
139 return mail_part;
140 }
141
142 EMailPart *
143 e_mail_part_ref (EMailPart *part)
144 {
145 g_return_val_if_fail (part != NULL, NULL);
146 g_return_val_if_fail (part->priv != NULL, NULL);
147
148 g_atomic_int_inc (&part->priv->ref_cnt);
149
150 return part;
151 }
152
153 void
154 e_mail_part_unref (EMailPart *part)
155 {
156 g_return_if_fail (part != NULL);
157 g_return_if_fail (part->priv != NULL);
158
159 if (g_atomic_int_dec_and_test (&part->priv->ref_cnt)) {
160 mail_part_free (part);
161 }
162 }
163
164 gsize
165 e_mail_part_get_instance_size (EMailPart *part)
166 {
167 g_return_val_if_fail (part != NULL, 0);
168
169 return part->priv->instance_size;
170 }
171
172 /**
173 * e_mail_part_update_validity:
174 * @part: An #EMailPart
175 * @validity_type: E_MAIL_PART_VALIDITY_* flags
176 * @validity: a #CamelCipherValidity
177 *
178 * Updates validity of the @part. When the part already has some validity
179 * set, the new @validity and @validity_type are just appended, preserving
180 * the original validity.
181 */
182 void
183 e_mail_part_update_validity (EMailPart *part,
184 CamelCipherValidity *validity,
185 guint32 validity_type)
186 {
187 g_return_if_fail (part != NULL);
188
189 part->validity_type &= validity_type;
190
191 if (part->validity) {
192 camel_cipher_validity_envelope (part->validity, validity);
193 } else {
194 part->validity = camel_cipher_validity_clone (validity);
195 }
196 }