evolution-3.6.4/modules/vcard-inline/e-mail-formatter-vcard-inline.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-formatter-vcard-inline.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-formatter-vcard-inline.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
  1 /*
  2  * e-mail-formatter-vcard-inline.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 #ifdef HAVE_CONFIG_H
 20 #include <config.h>
 21 #endif
 22 
 23 #include "e-mail-formatter-vcard-inline.h"
 24 #include "e-mail-part-vcard-inline.h"
 25 
 26 #include <glib/gi18n-lib.h>
 27 
 28 #include <libebackend/libebackend.h>
 29 
 30 #include <em-format/e-mail-formatter-extension.h>
 31 #include <em-format/e-mail-formatter.h>
 32 #include <em-format/e-mail-formatter-utils.h>
 33 #include <em-format/e-mail-part-utils.h>
 34 
 35 #include <camel/camel.h>
 36 
 37 #define d(x)
 38 
 39 typedef struct _EMailFormatterVCardInline {
 40 	EExtension parent;
 41 } EMailFormatterVCardInline;
 42 
 43 typedef struct _EMailFormatterVCardInlineClass {
 44 	EExtensionClass parent_class;
 45 } EMailFormatterVCardInlineClass;
 46 
 47 GType e_mail_formatter_vcard_inline_get_type (void);
 48 static void e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface);
 49 static void e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface);
 50 
 51 G_DEFINE_DYNAMIC_TYPE_EXTENDED (
 52 	EMailFormatterVCardInline,
 53 	e_mail_formatter_vcard_inline,
 54 	E_TYPE_EXTENSION,
 55 	0,
 56 	G_IMPLEMENT_INTERFACE_DYNAMIC (
 57 		E_TYPE_MAIL_EXTENSION,
 58 		e_mail_formatter_mail_extension_interface_init)
 59 	G_IMPLEMENT_INTERFACE_DYNAMIC (
 60 		E_TYPE_MAIL_FORMATTER_EXTENSION,
 61 		e_mail_formatter_formatter_extension_interface_init));
 62 
 63 static const gchar * formatter_mime_types[] = { "text/vcard", "text/x-vcard",
 64 					       "text/directory", NULL };
 65 
 66 static gboolean
 67 emfe_vcard_inline_format (EMailFormatterExtension *extension,
 68                           EMailFormatter *formatter,
 69                           EMailFormatterContext *context,
 70                           EMailPart *part,
 71                           CamelStream *stream,
 72                           GCancellable *cancellable)
 73 {
 74 	EMailPartVCardInline *vcard_part;
 75 
 76 	g_return_val_if_fail (E_MAIL_PART_IS (part, EMailPartVCardInline), FALSE);
 77 	vcard_part = (EMailPartVCardInline *) part;
 78 
 79 	if (context->mode == E_MAIL_FORMATTER_MODE_RAW)  {
 80 
 81 		EContact *contact;
 82 
 83 		if (vcard_part->contact_list != NULL)
 84 			contact = E_CONTACT (vcard_part->contact_list->data);
 85 		else
 86 			contact = NULL;
 87 
 88 		eab_contact_formatter_format_contact_sync (
 89 			vcard_part->formatter, contact, stream, cancellable);
 90 
 91 	} else {
 92 		const gchar *default_charset, *charset;
 93 		gchar *str, *uri;
 94 		gint length;
 95 		const gchar *label = NULL;
 96 		EABContactDisplayMode mode;
 97 		const gchar *info = NULL;
 98 		gchar *html_label, *access_key;
 99 
100 		length = g_slist_length (vcard_part->contact_list);
101 		if (length < 1)
102 			return FALSE;
103 
104 		default_charset = e_mail_formatter_get_default_charset (formatter);
105 		charset = e_mail_formatter_get_charset (formatter);
106 
107 		if (!default_charset)
108 			default_charset = "";
109 		if (!charset)
110 			charset = "";
111 
112 		if (!vcard_part->message_uid && context->message_uid)
113 			vcard_part->message_uid = g_strdup (context->message_uid);
114 
115 		if (!vcard_part->folder && context->folder)
116 			vcard_part->folder = g_object_ref (context->folder);
117 
118 		uri = e_mail_part_build_uri (
119 			context->folder, context->message_uid,
120 			"part_id", G_TYPE_STRING, part->id,
121 			"mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_RAW,
122 			"formatter_default_charset", G_TYPE_STRING, default_charset,
123 			"formatter_charset", G_TYPE_STRING, charset,
124 			NULL);
125 
126 		mode = eab_contact_formatter_get_display_mode (vcard_part->formatter);
127 		if (mode == EAB_CONTACT_DISPLAY_RENDER_COMPACT) {
128 			mode = EAB_CONTACT_DISPLAY_RENDER_NORMAL;
129 			label = _("Show F_ull vCard");
130 		} else {
131 			mode = EAB_CONTACT_DISPLAY_RENDER_COMPACT;
132 			label = _("Show Com_pact vCard");
133 		}
134 
135 		str = g_strdup_printf (
136 			"<div id=\"%s\">", part->id);
137 		camel_stream_write_string (stream, str, cancellable, NULL);
138 		g_free (str);
139 
140 		html_label = e_mail_formatter_parse_html_mnemonics (
141 				label, &access_key);
142 		str = g_strdup_printf (
143 			"<button type=\"button\" "
144 				"name=\"set-display-mode\" "
145 				"class=\"org-gnome-vcard-inline-display-mode-button\" "
146 				"value=\"%d\" "
147 				"accesskey=\"%s\">%s</button>",
148 			mode, access_key, html_label);
149 		camel_stream_write_string (stream, str, cancellable, NULL);
150 		g_free (str);
151 		g_free (html_label);
152 		if (access_key)
153 			g_free (access_key);
154 
155 		html_label = e_mail_formatter_parse_html_mnemonics (
156 				_("Save _To Addressbook"), &access_key);
157 		str = g_strdup_printf (
158 			"<button type=\"button\" "
159 				"name=\"save-to-addressbook\" "
160 				"class=\"org-gnome-vcard-inline-save-button\" "
161 				"value=\"%s\" "
162 				"accesskey=\"%s\">%s</button><br>"
163 			"<iframe width=\"100%%\" height=\"auto\" frameborder=\"0\""
164 				"src=\"%s\" name=\"%s\"></iframe>"
165 			"</div>",
166 			part->id, access_key, html_label,
167 			uri, part->id);
168 		camel_stream_write_string (stream, str, cancellable, NULL);
169 		g_free (str);
170 		g_free (html_label);
171 		if (access_key)
172 			g_free (access_key);
173 
174 		if (length == 2) {
175 
176 			info = _("There is one other contact.");
177 
178 		} else if (length > 2) {
179 
180 			/* Translators: This will always be two or more. */
181 			info = g_strdup_printf (ngettext (
182 				"There is %d other contact.",
183 				"There are %d other contacts.",
184 				length - 1), length - 1);
185 		}
186 
187 		if (info) {
188 
189 			str = g_strdup_printf (
190 				"<div class=\"attachment-info\">%s</div>",
191 				info);
192 
193 			camel_stream_write_string (stream, str, cancellable, NULL);
194 
195 			g_free (str);
196 		}
197 
198 		g_free (uri);
199 	}
200 
201 	return TRUE;
202 }
203 
204 static const gchar *
205 emfe_vcard_inline_get_display_name (EMailFormatterExtension *extension)
206 {
207 	return _("Addressbook Contact");
208 }
209 
210 static const gchar *
211 emfe_vcard_inline_get_description (EMailFormatterExtension *extension)
212 {
213 	return _("Display the part as an addressbook contact");
214 }
215 
216 static const gchar **
217 emfe_vcard_inline_mime_types (EMailExtension *extension)
218 {
219 	return formatter_mime_types;
220 }
221 
222 static void
223 e_mail_formatter_vcard_inline_constructed (GObject *object)
224 {
225 	EExtensible *extensible;
226 	EMailExtensionRegistry *reg;
227 
228 	extensible = e_extension_get_extensible (E_EXTENSION (object));
229 	reg = E_MAIL_EXTENSION_REGISTRY (extensible);
230 
231 	e_mail_extension_registry_add_extension (reg, E_MAIL_EXTENSION (object));
232 }
233 
234 static void
235 e_mail_formatter_vcard_inline_class_init (EMailFormatterVCardInlineClass *class)
236 {
237 	GObjectClass *object_class;
238 	EExtensionClass *extension_class;
239 
240 	object_class = G_OBJECT_CLASS (class);
241 	object_class->constructed = e_mail_formatter_vcard_inline_constructed;
242 
243 	extension_class = E_EXTENSION_CLASS (class);
244 	extension_class->extensible_type = E_TYPE_MAIL_FORMATTER_EXTENSION_REGISTRY;
245 }
246 
247 static void
248 e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface)
249 {
250 	iface->format = emfe_vcard_inline_format;
251 	iface->get_display_name = emfe_vcard_inline_get_display_name;
252 	iface->get_description = emfe_vcard_inline_get_description;
253 }
254 
255 static void
256 e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface)
257 {
258 	iface->mime_types = emfe_vcard_inline_mime_types;
259 }
260 
261 static void
262 e_mail_formatter_vcard_inline_init (EMailFormatterVCardInline *formatter)
263 {
264 
265 }
266 
267 void
268 e_mail_formatter_vcard_inline_type_register (GTypeModule *type_module)
269 {
270 	e_mail_formatter_vcard_inline_register_type (type_module);
271 }
272 
273 static void
274 e_mail_formatter_vcard_inline_class_finalize (EMailFormatterVCardInlineClass *class)
275 {
276 
277 }