evolution-3.6.4/em-format/e-mail-parser-message-external.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-parser-message-external.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-parser-message-external.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-parser-message-external.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-format-extensions.h"
 24 
 25 #include <em-format/e-mail-parser-extension.h>
 26 #include <em-format/e-mail-parser.h>
 27 #include <e-util/e-util.h>
 28 
 29 #include <glib/gi18n-lib.h>
 30 #include <camel/camel.h>
 31 
 32 #include <string.h>
 33 #include <ctype.h>
 34 
 35 typedef struct _EMailParserMessageExternal {
 36 	GObject parent;
 37 } EMailParserMessageExternal;
 38 
 39 typedef struct _EMailParserMessageExternalClass {
 40 	GObjectClass parent_class;
 41 } EMailParserMessageExternalClass;
 42 
 43 static void e_mail_parser_parser_extension_interface_init (EMailParserExtensionInterface *iface);
 44 static void e_mail_parser_mail_extension_interface_init (EMailExtensionInterface *iface);
 45 
 46 G_DEFINE_TYPE_EXTENDED (
 47 	EMailParserMessageExternal,
 48 	e_mail_parser_message_external,
 49 	G_TYPE_OBJECT,
 50 	0,
 51 	G_IMPLEMENT_INTERFACE (
 52 		E_TYPE_MAIL_EXTENSION,
 53 		e_mail_parser_mail_extension_interface_init)
 54 	G_IMPLEMENT_INTERFACE (
 55 		E_TYPE_MAIL_PARSER_EXTENSION,
 56 		e_mail_parser_parser_extension_interface_init));
 57 
 58 static const gchar * parser_mime_types[] = { "message/external-body",
 59 					    NULL };
 60 
 61 static GSList *
 62 empe_msg_external_parse (EMailParserExtension *extension,
 63                          EMailParser *parser,
 64                          CamelMimePart *part,
 65                          GString *part_id,
 66                          GCancellable *cancellable)
 67 {
 68 	EMailPart *mail_part;
 69 	CamelMimePart *newpart;
 70 	CamelContentType *type;
 71 	const gchar *access_type;
 72 	gchar *url = NULL, *desc = NULL;
 73 	gchar *content;
 74 	gint len;
 75 	gchar *mime_type;
 76 
 77 	if (g_cancellable_is_cancelled (cancellable))
 78 		return NULL;
 79 
 80 	newpart = camel_mime_part_new ();
 81 
 82 	/* needs to be cleaner */
 83 	type = camel_mime_part_get_content_type (part);
 84 	access_type = camel_content_type_param (type, "access-type");
 85 	if (!access_type) {
 86 		const gchar *msg = _("Malformed external-body part");
 87 		mime_type = g_strdup ("text/plain");
 88 		camel_mime_part_set_content (newpart, msg, strlen (msg), mime_type);
 89 		goto addPart;
 90 	}
 91 
 92 	if (!g_ascii_strcasecmp (access_type, "ftp") ||
 93 	    !g_ascii_strcasecmp (access_type, "anon-ftp")) {
 94 		const gchar *name, *site, *dir, *mode;
 95 		gchar *path;
 96 		gchar ftype[16];
 97 
 98 		name = camel_content_type_param (type, "name");
 99 		site = camel_content_type_param (type, "site");
100 		dir = camel_content_type_param (type, "directory");
101 		mode = camel_content_type_param (type, "mode");
102 		if (name == NULL || site == NULL)
103 			goto fail;
104 
105 		/* Generate the path. */
106 		if (dir)
107 			path = g_strdup_printf ("/%s/%s", *dir == '/' ? dir + 1 : dir, name);
108 		else
109 			path = g_strdup_printf ("/%s", *name == '/' ? name + 1 : name);
110 
111 		if (mode && *mode)
112 			sprintf (ftype, ";type=%c",  *mode);
113 		else
114 			ftype[0] = 0;
115 
116 		url = g_strdup_printf ("ftp://%s%s%s", site, path, ftype);
117 		g_free (path);
118 		desc = g_strdup_printf (_("Pointer to FTP site (%s)"), url);
119 	} else if (!g_ascii_strcasecmp (access_type, "local-file")) {
120 		const gchar *name, *site;
121 
122 		name = camel_content_type_param (type, "name");
123 		site = camel_content_type_param (type, "site");
124 		if (name == NULL)
125 			goto fail;
126 
127 		url = g_filename_to_uri (name, NULL, NULL);
128 		if (site)
129 			desc = g_strdup_printf (_("Pointer to local file (%s) valid at site \"%s\""), name, site);
130 		else
131 			desc = g_strdup_printf (_("Pointer to local file (%s)"), name);
132 	} else if (!g_ascii_strcasecmp (access_type, "URL")) {
133 		const gchar *urlparam;
134 		gchar *s, *d;
135 
136 		/* RFC 2017 */
137 		urlparam = camel_content_type_param (type, "url");
138 		if (urlparam == NULL)
139 			goto fail;
140 
141 		/* For obscure MIMEy reasons, the URL may be split into words */
142 		url = g_strdup (urlparam);
143 		s = d = url;
144 		while (*s) {
145 			if (!isspace ((guchar) * s))
146 				*d++ = *s;
147 			s++;
148 		}
149 		*d = 0;
150 		desc = g_strdup_printf (_("Pointer to remote data (%s)"), url);
151 	} else {
152 		goto fail;
153 	}
154 
155 	mime_type = g_strdup ("text/html");
156 	content = g_strdup_printf ("<a href=\"%s\">%s</a>", url, desc);
157 	camel_mime_part_set_content (newpart, content, strlen (content), mime_type);
158 	g_free (content);
159 
160 	g_free (url);
161 	g_free (desc);
162 
163 	goto addPart;
164 
165 fail:
166 	content = g_strdup_printf (
167 		_("Pointer to unknown external data (\"%s\" type)"),
168 		access_type);
169 	mime_type = g_strdup ("text/plain");
170 	camel_mime_part_set_content (newpart, content, strlen (content), mime_type);
171 	g_free (content);
172 
173 addPart:
174 	len = part_id->len;
175 	g_string_append (part_id, ".msg_external");
176 	mail_part = e_mail_part_new (part, part_id->str);
177 	mail_part->mime_type = mime_type;
178 	g_string_truncate (part_id, len);
179 
180 	return g_slist_append (NULL, mail_part);
181 }
182 
183 static const gchar **
184 empe_msg_external_mime_types (EMailExtension *extension)
185 {
186 	return parser_mime_types;
187 }
188 
189 static void
190 e_mail_parser_message_external_class_init (EMailParserMessageExternalClass *class)
191 {
192 }
193 
194 static void
195 e_mail_parser_parser_extension_interface_init (EMailParserExtensionInterface *iface)
196 {
197 	iface->parse = empe_msg_external_parse;
198 }
199 
200 static void
201 e_mail_parser_mail_extension_interface_init (EMailExtensionInterface *iface)
202 {
203 	iface->mime_types = empe_msg_external_mime_types;
204 }
205 
206 static void
207 e_mail_parser_message_external_init (EMailParserMessageExternal *parser)
208 {
209 
210 }