evolution-3.6.4/em-format/e-mail-formatter-quote.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-formatter-quote.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-formatter-quote.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-quote.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 "e-mail-formatter-quote.h"
 20 
 21 #include <camel/camel.h>
 22 
 23 #include "e-mail-formatter-extension.h"
 24 #include "e-mail-format-extensions.h"
 25 #include "e-mail-part.h"
 26 #include "e-mail-part-attachment.h"
 27 #include "e-mail-part-utils.h"
 28 
 29 #include <libebackend/libebackend.h>
 30 #include <gdk/gdk.h>
 31 #include <glib/gi18n.h>
 32 
 33 struct _EMailFormatterQuotePrivate {
 34 	gchar *credits;
 35 	EMailFormatterQuoteFlags flags;
 36 };
 37 
 38 #define E_MAIL_FORMATTER_QUOTE_GET_PRIVATE(obj) \
 39 	(G_TYPE_INSTANCE_GET_PRIVATE \
 40 	((obj), E_TYPE_MAIL_FORMATTER_QUOTE, EMailFormatterQuotePrivate))
 41 
 42 static gpointer e_mail_formatter_quote_parent_class = 0;
 43 
 44 static EMailFormatterContext *
 45 mail_formatter_quote_create_context (EMailFormatter *formatter)
 46 {
 47 	return g_malloc0 (sizeof (EMailFormatterQuoteContext));
 48 }
 49 
 50 static void
 51 mail_formatter_quote_free_context (EMailFormatter *formatter,
 52                                    EMailFormatterContext *context)
 53 {
 54 	g_free ((EMailFormatterQuoteContext *) context);
 55 }
 56 
 57 static void
 58 mail_formatter_quote_run (EMailFormatter *formatter,
 59                           EMailFormatterContext *context,
 60                           CamelStream *stream,
 61                           GCancellable *cancellable)
 62 {
 63 	EMailFormatterQuote *qf;
 64 	EMailFormatterQuoteContext *qf_context;
 65 	GSettings *settings;
 66 	GSList *iter;
 67 
 68 	if (g_cancellable_is_cancelled (cancellable))
 69 		return;
 70 
 71 	qf = E_MAIL_FORMATTER_QUOTE (formatter);
 72 
 73 	qf_context = (EMailFormatterQuoteContext *) context;
 74 	qf_context->qf_flags = qf->priv->flags;
 75 
 76 	g_seekable_seek (
 77 		G_SEEKABLE (stream),
 78 		0, G_SEEK_SET, NULL, NULL);
 79 
 80 	settings = g_settings_new ("org.gnome.evolution.mail");
 81 	if (g_settings_get_boolean (
 82 		settings, "composer-top-signature"))
 83 		camel_stream_write_string (
 84 			stream, "<br>\n", cancellable, NULL);
 85 	g_object_unref (settings);
 86 
 87 	if (qf->priv->credits && *qf->priv->credits) {
 88 		gchar *credits = g_strdup_printf ("%s<br>", qf->priv->credits);
 89 		camel_stream_write_string (stream, credits, cancellable, NULL);
 90 		g_free (credits);
 91 	} else {
 92 		camel_stream_write_string (stream, "<br>", cancellable, NULL);
 93 	}
 94 
 95 	if (qf->priv->flags & E_MAIL_FORMATTER_QUOTE_FLAG_CITE) {
 96 		camel_stream_write_string (
 97 			stream,
 98 			"<!--+GtkHTML:<DATA class=\"ClueFlow\" "
 99 			"key=\"orig\" value=\"1\">-->\n"
100 			"<blockquote type=cite>\n", cancellable, NULL);
101 	}
102 
103 	for (iter = context->parts; iter; iter = g_slist_next (iter)) {
104 		EMailPart *part = iter->data;
105 
106 		if (!part)
107 			continue;
108 
109 		if (g_str_has_suffix (part->id, ".headers") &&
110 		   !(qf_context->qf_flags & E_MAIL_FORMATTER_QUOTE_FLAG_HEADERS)) {
111 			continue;
112 		}
113 
114 		if (g_str_has_suffix (part->id, ".rfc822")) {
115 			gchar *end = g_strconcat (part->id, ".end", NULL);
116 
117 			while (iter) {
118 				EMailPart *p = iter->data;
119 				if (!p) {
120 					iter = g_slist_next (iter);
121 					if (!iter) {
122 						break;
123 					}
124 					continue;
125 				}
126 
127 				if (g_strcmp0 (p->id, end) == 0)
128 					break;
129 
130 				iter = g_slist_next (iter);
131 				if (!iter) {
132 					break;
133 				}
134 			}
135 			g_free (end);
136 
137 			continue;
138 		}
139 
140 		if (part->is_hidden || part->is_attachment)
141 			continue;
142 
143 		e_mail_formatter_format_as (
144 			formatter, context, part, stream,
145 			part->mime_type, cancellable);
146 	}
147 
148 	if (qf->priv->flags & E_MAIL_FORMATTER_QUOTE_FLAG_CITE) {
149 		camel_stream_write_string (
150 			stream, "</blockquote><!--+GtkHTML:"
151 			"<DATA class=\"ClueFlow\" clear=\"orig\">-->",
152 			cancellable, NULL);
153 	}
154 }
155 
156 static void
157 e_mail_formatter_quote_init (EMailFormatterQuote *formatter)
158 {
159 	formatter->priv = E_MAIL_FORMATTER_QUOTE_GET_PRIVATE (formatter);
160 }
161 
162 static void
163 e_mail_formatter_quote_finalize (GObject *object)
164 {
165 	/* Chain up to parent's finalize() */
166 	G_OBJECT_CLASS (e_mail_formatter_quote_parent_class)->finalize (object);
167 }
168 
169 static void
170 e_mail_formatter_quote_base_init (EMailFormatterQuoteClass *class)
171 {
172 	e_mail_formatter_quote_internal_extensions_load (
173 		E_MAIL_EXTENSION_REGISTRY (
174 			E_MAIL_FORMATTER_CLASS (class)->extension_registry));
175 
176 	E_MAIL_FORMATTER_CLASS (class)->text_html_flags =
177 		CAMEL_MIME_FILTER_TOHTML_PRE |
178 		CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS |
179 		CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES;
180 }
181 
182 static void
183 e_mail_formatter_quote_class_init (EMailFormatterQuoteClass *class)
184 {
185 	GObjectClass *object_class;
186 	EMailFormatterClass *formatter_class;
187 
188 	e_mail_formatter_quote_parent_class = g_type_class_peek_parent (class);
189 	g_type_class_add_private (class, sizeof (EMailFormatterQuotePrivate));
190 
191 	formatter_class = E_MAIL_FORMATTER_CLASS (class);
192 	formatter_class->run = mail_formatter_quote_run;
193 	formatter_class->create_context = mail_formatter_quote_create_context;
194 	formatter_class->free_context = mail_formatter_quote_free_context;
195 
196 	object_class = G_OBJECT_CLASS (class);
197 	object_class->finalize = e_mail_formatter_quote_finalize;
198 }
199 
200 GType
201 e_mail_formatter_quote_get_type (void)
202 {
203 	static GType type = 0;
204 
205 	if (G_UNLIKELY (type == 0)) {
206 		const GTypeInfo type_info = {
207 			sizeof (EMailFormatterClass),
208 			(GBaseInitFunc) e_mail_formatter_quote_base_init,
209 			(GBaseFinalizeFunc) NULL,
210 			(GClassInitFunc) e_mail_formatter_quote_class_init,
211 			(GClassFinalizeFunc) NULL,
212 			NULL,	/* class_data */
213 			sizeof (EMailFormatterQuote),
214 			0,	/* n_preallocs */
215 			(GInstanceInitFunc) e_mail_formatter_quote_init,
216 			NULL	/* value_table */
217 		};
218 
219 		type = g_type_register_static (
220 			E_TYPE_MAIL_FORMATTER,
221 			"EMailFormatterQuote", &type_info, 0);
222 	}
223 
224 	return type;
225 }
226 
227 EMailFormatter *
228 e_mail_formatter_quote_new (const gchar *credits,
229                             EMailFormatterQuoteFlags flags)
230 {
231 	EMailFormatterQuote *formatter;
232 	formatter = g_object_new (E_TYPE_MAIL_FORMATTER_QUOTE, NULL);
233 
234 	formatter->priv->credits = g_strdup (credits);
235 	formatter->priv->flags = flags;
236 
237 	return (EMailFormatter *) formatter;
238 }