RSSyl: Allow use of .netrc by libcurl. Bug/enhancement #3309, by Vincent Pelletier
[claws.git] / src / plugins / pgpcore / sgpgme.c
index d30ef72301d839c4888597a3145c79403f592104..3de07e2d57df6a1fccbe23aa8c6fbe31af9ee65a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 the Claws Mail team
+ * Copyright (C) 1999-2014 the Claws Mail team
  *
  * 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
@@ -153,6 +153,22 @@ static const gchar *get_validity_str(unsigned long validity)
        }
 }
 
+static const gchar *get_owner_trust_str(unsigned long owner_trust)
+{
+       switch (gpgme_err_code(owner_trust)) {
+       case GPGME_VALIDITY_NEVER:
+               return _("Untrusted");
+       case GPGME_VALIDITY_MARGINAL:
+               return _("Marginal");
+       case GPGME_VALIDITY_FULL:
+               return _("Full");
+       case GPGME_VALIDITY_ULTIMATE:
+               return _("Ultimate");
+       default:
+               return _("Unknown");
+       }
+}
+
 static gchar *extract_name(const char *uid)
 {
        if (uid == NULL)
@@ -209,25 +225,16 @@ gchar *sgpgme_sigstat_info_short(gpgme_ctx_t ctx, gpgme_verify_result_t status)
                uname = g_strdup("<?>");
        switch (gpg_err_code(sig->status)) {
        case GPG_ERR_NO_ERROR:
-               switch (gpg_err_code(sig->validity)) {
-               case GPGME_VALIDITY_FULL:
-               case GPGME_VALIDITY_ULTIMATE:
-                       result = g_strdup_printf(_("Good signature from %s."), uname);
-                       break;
-               case GPGME_VALIDITY_MARGINAL:
-               case GPGME_VALIDITY_UNKNOWN:
-               case GPGME_VALIDITY_UNDEFINED:
-               case GPGME_VALIDITY_NEVER:
-               default:
-                       result = g_strdup_printf(_("Good signature (untrusted) from %s."), uname);
-                       break;
-               }
+               result = g_strdup_printf(_("Good signature from %s."), uname);
                break;
        case GPG_ERR_SIG_EXPIRED:
                result = g_strdup_printf(_("Expired signature from %s."), uname);
                break;
        case GPG_ERR_KEY_EXPIRED:
-               result = g_strdup_printf(_("Expired key from %s."), uname);
+               result = g_strdup_printf(_("Good signature from %s, but the key has expired."), uname);
+               break;
+       case GPG_ERR_CERT_REVOKED:
+               result = g_strdup_printf(_("Good signature from %s, but the key has been revoked."), uname);
                break;
        case GPG_ERR_BAD_SIGNATURE:
                result = g_strdup_printf(_("Bad signature from %s."), uname);
@@ -301,16 +308,25 @@ gchar *sgpgme_sigstat_info_full(gpgme_ctx_t ctx, gpgme_verify_result_t status)
                
                switch (gpg_err_code(sig->status)) {
                case GPG_ERR_NO_ERROR:
-               case GPG_ERR_KEY_EXPIRED:
                        g_string_append_printf(siginfo,
                                _("Good signature from uid \"%s\" (Validity: %s)\n"),
                                uid, get_validity_str(user?user->validity:GPGME_VALIDITY_UNKNOWN));
                        break;
+               case GPG_ERR_KEY_EXPIRED:
+                       g_string_append_printf(siginfo,
+                               _("Expired key uid \"%s\"\n"),
+                               uid);
+                       break;
                case GPG_ERR_SIG_EXPIRED:
                        g_string_append_printf(siginfo,
                                _("Expired signature from uid \"%s\" (Validity: %s)\n"),
                                uid, get_validity_str(user?user->validity:GPGME_VALIDITY_UNKNOWN));
                        break;
+               case GPG_ERR_CERT_REVOKED:
+                       g_string_append_printf(siginfo,
+                               _("Revoked key uid \"%s\"\n"),
+                               uid);
+                       break;
                case GPG_ERR_BAD_SIGNATURE:
                        g_string_append_printf(siginfo,
                                _("BAD signature from \"%s\"\n"),
@@ -326,10 +342,12 @@ gchar *sgpgme_sigstat_info_full(gpgme_ctx_t ctx, gpgme_verify_result_t status)
                                g_string_append_printf(siginfo,
                                        _("                    uid \"%s\" (Validity: %s)\n"),
                                        user->uid,
-                                       get_validity_str(user->validity));
+                                       user->revoked==TRUE?_("Revoked"):get_validity_str(user->validity));
                                j++;
                                user = user->next;
                        }
+                       g_string_append_printf(siginfo,_("Owner Trust: %s\n"),
+                                              get_owner_trust_str(key->owner_trust));
                        g_string_append(siginfo,
                                _("Primary key fingerprint:"));
                        const char* primary_fpr = NULL;
@@ -378,20 +396,12 @@ gpgme_data_t sgpgme_data_from_mimeinfo(MimeInfo *mimeinfo)
        gpgme_data_t data = NULL;
        gpgme_error_t err;
        FILE *fp = g_fopen(mimeinfo->data.filename, "rb");
-       gchar *tmp_file = NULL;
 
        if (!fp) 
                return NULL;
 
-       tmp_file = get_tmp_file();
-       copy_file_part(fp, mimeinfo->offset, mimeinfo->length, tmp_file);
+       err = gpgme_data_new_from_filepart(&data, NULL, fp, mimeinfo->offset, mimeinfo->length);
        fclose(fp);
-       fp = NULL;
-       debug_print("tmp file %s\n", tmp_file);
-       
-       err = gpgme_data_new_from_file(&data, tmp_file, 1);
-       claws_unlink(tmp_file);
-       g_free(tmp_file);
 
        debug_print("data %p (%d %d)\n", (void *)&data, mimeinfo->offset, mimeinfo->length);
        if (err) {
@@ -619,19 +629,23 @@ void sgpgme_init()
 #else
                ctype_locale = g_strdup(setlocale(LC_CTYPE, NULL));
 #endif
-               debug_print("setting gpgme locale to: %s\n", ctype_locale ? ctype_locale : "NULL");
-               if (strchr(ctype_locale, '.'))
-                       *(strchr(ctype_locale, '.')) = '\0';
-               else if (strchr(ctype_locale, '@'))
-                       *(strchr(ctype_locale, '@')) = '\0';
-               ctype_utf8_locale = g_strconcat(ctype_locale, ".UTF-8", NULL);
-
-               debug_print("setting gpgme locale to UTF8: %s\n", ctype_utf8_locale ? ctype_utf8_locale : "NULL");
-               gpgme_set_locale(NULL, LC_CTYPE, ctype_utf8_locale);
-
-               debug_print("done\n");
-               g_free(ctype_utf8_locale);
-               g_free(ctype_locale);
+               if (ctype_locale) {
+                       debug_print("setting gpgme CTYPE locale to: %s\n", ctype_locale);
+                       if (strchr(ctype_locale, '.'))
+                               *(strchr(ctype_locale, '.')) = '\0';
+                       else if (strchr(ctype_locale, '@'))
+                               *(strchr(ctype_locale, '@')) = '\0';
+                       ctype_utf8_locale = g_strconcat(ctype_locale, ".UTF-8", NULL);
+
+                       debug_print("setting gpgme locale to UTF8: %s\n", ctype_utf8_locale ? ctype_utf8_locale : "NULL");
+                       gpgme_set_locale(NULL, LC_CTYPE, ctype_utf8_locale);
+
+                       debug_print("done\n");
+                       g_free(ctype_utf8_locale);
+                       g_free(ctype_locale);
+               } else {
+                       debug_print("couldn't set gpgme CTYPE locale\n");
+               }
 #endif
 #ifdef LC_MESSAGES
                debug_print("setting gpgme MESSAGES locale\n");
@@ -640,19 +654,23 @@ void sgpgme_init()
 #else
                messages_locale = g_strdup(setlocale(LC_MESSAGES, NULL));
 #endif
-               debug_print("setting gpgme locale to: %s\n", messages_locale ? messages_locale : "NULL");
-               if (strchr(messages_locale, '.'))
-                       *(strchr(messages_locale, '.')) = '\0';
-               else if (strchr(messages_locale, '@'))
-                       *(strchr(messages_locale, '@')) = '\0';
-               messages_utf8_locale = g_strconcat(messages_locale, ".UTF-8", NULL);
-               debug_print("setting gpgme locale to UTF8: %s\n", messages_utf8_locale ? messages_utf8_locale : "NULL");
-
-               gpgme_set_locale(NULL, LC_MESSAGES, messages_utf8_locale);
-
-               debug_print("done\n");
-               g_free(messages_utf8_locale);
-               g_free(messages_locale);
+               if (messages_locale) {
+                       debug_print("setting gpgme MESSAGES locale to: %s\n", messages_locale);
+                       if (strchr(messages_locale, '.'))
+                               *(strchr(messages_locale, '.')) = '\0';
+                       else if (strchr(messages_locale, '@'))
+                               *(strchr(messages_locale, '@')) = '\0';
+                       messages_utf8_locale = g_strconcat(messages_locale, ".UTF-8", NULL);
+                       debug_print("setting gpgme locale to UTF8: %s\n", messages_utf8_locale ? messages_utf8_locale : "NULL");
+
+                       gpgme_set_locale(NULL, LC_MESSAGES, messages_utf8_locale);
+
+                       debug_print("done\n");
+                       g_free(messages_utf8_locale);
+                       g_free(messages_locale);
+               } else {
+                       debug_print("couldn't set gpgme MESSAGES locale\n");
+               }
 #endif
                if (!gpgme_get_engine_info(&engineInfo)) {
                        while (engineInfo) {
@@ -780,9 +798,9 @@ again:
        }
        
        key_parms = g_strdup_printf("<GnupgKeyParms format=\"internal\">\n"
-                                       "Key-Type: DSA\n"
-                                       "Key-Length: 1024\n"
-                                       "Subkey-Type: ELG-E\n"
+                                       "Key-Type: RSA\n"
+                                       "Key-Length: 2048\n"
+                                       "Subkey-Type: RSA\n"
                                        "Subkey-Length: 2048\n"
                                        "Name-Real: %s\n"
                                        "Name-Email: %s\n"