|
Packit |
15f964 |
/*
|
|
Packit |
15f964 |
* e-mail-parser-application-xpkcs7mime.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 EMailParserApplicationSMIME;
|
|
Packit |
15f964 |
typedef EMailParserExtensionClass EMailParserApplicationSMIMEClass;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
GType e_mail_parser_application_smime_get_type (void);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
G_DEFINE_TYPE (
|
|
Packit |
15f964 |
EMailParserApplicationSMIME,
|
|
Packit |
15f964 |
e_mail_parser_application_smime,
|
|
Packit |
15f964 |
E_TYPE_MAIL_PARSER_EXTENSION)
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static const gchar *parser_mime_types[] = {
|
|
Packit |
15f964 |
"application/xpkcs7mime",
|
|
Packit |
15f964 |
"application/x-pkcs7-mime",
|
|
Packit |
15f964 |
"application/pkcs7-mime",
|
|
Packit |
15f964 |
"application/pkcs7-signature",
|
|
Packit |
15f964 |
"application/xpkcs7-signature",
|
|
Packit |
15f964 |
"application/x-pkcs7-signature",
|
|
Packit |
15f964 |
NULL
|
|
Packit |
15f964 |
};
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static gboolean
|
|
Packit |
15f964 |
empe_app_smime_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 |
CamelCipherContext *context;
|
|
Packit |
15f964 |
CamelMimePart *opart;
|
|
Packit |
15f964 |
CamelCipherValidity *valid;
|
|
Packit |
15f964 |
CamelContentType *ct;
|
|
Packit |
15f964 |
GError *local_error = NULL;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
ct = camel_mime_part_get_content_type (part);
|
|
Packit |
15f964 |
if (camel_content_type_is (ct, "application", "pkcs7-signature") ||
|
|
Packit |
15f964 |
camel_content_type_is (ct, "application", "xpkcs7-signature") ||
|
|
Packit |
15f964 |
camel_content_type_is (ct, "application", "x-pkcs7-signature")) {
|
|
Packit |
15f964 |
return TRUE;
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
context = camel_smime_context_new (e_mail_parser_get_session (parser));
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
opart = camel_mime_part_new ();
|
|
Packit |
15f964 |
valid = camel_cipher_context_decrypt_sync (
|
|
Packit |
15f964 |
context, part, opart,
|
|
Packit |
15f964 |
cancellable, &local_error);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
e_mail_part_preserve_charset_in_content_type (part, opart);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if (local_error != NULL) {
|
|
Packit |
15f964 |
e_mail_parser_error (
|
|
Packit |
15f964 |
parser, out_mail_parts,
|
|
Packit |
15f964 |
_("Could not parse S/MIME message: %s"),
|
|
Packit |
15f964 |
local_error->message);
|
|
Packit |
15f964 |
g_error_free (local_error);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
} else {
|
|
Packit |
15f964 |
GQueue work_queue = G_QUEUE_INIT;
|
|
Packit |
15f964 |
GList *head, *link;
|
|
Packit |
15f964 |
gint len = part_id->len;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_string_append (part_id, ".encrypted");
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
e_mail_parser_parse_part (
|
|
Packit |
15f964 |
parser, opart, part_id, cancellable, &work_queue);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_string_truncate (part_id, len);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
head = g_queue_peek_head_link (&work_queue);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/* Update validity flags of all the involved subp-arts */
|
|
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_ENCRYPTED |
|
|
Packit |
15f964 |
E_MAIL_PART_VALIDITY_SMIME);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
e_queue_transfer (&work_queue, out_mail_parts);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/* Add a widget with details about the encryption, but only
|
|
Packit |
15f964 |
* when the encrypted isn't itself secured, in that case it
|
|
Packit |
15f964 |
* has created 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, ".encrypted.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 |
|
|
Packit |
15f964 |
if (mail_part != NULL)
|
|
Packit |
15f964 |
e_mail_part_update_validity (
|
|
Packit |
15f964 |
mail_part, valid,
|
|
Packit |
15f964 |
E_MAIL_PART_VALIDITY_ENCRYPTED |
|
|
Packit |
15f964 |
E_MAIL_PART_VALIDITY_SMIME);
|
|
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 |
camel_cipher_validity_free (valid);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_object_unref (opart);
|
|
Packit |
15f964 |
g_object_unref (context);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
return TRUE;
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static void
|
|
Packit |
15f964 |
e_mail_parser_application_smime_class_init (EMailParserExtensionClass *class)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
class->mime_types = parser_mime_types;
|
|
Packit |
15f964 |
class->priority = G_PRIORITY_LOW;
|
|
Packit |
15f964 |
class->flags = E_MAIL_PARSER_EXTENSION_INLINE;
|
|
Packit |
15f964 |
class->parse = empe_app_smime_parse;
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static void
|
|
Packit |
15f964 |
e_mail_parser_application_smime_init (EMailParserExtension *extension)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
}
|