2003-12-30 09:59:02 +01:00
|
|
|
/*
|
|
|
|
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
|
2012-05-27 19:31:10 +02:00
|
|
|
* Copyright (C) 1999-2012 Hiroyuki Yamamoto & the Claws Mail team
|
2003-12-30 09:59:02 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-07-11 18:38:12 +02:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-12-30 09:59:02 +01:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-07-11 18:38:12 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
2003-12-30 09:59:02 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <glib.h>
|
2005-02-10 13:06:07 +01:00
|
|
|
#include <glib/gi18n.h>
|
2003-12-30 09:59:02 +01:00
|
|
|
|
|
|
|
#include "privacy.h"
|
|
|
|
#include "procmime.h"
|
2012-09-08 22:23:12 +02:00
|
|
|
#include "procmsg.h"
|
2003-12-30 09:59:02 +01:00
|
|
|
|
|
|
|
static GSList *systems = NULL;
|
2006-06-15 19:03:17 +02:00
|
|
|
static gchar *privacy_last_error = NULL;
|
|
|
|
|
|
|
|
void privacy_set_error(const gchar *format, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
gchar buf[BUFSIZ];
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
g_vsnprintf(buf, BUFSIZ, format, args);
|
|
|
|
va_end(args);
|
|
|
|
g_free(privacy_last_error);
|
|
|
|
privacy_last_error = g_strdup(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar tmp_privacy_error[BUFSIZ];
|
|
|
|
|
2006-07-03 14:35:59 +02:00
|
|
|
void privacy_reset_error(void)
|
|
|
|
{
|
|
|
|
g_free(privacy_last_error);
|
|
|
|
privacy_last_error = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean privacy_peek_error(void)
|
|
|
|
{
|
|
|
|
return (privacy_last_error != NULL);
|
|
|
|
}
|
|
|
|
|
2006-06-15 19:03:17 +02:00
|
|
|
const gchar *privacy_get_error (void)
|
|
|
|
{
|
|
|
|
if (privacy_last_error) {
|
|
|
|
strncpy2(tmp_privacy_error, privacy_last_error, BUFSIZ-1);
|
2006-07-03 14:35:59 +02:00
|
|
|
privacy_reset_error();
|
2006-06-15 19:03:17 +02:00
|
|
|
return tmp_privacy_error;
|
|
|
|
} else {
|
|
|
|
return _("Unknown error");
|
|
|
|
}
|
|
|
|
}
|
2003-12-30 09:59:02 +01:00
|
|
|
|
2007-01-20 20:54:05 +01:00
|
|
|
static PrivacySystem *privacy_data_get_system(PrivacyData *data)
|
2005-07-17 13:40:07 +02:00
|
|
|
{
|
|
|
|
/* Make sure the cached system is still registered */
|
|
|
|
if (data->system && g_slist_find(systems, data->system))
|
|
|
|
return data->system;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
2003-12-30 09:59:02 +01:00
|
|
|
/**
|
|
|
|
* Register a new Privacy System
|
|
|
|
*
|
|
|
|
* \param system The Privacy System that should be registered
|
|
|
|
*/
|
|
|
|
void privacy_register_system(PrivacySystem *system)
|
|
|
|
{
|
|
|
|
systems = g_slist_append(systems, system);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unregister a new Privacy System. The system must not be in
|
|
|
|
* use anymore when it is unregistered.
|
|
|
|
*
|
|
|
|
* \param system The Privacy System that should be unregistered
|
|
|
|
*/
|
|
|
|
void privacy_unregister_system(PrivacySystem *system)
|
|
|
|
{
|
|
|
|
systems = g_slist_remove(systems, system);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free a PrivacyData of a PrivacySystem
|
|
|
|
*
|
|
|
|
* \param privacydata The data to free
|
|
|
|
*/
|
|
|
|
void privacy_free_privacydata(PrivacyData *privacydata)
|
|
|
|
{
|
2005-07-17 13:40:07 +02:00
|
|
|
PrivacySystem *system = NULL;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_if_fail(privacydata != NULL);
|
2003-12-30 09:59:02 +01:00
|
|
|
|
2005-07-17 13:40:07 +02:00
|
|
|
system = privacy_data_get_system(privacydata);
|
|
|
|
if (!system)
|
|
|
|
return;
|
|
|
|
system->free_privacydata(privacydata);
|
2003-12-30 09:59:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a MimeInfo is signed with one of the available
|
|
|
|
* privacy system. If a privacydata is set in the MimeInfo
|
|
|
|
* it will directory return the return value by the system
|
|
|
|
* set in the privacy data or check all available privacy
|
|
|
|
* systems otherwise.
|
|
|
|
*
|
|
|
|
* \return True if the MimeInfo has a signature
|
|
|
|
*/
|
|
|
|
gboolean privacy_mimeinfo_is_signed(MimeInfo *mimeinfo)
|
|
|
|
{
|
|
|
|
GSList *cur;
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(mimeinfo != NULL, FALSE);
|
2003-12-30 09:59:02 +01:00
|
|
|
|
|
|
|
if (mimeinfo->privacy != NULL) {
|
2005-07-17 13:40:07 +02:00
|
|
|
PrivacySystem *system =
|
|
|
|
privacy_data_get_system(mimeinfo->privacy);
|
|
|
|
|
|
|
|
if (system == NULL) {
|
|
|
|
mimeinfo->privacy = NULL;
|
|
|
|
goto try_others;
|
|
|
|
}
|
2003-12-30 09:59:02 +01:00
|
|
|
|
|
|
|
if (system->is_signed != NULL)
|
|
|
|
return system->is_signed(mimeinfo);
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-07-17 13:40:07 +02:00
|
|
|
try_others:
|
2003-12-30 09:59:02 +01:00
|
|
|
for(cur = systems; cur != NULL; cur = g_slist_next(cur)) {
|
|
|
|
PrivacySystem *system = (PrivacySystem *) cur->data;
|
|
|
|
|
|
|
|
if(system->is_signed != NULL && system->is_signed(mimeinfo))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-01-22 19:06:02 +01:00
|
|
|
struct SignedState {
|
|
|
|
MsgInfo *msginfo;
|
|
|
|
gchar **system;
|
|
|
|
};
|
|
|
|
|
2008-08-28 15:09:09 +02:00
|
|
|
static void msginfo_set_signed_flag(GNode *node, gpointer data)
|
|
|
|
{
|
2009-01-22 19:06:02 +01:00
|
|
|
struct SignedState *sstate = (struct SignedState *)data;
|
|
|
|
MsgInfo *msginfo = sstate->msginfo;
|
2008-08-28 15:09:09 +02:00
|
|
|
MimeInfo *mimeinfo = node->data;
|
|
|
|
|
|
|
|
if (privacy_mimeinfo_is_signed(mimeinfo)) {
|
|
|
|
procmsg_msginfo_set_flags(msginfo, 0, MSG_SIGNED);
|
2009-01-22 19:06:02 +01:00
|
|
|
if (sstate->system && !*(sstate->system) && mimeinfo->privacy)
|
|
|
|
*(sstate->system) = g_strdup(mimeinfo->privacy->system->id);
|
2008-08-28 15:09:09 +02:00
|
|
|
}
|
|
|
|
if (privacy_mimeinfo_is_encrypted(mimeinfo)) {
|
|
|
|
procmsg_msginfo_set_flags(msginfo, 0, MSG_ENCRYPTED);
|
2009-01-22 19:06:02 +01:00
|
|
|
if (sstate->system && !*(sstate->system) && mimeinfo->privacy)
|
|
|
|
*(sstate->system) = g_strdup(mimeinfo->privacy->system->id);
|
2008-08-28 15:09:09 +02:00
|
|
|
} else {
|
|
|
|
/* searching inside encrypted parts doesn't really make sense */
|
2009-01-22 19:06:02 +01:00
|
|
|
g_node_children_foreach(mimeinfo->node, G_TRAVERSE_ALL, msginfo_set_signed_flag, sstate);
|
2008-08-28 15:09:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-22 19:06:02 +01:00
|
|
|
void privacy_msginfo_get_signed_state(MsgInfo *msginfo, gchar **system)
|
2008-08-28 15:09:09 +02:00
|
|
|
{
|
2009-01-22 19:06:02 +01:00
|
|
|
struct SignedState sstate;
|
2008-08-28 15:09:09 +02:00
|
|
|
MimeInfo *mimeinfo = procmime_scan_message(msginfo);
|
2009-02-22 19:47:11 +01:00
|
|
|
if (!mimeinfo)
|
|
|
|
return;
|
2009-01-22 19:06:02 +01:00
|
|
|
sstate.msginfo = msginfo;
|
|
|
|
sstate.system = system;
|
|
|
|
g_node_children_foreach(mimeinfo->node, G_TRAVERSE_ALL, msginfo_set_signed_flag, &sstate);
|
2008-08-28 15:09:09 +02:00
|
|
|
}
|
|
|
|
|
2003-12-30 09:59:02 +01:00
|
|
|
/**
|
|
|
|
* Check the signature of a MimeInfo. privacy_mimeinfo_is_signed
|
|
|
|
* should be called before otherwise it is done by this function.
|
|
|
|
* If the MimeInfo is not signed an error code will be returned.
|
|
|
|
*
|
|
|
|
* \return Error code indicating the result of the check,
|
2016-05-01 16:56:18 +02:00
|
|
|
* < 0 if an error occurred
|
2003-12-30 09:59:02 +01:00
|
|
|
*/
|
|
|
|
gint privacy_mimeinfo_check_signature(MimeInfo *mimeinfo)
|
|
|
|
{
|
|
|
|
PrivacySystem *system;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(mimeinfo != NULL, -1);
|
2003-12-30 09:59:02 +01:00
|
|
|
|
|
|
|
if (mimeinfo->privacy == NULL)
|
|
|
|
privacy_mimeinfo_is_signed(mimeinfo);
|
|
|
|
|
|
|
|
if (mimeinfo->privacy == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2005-07-17 13:40:07 +02:00
|
|
|
system = privacy_data_get_system(mimeinfo->privacy);
|
|
|
|
if (system == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2003-12-30 09:59:02 +01:00
|
|
|
if (system->check_signature == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return system->check_signature(mimeinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
SignatureStatus privacy_mimeinfo_get_sig_status(MimeInfo *mimeinfo)
|
|
|
|
{
|
|
|
|
PrivacySystem *system;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(mimeinfo != NULL, -1);
|
2003-12-30 09:59:02 +01:00
|
|
|
|
|
|
|
if (mimeinfo->privacy == NULL)
|
|
|
|
privacy_mimeinfo_is_signed(mimeinfo);
|
|
|
|
|
|
|
|
if (mimeinfo->privacy == NULL)
|
|
|
|
return SIGNATURE_UNCHECKED;
|
|
|
|
|
2005-07-17 13:40:07 +02:00
|
|
|
system = privacy_data_get_system(mimeinfo->privacy);
|
|
|
|
if (system == NULL)
|
|
|
|
return SIGNATURE_UNCHECKED;
|
2003-12-30 09:59:02 +01:00
|
|
|
if (system->get_sig_status == NULL)
|
|
|
|
return SIGNATURE_UNCHECKED;
|
|
|
|
|
|
|
|
return system->get_sig_status(mimeinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
gchar *privacy_mimeinfo_sig_info_short(MimeInfo *mimeinfo)
|
|
|
|
{
|
|
|
|
PrivacySystem *system;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(mimeinfo != NULL, NULL);
|
2003-12-30 09:59:02 +01:00
|
|
|
|
|
|
|
if (mimeinfo->privacy == NULL)
|
|
|
|
privacy_mimeinfo_is_signed(mimeinfo);
|
|
|
|
|
|
|
|
if (mimeinfo->privacy == NULL)
|
|
|
|
return g_strdup(_("No signature found"));
|
|
|
|
|
2005-07-17 13:40:07 +02:00
|
|
|
system = privacy_data_get_system(mimeinfo->privacy);
|
|
|
|
if (system == NULL)
|
|
|
|
return g_strdup(_("No signature found"));
|
2003-12-30 09:59:02 +01:00
|
|
|
if (system->get_sig_info_short == NULL)
|
|
|
|
return g_strdup(_("No information available"));
|
|
|
|
|
|
|
|
return system->get_sig_info_short(mimeinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
gchar *privacy_mimeinfo_sig_info_full(MimeInfo *mimeinfo)
|
|
|
|
{
|
|
|
|
PrivacySystem *system;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(mimeinfo != NULL, NULL);
|
2003-12-30 09:59:02 +01:00
|
|
|
|
|
|
|
if (mimeinfo->privacy == NULL)
|
|
|
|
privacy_mimeinfo_is_signed(mimeinfo);
|
|
|
|
|
|
|
|
if (mimeinfo->privacy == NULL)
|
|
|
|
return g_strdup(_("No signature found"));
|
|
|
|
|
2005-07-17 13:40:07 +02:00
|
|
|
system = privacy_data_get_system(mimeinfo->privacy);
|
|
|
|
if (system == NULL)
|
|
|
|
return g_strdup(_("No signature found"));
|
2003-12-30 09:59:02 +01:00
|
|
|
if (system->get_sig_info_full == NULL)
|
|
|
|
return g_strdup(_("No information available"));
|
|
|
|
|
|
|
|
return system->get_sig_info_full(mimeinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean privacy_mimeinfo_is_encrypted(MimeInfo *mimeinfo)
|
|
|
|
{
|
|
|
|
GSList *cur;
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(mimeinfo != NULL, FALSE);
|
2003-12-30 09:59:02 +01:00
|
|
|
|
|
|
|
for(cur = systems; cur != NULL; cur = g_slist_next(cur)) {
|
|
|
|
PrivacySystem *system = (PrivacySystem *) cur->data;
|
|
|
|
|
|
|
|
if(system->is_encrypted != NULL && system->is_encrypted(mimeinfo))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint decrypt(MimeInfo *mimeinfo, PrivacySystem *system)
|
|
|
|
{
|
|
|
|
MimeInfo *decryptedinfo, *parentinfo;
|
|
|
|
gint childnumber;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(system->decrypt != NULL, -1);
|
2003-12-30 09:59:02 +01:00
|
|
|
|
|
|
|
decryptedinfo = system->decrypt(mimeinfo);
|
|
|
|
if (decryptedinfo == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
parentinfo = procmime_mimeinfo_parent(mimeinfo);
|
|
|
|
childnumber = g_node_child_index(parentinfo->node, mimeinfo);
|
|
|
|
|
2016-02-08 18:26:49 +01:00
|
|
|
procmime_mimeinfo_free_all(&mimeinfo);
|
2003-12-30 09:59:02 +01:00
|
|
|
|
|
|
|
g_node_insert(parentinfo->node, childnumber, decryptedinfo->node);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
gint privacy_mimeinfo_decrypt(MimeInfo *mimeinfo)
|
|
|
|
{
|
|
|
|
GSList *cur;
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(mimeinfo != NULL, FALSE);
|
2003-12-30 09:59:02 +01:00
|
|
|
|
2010-02-03 14:11:58 +01:00
|
|
|
procmime_decode_content(mimeinfo);
|
|
|
|
|
2003-12-30 09:59:02 +01:00
|
|
|
for(cur = systems; cur != NULL; cur = g_slist_next(cur)) {
|
|
|
|
PrivacySystem *system = (PrivacySystem *) cur->data;
|
|
|
|
|
|
|
|
if(system->is_encrypted != NULL && system->is_encrypted(mimeinfo))
|
|
|
|
return decrypt(mimeinfo, system);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2004-10-12 11:45:18 +02:00
|
|
|
|
|
|
|
GSList *privacy_get_system_ids()
|
|
|
|
{
|
|
|
|
GSList *cur;
|
|
|
|
GSList *ret = NULL;
|
|
|
|
|
|
|
|
for(cur = systems; cur != NULL; cur = g_slist_next(cur)) {
|
|
|
|
PrivacySystem *system = (PrivacySystem *) cur->data;
|
|
|
|
|
|
|
|
ret = g_slist_append(ret, g_strdup(system->id));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PrivacySystem *privacy_get_system(const gchar *id)
|
|
|
|
{
|
|
|
|
GSList *cur;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(id != NULL, NULL);
|
2004-10-12 11:45:18 +02:00
|
|
|
|
|
|
|
for(cur = systems; cur != NULL; cur = g_slist_next(cur)) {
|
|
|
|
PrivacySystem *system = (PrivacySystem *) cur->data;
|
|
|
|
|
|
|
|
if(strcmp(id, system->id) == 0)
|
|
|
|
return system;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *privacy_system_get_name(const gchar *id)
|
|
|
|
{
|
|
|
|
PrivacySystem *system;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(id != NULL, NULL);
|
2004-10-12 11:45:18 +02:00
|
|
|
|
|
|
|
system = privacy_get_system(id);
|
|
|
|
if (system == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return system->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean privacy_system_can_sign(const gchar *id)
|
|
|
|
{
|
|
|
|
PrivacySystem *system;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(id != NULL, FALSE);
|
2004-10-12 11:45:18 +02:00
|
|
|
|
|
|
|
system = privacy_get_system(id);
|
|
|
|
if (system == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return system->can_sign;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean privacy_system_can_encrypt(const gchar *id)
|
|
|
|
{
|
|
|
|
PrivacySystem *system;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(id != NULL, FALSE);
|
2004-10-12 11:45:18 +02:00
|
|
|
|
|
|
|
system = privacy_get_system(id);
|
|
|
|
if (system == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return system->can_encrypt;
|
|
|
|
}
|
|
|
|
|
2008-12-15 17:46:27 +01:00
|
|
|
gboolean privacy_sign(const gchar *id, MimeInfo *target, PrefsAccount *account, const gchar *from_addr)
|
2004-10-12 11:45:18 +02:00
|
|
|
{
|
|
|
|
PrivacySystem *system;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(id != NULL, FALSE);
|
|
|
|
cm_return_val_if_fail(target != NULL, FALSE);
|
2004-10-12 11:45:18 +02:00
|
|
|
|
|
|
|
system = privacy_get_system(id);
|
|
|
|
if (system == NULL)
|
|
|
|
return FALSE;
|
|
|
|
if (!system->can_sign)
|
|
|
|
return FALSE;
|
|
|
|
if (system->sign == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2008-12-15 17:46:27 +01:00
|
|
|
return system->sign(target, account, from_addr);
|
2004-10-12 11:45:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gchar *privacy_get_encrypt_data(const gchar *id, GSList *recp_names)
|
|
|
|
{
|
|
|
|
PrivacySystem *system;
|
2009-02-15 19:49:01 +01:00
|
|
|
gchar *ret = NULL;
|
|
|
|
GSList *uniq_names = NULL, *cur;
|
2004-10-12 11:45:18 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(id != NULL, NULL);
|
|
|
|
cm_return_val_if_fail(recp_names != NULL, NULL);
|
2004-10-12 11:45:18 +02:00
|
|
|
|
|
|
|
system = privacy_get_system(id);
|
|
|
|
if (system == NULL)
|
2004-11-17 14:48:31 +01:00
|
|
|
return NULL;
|
2004-10-12 11:45:18 +02:00
|
|
|
if (!system->can_encrypt)
|
2004-11-17 14:48:31 +01:00
|
|
|
return NULL;
|
2004-10-12 11:45:18 +02:00
|
|
|
if (system->get_encrypt_data == NULL)
|
2004-11-17 14:48:31 +01:00
|
|
|
return NULL;
|
2004-10-12 11:45:18 +02:00
|
|
|
|
2009-02-15 19:49:01 +01:00
|
|
|
for (cur = recp_names; cur; cur = cur->next) {
|
|
|
|
if (!g_slist_find_custom(uniq_names, cur->data, (GCompareFunc)strcmp)) {
|
|
|
|
uniq_names = g_slist_prepend(uniq_names, cur->data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret = system->get_encrypt_data(uniq_names);
|
|
|
|
|
|
|
|
g_slist_free(uniq_names);
|
|
|
|
return ret;
|
2004-10-12 11:45:18 +02:00
|
|
|
}
|
|
|
|
|
2007-05-04 19:16:35 +02:00
|
|
|
const gchar *privacy_get_encrypt_warning(const gchar *id)
|
|
|
|
{
|
|
|
|
PrivacySystem *system;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(id != NULL, NULL);
|
2007-05-04 19:16:35 +02:00
|
|
|
|
|
|
|
system = privacy_get_system(id);
|
|
|
|
if (system == NULL)
|
|
|
|
return NULL;
|
|
|
|
if (!system->can_encrypt)
|
|
|
|
return NULL;
|
|
|
|
if (system->get_encrypt_warning == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return system->get_encrypt_warning();
|
|
|
|
}
|
|
|
|
|
|
|
|
void privacy_inhibit_encrypt_warning(const gchar *id, gboolean inhibit)
|
|
|
|
{
|
|
|
|
PrivacySystem *system;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_if_fail(id != NULL);
|
2007-05-04 19:16:35 +02:00
|
|
|
|
|
|
|
system = privacy_get_system(id);
|
|
|
|
if (system == NULL)
|
|
|
|
return;
|
|
|
|
if (!system->can_encrypt)
|
|
|
|
return;
|
|
|
|
if (system->inhibit_encrypt_warning == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
system->inhibit_encrypt_warning(inhibit);
|
|
|
|
}
|
|
|
|
|
2004-10-12 11:45:18 +02:00
|
|
|
gboolean privacy_encrypt(const gchar *id, MimeInfo *mimeinfo, const gchar *encdata)
|
|
|
|
{
|
|
|
|
PrivacySystem *system;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(id != NULL, FALSE);
|
|
|
|
cm_return_val_if_fail(mimeinfo != NULL, FALSE);
|
2006-06-15 19:03:17 +02:00
|
|
|
if (encdata == NULL) {
|
|
|
|
privacy_set_error(_("No recipient keys defined."));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-10-12 11:45:18 +02:00
|
|
|
|
|
|
|
system = privacy_get_system(id);
|
|
|
|
if (system == NULL)
|
|
|
|
return FALSE;
|
|
|
|
if (!system->can_encrypt)
|
|
|
|
return FALSE;
|
|
|
|
if (system->encrypt == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return system->encrypt(mimeinfo, encdata);
|
|
|
|
}
|
2013-07-25 13:26:24 +02:00
|
|
|
|
|
|
|
gboolean privacy_auto_check_signatures(MimeInfo *mimeinfo)
|
|
|
|
{
|
|
|
|
PrivacySystem *system;
|
|
|
|
|
|
|
|
cm_return_val_if_fail(mimeinfo != NULL, FALSE);
|
|
|
|
|
|
|
|
if (mimeinfo->privacy == NULL)
|
|
|
|
privacy_mimeinfo_is_signed(mimeinfo);
|
|
|
|
|
|
|
|
if (mimeinfo->privacy == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
system = privacy_data_get_system(mimeinfo->privacy);
|
|
|
|
if (system == NULL)
|
|
|
|
return FALSE;
|
|
|
|
if (system->auto_check_signatures == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return system->auto_check_signatures();
|
|
|
|
}
|