0.9.6claws32
[claws.git] / src / sgpgme.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2003 Hiroyuki Yamamoto & the Sylpheed-Claws team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19  
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23  
24 #ifdef USE_GPGME
25
26 #include <gtk/gtk.h>
27 #include <gpgme.h>
28
29 #include "sgpgme.h"
30 #include "privacy.h"
31 #include "prefs_common.h"
32 #include "utils.h"
33 #include "alertpanel.h"
34 #include "passphrase.h"
35 #include "intl.h"
36
37 static void idle_function_for_gpgme(void)
38 {
39         while (gtk_events_pending())
40                 gtk_main_iteration();
41 }
42
43 static void sgpgme_disable_all(void)
44 {
45     /* FIXME: set a flag, so that we don't bother the user with failed
46      * gpgme messages */
47 }
48
49 GpgmeSigStat sgpgme_verify_signature(GpgmeCtx ctx, GpgmeData sig, 
50                                         GpgmeData plain)
51 {
52         GpgmeSigStat status;
53
54         if (gpgme_op_verify(ctx, sig, plain, &status) != GPGME_No_Error)
55                 return GPGME_SIG_STAT_ERROR;
56
57         return status;
58 }
59
60 SignatureStatus sgpgme_sigstat_gpgme_to_privacy(GpgmeSigStat status)
61 {
62         switch (status) {
63         case GPGME_SIG_STAT_GOOD:
64                 return SIGNATURE_OK;
65         case GPGME_SIG_STAT_GOOD_EXP:
66         case GPGME_SIG_STAT_GOOD_EXPKEY:
67         case GPGME_SIG_STAT_DIFF:
68                 return SIGNATURE_WARN;
69         case GPGME_SIG_STAT_BAD:
70                 return SIGNATURE_INVALID;
71         case GPGME_SIG_STAT_NOKEY:
72         case GPGME_SIG_STAT_NOSIG:
73         case GPGME_SIG_STAT_ERROR:
74                 return SIGNATURE_CHECK_FAILED;
75         case GPGME_SIG_STAT_NONE:
76                 return SIGNATURE_UNCHECKED;
77         }
78         return SIGNATURE_CHECK_FAILED;
79 }
80
81 void sgpgme_init()
82 {
83         if (gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP) != 
84                         GPGME_No_Error) {  /* Also does some gpgme init */
85                 sgpgme_disable_all();
86                 debug_print("gpgme_engine_version:\n%s\n",
87                             gpgme_get_engine_info());
88
89                 if (prefs_common.gpg_warning) {
90                         AlertValue val;
91
92                         val = alertpanel_message_with_disable
93                                 (_("Warning"),
94                                  _("GnuPG is not installed properly, or needs to be upgraded.\n"
95                                    "OpenPGP support disabled."));
96                         if (val & G_ALERTDISABLE)
97                                 prefs_common.gpg_warning = FALSE;
98                 }
99         }
100
101         gpgme_register_idle(idle_function_for_gpgme);
102 }
103
104 void sgpgme_done()
105 {
106         gpgmegtk_free_passphrase();
107 }
108
109 #endif /* USE_GPGME */