|
Packit |
15f964 |
/*
|
|
Packit |
15f964 |
* e-mail-parser-inlinepgp-encrypted.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 EMailParserInlinePGPEncrypted;
|
|
Packit |
15f964 |
typedef EMailParserExtensionClass EMailParserInlinePGPEncryptedClass;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
GType e_mail_parser_inline_pgp_encrypted_get_type (void);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
G_DEFINE_TYPE (
|
|
Packit |
15f964 |
EMailParserInlinePGPEncrypted,
|
|
Packit |
15f964 |
e_mail_parser_inline_pgp_encrypted,
|
|
Packit |
15f964 |
E_TYPE_MAIL_PARSER_EXTENSION)
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static const gchar *parser_mime_types[] = {
|
|
Packit |
15f964 |
"application/x-inlinepgp-encrypted",
|
|
Packit |
15f964 |
NULL
|
|
Packit |
15f964 |
};
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static gboolean
|
|
Packit |
15f964 |
empe_inlinepgp_encrypted_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 *cipher;
|
|
Packit |
15f964 |
CamelCipherValidity *valid;
|
|
Packit |
15f964 |
CamelMimePart *opart;
|
|
Packit |
15f964 |
CamelDataWrapper *dw;
|
|
Packit |
15f964 |
gchar *mime_type;
|
|
Packit |
15f964 |
gint len;
|
|
Packit |
15f964 |
GQueue work_queue = G_QUEUE_INIT;
|
|
Packit |
15f964 |
GList *head, *link;
|
|
Packit |
15f964 |
GError *local_error = NULL;
|
|
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 |
opart = camel_mime_part_new ();
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/* Decrypt the message */
|
|
Packit |
15f964 |
valid = camel_cipher_context_decrypt_sync (
|
|
Packit |
15f964 |
cipher, part, opart, 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 |
_("Could not parse PGP message: %s"),
|
|
Packit |
15f964 |
local_error->message);
|
|
Packit |
15f964 |
g_error_free (local_error);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
e_mail_parser_parse_part_as (
|
|
Packit |
15f964 |
parser,
|
|
Packit |
15f964 |
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 |
g_object_unref (opart);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
return TRUE;
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
dw = camel_medium_get_content ((CamelMedium *) opart);
|
|
Packit |
15f964 |
mime_type = camel_data_wrapper_get_mime_type (dw);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/* this ensures to show the 'opart' as inlined, if possible */
|
|
Packit |
15f964 |
if (mime_type && g_ascii_strcasecmp (mime_type, "application/octet-stream") == 0) {
|
|
Packit |
15f964 |
const gchar *snoop;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
snoop = e_mail_part_snoop_type (opart);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if (snoop != NULL) {
|
|
Packit |
15f964 |
camel_data_wrapper_set_mime_type (dw, snoop);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/* Set the MIME type on the 'opart' itself as well.
|
|
Packit |
15f964 |
* If it's "text/plain", then we want the TextPlain
|
|
Packit |
15f964 |
* parser extension to treat it as "text/plain" and
|
|
Packit |
15f964 |
* NOT wrap it as an attachment. */
|
|
Packit |
15f964 |
camel_data_wrapper_set_mime_type (
|
|
Packit |
15f964 |
CAMEL_DATA_WRAPPER (opart), snoop);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
e_mail_part_preserve_charset_in_content_type (part, opart);
|
|
Packit |
15f964 |
g_free (mime_type);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/* Pass it off to the real formatter */
|
|
Packit |
15f964 |
len = part_id->len;
|
|
Packit |
15f964 |
g_string_append (part_id, ".inlinepgp_encrypted");
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
mime_type = camel_data_wrapper_get_mime_type (dw);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_warn_if_fail (e_mail_parser_parse_part_as (
|
|
Packit |
15f964 |
parser, opart, part_id, mime_type,
|
|
Packit |
15f964 |
cancellable, &work_queue));
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_free (mime_type);
|
|
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 |
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_PGP);
|
|
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 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_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 |
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_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 (cipher);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
return TRUE;
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static void
|
|
Packit |
15f964 |
e_mail_parser_inline_pgp_encrypted_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_encrypted_parse;
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static void
|
|
Packit |
15f964 |
e_mail_parser_inline_pgp_encrypted_init (EMailParserExtension *extension)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
}
|