|
Packit |
15f964 |
/*
|
|
Packit |
15f964 |
* e-mail-parser-inlinepgp-signed.c
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* This program is free software; you can redistribute it and/or modify it
|
|
Packit |
15f964 |
* under the terms of the GNU Lesser General Public License as published by
|
|
Packit |
15f964 |
* the Free Software Foundation.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* This program is distributed in the hope that it will be useful, but
|
|
Packit |
15f964 |
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
Packit |
15f964 |
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
Packit |
15f964 |
* for more details.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* You should have received a copy of the GNU Lesser General Public License
|
|
Packit |
15f964 |
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
*/
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
#include "evolution-config.h"
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
#include <string.h>
|
|
Packit |
15f964 |
#include <glib/gi18n-lib.h>
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
#include <e-util/e-util.h>
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
#include "e-mail-parser-extension.h"
|
|
Packit |
15f964 |
#include "e-mail-part-utils.h"
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
typedef EMailParserExtension EMailParserInlinePGPSigned;
|
|
Packit |
15f964 |
typedef EMailParserExtensionClass EMailParserInlinePGPSignedClass;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
GType e_mail_parser_inline_pgp_signed_get_type (void);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
G_DEFINE_TYPE (
|
|
Packit |
15f964 |
EMailParserInlinePGPSigned,
|
|
Packit |
15f964 |
e_mail_parser_inline_pgp_signed,
|
|
Packit |
15f964 |
E_TYPE_MAIL_PARSER_EXTENSION)
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static const gchar *parser_mime_types[] = {
|
|
Packit |
15f964 |
"application/x-inlinepgp-signed",
|
|
Packit |
15f964 |
NULL
|
|
Packit |
15f964 |
};
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static gboolean
|
|
Packit |
15f964 |
empe_inlinepgp_signed_parse (EMailParserExtension *extension,
|
|
Packit |
15f964 |
EMailParser *parser,
|
|
Packit |
15f964 |
CamelMimePart *part,
|
|
Packit |
15f964 |
GString *part_id,
|
|
Packit |
15f964 |
GCancellable *cancellable,
|
|
Packit |
15f964 |
GQueue *out_mail_parts)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
CamelStream *filtered_stream;
|
|
Packit |
15f964 |
CamelMimeFilterPgp *pgp_filter;
|
|
Packit |
15f964 |
CamelContentType *content_type;
|
|
Packit |
15f964 |
CamelCipherContext *cipher;
|
|
Packit |
15f964 |
CamelCipherValidity *valid;
|
|
Packit |
15f964 |
CamelDataWrapper *dw;
|
|
Packit |
15f964 |
CamelMimePart *opart;
|
|
Packit |
15f964 |
CamelStream *ostream;
|
|
Packit |
15f964 |
GQueue work_queue = G_QUEUE_INIT;
|
|
Packit |
15f964 |
GList *head, *link;
|
|
Packit |
15f964 |
gchar *type;
|
|
Packit |
15f964 |
gint len;
|
|
Packit |
15f964 |
GError *local_error = NULL;
|
|
Packit |
15f964 |
GByteArray *ba;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if (g_cancellable_is_cancelled (cancellable))
|
|
Packit |
15f964 |
return FALSE;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
cipher = camel_gpg_context_new (e_mail_parser_get_session (parser));
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/* Verify the signature of the message */
|
|
Packit |
15f964 |
valid = camel_cipher_context_verify_sync (
|
|
Packit |
15f964 |
cipher, part, cancellable, &local_error);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if (local_error != NULL) {
|
|
Packit |
15f964 |
e_mail_parser_error (
|
|
Packit |
15f964 |
parser, out_mail_parts,
|
|
Packit |
15f964 |
_("Error verifying signature: %s"),
|
|
Packit |
15f964 |
local_error->message);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_error_free (local_error);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
e_mail_parser_parse_part_as (
|
|
Packit |
15f964 |
parser, part, part_id,
|
|
Packit |
15f964 |
"application/vnd.evolution.source",
|
|
Packit |
15f964 |
cancellable, out_mail_parts);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_object_unref (cipher);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
return TRUE;
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/* Setup output stream */
|
|
Packit |
15f964 |
ostream = camel_stream_mem_new ();
|
|
Packit |
15f964 |
filtered_stream = camel_stream_filter_new (ostream);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/* Add PGP header / footer filter */
|
|
Packit |
15f964 |
pgp_filter = (CamelMimeFilterPgp *) camel_mime_filter_pgp_new ();
|
|
Packit |
15f964 |
camel_stream_filter_add (
|
|
Packit |
15f964 |
CAMEL_STREAM_FILTER (filtered_stream),
|
|
Packit |
15f964 |
CAMEL_MIME_FILTER (pgp_filter));
|
|
Packit |
15f964 |
g_object_unref (pgp_filter);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/* Pass through the filters that have been setup */
|
|
Packit |
15f964 |
dw = camel_medium_get_content ((CamelMedium *) part);
|
|
Packit |
15f964 |
camel_data_wrapper_decode_to_stream_sync (
|
|
Packit |
15f964 |
dw, (CamelStream *) filtered_stream, cancellable, NULL);
|
|
Packit |
15f964 |
camel_stream_flush ((CamelStream *) filtered_stream, cancellable, NULL);
|
|
Packit |
15f964 |
g_object_unref (filtered_stream);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/* Create a new text/plain MIME part containing the signed
|
|
Packit |
15f964 |
* content preserving the original part's Content-Type params. */
|
|
Packit |
15f964 |
content_type = camel_mime_part_get_content_type (part);
|
|
Packit |
15f964 |
type = camel_content_type_format (content_type);
|
|
Packit |
15f964 |
content_type = camel_content_type_decode (type);
|
|
Packit |
15f964 |
g_free (type);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_free (content_type->type);
|
|
Packit |
15f964 |
content_type->type = g_strdup ("text");
|
|
Packit |
15f964 |
g_free (content_type->subtype);
|
|
Packit |
15f964 |
content_type->subtype = g_strdup ("plain");
|
|
Packit |
15f964 |
type = camel_content_type_format (content_type);
|
|
Packit |
15f964 |
camel_content_type_unref (content_type);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
ba = camel_stream_mem_get_byte_array ((CamelStreamMem *) ostream);
|
|
Packit |
15f964 |
opart = camel_mime_part_new ();
|
|
Packit |
15f964 |
camel_mime_part_set_content (opart, (gchar *) ba->data, ba->len, type);
|
|
Packit |
15f964 |
g_free (type);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
len = part_id->len;
|
|
Packit |
15f964 |
g_string_append (part_id, ".inlinepgp_signed");
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_warn_if_fail (e_mail_parser_parse_part (
|
|
Packit |
15f964 |
parser, opart, part_id, cancellable, &work_queue));
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
head = g_queue_peek_head_link (&work_queue);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
for (link = head; link != NULL; link = g_list_next (link)) {
|
|
Packit |
15f964 |
EMailPart *mail_part = link->data;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
e_mail_part_update_validity (
|
|
Packit |
15f964 |
mail_part, valid,
|
|
Packit |
15f964 |
E_MAIL_PART_VALIDITY_SIGNED |
|
|
Packit |
15f964 |
E_MAIL_PART_VALIDITY_PGP);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
e_queue_transfer (&work_queue, out_mail_parts);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_string_truncate (part_id, len);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/* Add a widget with details about the encryption, but only when
|
|
Packit |
15f964 |
* the encrypted isn't itself secured, in that case it has created
|
|
Packit |
15f964 |
* the button itself */
|
|
Packit |
15f964 |
if (!e_mail_part_is_secured (opart)) {
|
|
Packit |
15f964 |
EMailPart *mail_part;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_string_append (part_id, ".inlinepgp_signed.button");
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
e_mail_parser_parse_part_as (
|
|
Packit |
15f964 |
parser, part, part_id,
|
|
Packit |
15f964 |
"application/vnd.evolution.secure-button",
|
|
Packit |
15f964 |
cancellable, &work_queue);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
mail_part = g_queue_peek_head (&work_queue);
|
|
Packit |
15f964 |
if (mail_part != NULL)
|
|
Packit |
15f964 |
e_mail_part_update_validity (
|
|
Packit |
15f964 |
mail_part, valid,
|
|
Packit |
15f964 |
E_MAIL_PART_VALIDITY_SIGNED |
|
|
Packit |
15f964 |
E_MAIL_PART_VALIDITY_PGP);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
e_queue_transfer (&work_queue, out_mail_parts);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_string_truncate (part_id, len);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/* Clean Up */
|
|
Packit |
15f964 |
camel_cipher_validity_free (valid);
|
|
Packit |
15f964 |
g_object_unref (opart);
|
|
Packit |
15f964 |
g_object_unref (ostream);
|
|
Packit |
15f964 |
g_object_unref (cipher);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
return TRUE;
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static void
|
|
Packit |
15f964 |
e_mail_parser_inline_pgp_signed_class_init (EMailParserExtensionClass *class)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
class->mime_types = parser_mime_types;
|
|
Packit |
15f964 |
class->priority = G_PRIORITY_LOW;
|
|
Packit |
15f964 |
class->parse = empe_inlinepgp_signed_parse;
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static void
|
|
Packit |
15f964 |
e_mail_parser_inline_pgp_signed_init (EMailParserExtension *extension)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
}
|