Репозитории ALT
S: | 3.7.0-alt0.6 |
4.1: | 2.2.9-alt1.1 |
4.0: | 2.2.9-alt1.1 |
3.0: | 1.0.4-alt1 |
Группа :: Сети/Почта
Пакет: sylpheed
Главная Изменения Спек Патчи Sources Загрузить Gear Bugs and FR Repocop
Патч: sylpheed-1.0.4-alt-gpg_utf8.patch
Скачать
Скачать
--- sylpheed-1.0.4/src/codeconv.c.alt-gpg_utf8 2005-06-06 19:05:45 +0400
+++ sylpheed-1.0.4/src/codeconv.c 2005-06-08 19:07:54 +0400
@@ -1670,3 +1670,75 @@ void conv_encode_header(gchar *dest, gin
}
#undef LBREAK_IF_REQUIRED
+
+/*
+ * Given the first byte of an UTF-8 character sequence, returns number
+ * of bytes in the sequence, or -1 if the byte cannot begin a valid
+ * UTF-8 sequence.
+ *
+ * Important: The character value must be unsigned.
+ */
+#define UTF8_CHAR_LEN(c) ( (c) < 0x80 ? 1 : \
+ (c) < 0xC2 ? -1 : \
+ (c) < 0xE0 ? 2 : \
+ (c) < 0xF0 ? 3 : \
+ (c) < 0xF8 ? 4 : \
+ (c) < 0xFC ? 5 : \
+ (c) < 0xFE ? 6 : -1 )
+
+/*
+ * Convert an UTF-8 string to the local encoding. Characters that
+ * cannot be converted (not representable in the local encoding, or
+ * invalid UTF-8) are replaced by the \x## C-style escape representation
+ * using UTF-8 codes (like GPG does).
+ *
+ * Returns a newly allocated string which must be freed with g_free().
+ */
+gchar *conv_utf8_to_local_with_escapes(const gchar *inbuf)
+{
+ const gchar *cur_charset = conv_get_current_charset_str();
+ GString *result_str;
+ gchar *result;
+ gchar *conv_result;
+ gchar buf[6+1];
+ guchar code;
+ gint char_len;
+ gint bytes_left;
+
+ /* First try direct conversion */
+ result = conv_codeset_strdup(inbuf, CS_UTF_8, cur_charset);
+ if (result)
+ return result;
+
+ /* Direct conversion failed - need to go character by character */
+ result_str = g_string_new("");
+ bytes_left = strlen(inbuf);
+ while (bytes_left > 0) {
+ code = *inbuf;
+ char_len = UTF8_CHAR_LEN(code);
+
+ if (char_len != -1 && char_len <= bytes_left) {
+ memcpy(buf, inbuf, char_len);
+ buf[char_len] = '\0';
+ conv_result = conv_codeset_strdup(buf, CS_UTF_8,
+ cur_charset);
+ } else
+ conv_result = NULL;
+
+ if (conv_result) {
+ g_string_append(result_str, conv_result);
+ g_free(conv_result);
+ inbuf += char_len;
+ bytes_left -= char_len;
+ } else {
+ sprintf(buf, "\\x%02x", code);
+ g_string_append(result_str, buf);
+ ++inbuf;
+ --bytes_left;
+ }
+ }
+
+ result = result_str->str;
+ g_string_free(result_str, FALSE);
+ return result;
+}
--- sylpheed-1.0.4/src/codeconv.h.alt-gpg_utf8 2005-03-04 10:14:42 +0300
+++ sylpheed-1.0.4/src/codeconv.h 2005-06-08 19:06:56 +0400
@@ -226,5 +226,7 @@ void conv_encode_header (gchar *dest,
gint header_len,
gboolean addr_field);
+gchar *conv_utf8_to_local_with_escapes (const gchar *inbuf);
+
#endif /* __CODECONV_H__ */
--- sylpheed-1.0.4/src/passphrase.c.alt-gpg_utf8 2005-01-28 10:44:19 +0300
+++ sylpheed-1.0.4/src/passphrase.c 2005-06-08 19:11:12 +0400
@@ -45,6 +45,7 @@
#include "prefs_common.h"
#include "manage_window.h"
#include "utils.h"
+#include "codeconv.h"
static int grab_all = 0;
@@ -281,10 +282,12 @@ static int free_passphrase(gpointer _unu
}
gpgme_error_t
-gpgmegtk_passphrase_cb(void *opaque, const char *uid_hint,
- const char *passphrase_hint, int prev_bad, int fd)
+gpgmegtk_passphrase_cb(void *opaque, const char *uid_hint_utf8,
+ const char *passphrase_hint_utf8, int prev_bad, int fd)
{
const char *pass;
+ gchar *uid_hint;
+ gchar *passphrase_hint;
if (prefs_common.store_passphrase && last_pass != NULL && !prev_bad) {
write(fd, last_pass, strlen(last_pass));
@@ -292,8 +295,12 @@ gpgmegtk_passphrase_cb(void *opaque, con
return GPG_ERR_NO_ERROR;
}
gpgmegtk_set_passphrase_grab (prefs_common.passphrase_grab);
+ uid_hint = conv_utf8_to_local_with_escapes(uid_hint_utf8);
+ passphrase_hint = conv_utf8_to_local_with_escapes(passphrase_hint_utf8);
debug_print ("%% requesting passphrase for `%s': ", uid_hint);
pass = passphrase_mbox (uid_hint, passphrase_hint, prev_bad);
+ g_free(uid_hint);
+ g_free(passphrase_hint);
gpgmegtk_free_passphrase();
if (!pass) {
debug_print ("%% cancel passphrase entry");
--- sylpheed-1.0.4/src/passphrase.h.alt-gpg_utf8 2005-01-28 10:44:19 +0300
+++ sylpheed-1.0.4/src/passphrase.h 2005-06-08 19:11:58 +0400
@@ -28,8 +28,8 @@ struct passphrase_cb_info_s {
};
void gpgmegtk_set_passphrase_grab (gint yesno);
-gpgme_error_t gpgmegtk_passphrase_cb(void *opaque, const char *uid_hint,
- const char *passphrase_info, int prev_bad, int fd);
+gpgme_error_t gpgmegtk_passphrase_cb(void *opaque, const char *uid_hint_utf8,
+ const char *passphrase_info_utf8, int prev_bad, int fd);
void gpgmegtk_free_passphrase();
#endif /* GPGMEGTK_PASSPHRASE_H */
--- sylpheed-1.0.4/src/rfc2015.c.alt-gpg_utf8 2005-06-06 19:05:45 +0400
+++ sylpheed-1.0.4/src/rfc2015.c 2005-06-08 19:37:57 +0400
@@ -126,6 +126,7 @@ sig_status_for_key(GString *str, gpgme_c
{
gpgme_key_t key;
gpgme_user_id_t user;
+ gchar *uid;
gpgme_get_key(ctx, sig->fpr, &key, 0);
if (key == NULL || key->uids->uid == NULL) {
@@ -137,15 +138,19 @@ sig_status_for_key(GString *str, gpgme_c
return;
}
user = key->uids;
+ uid = conv_utf8_to_local_with_escapes(user->uid);
g_string_sprintfa
- (str, gpgmegtk_sig_status_to_string (sig, TRUE), user->uid);
+ (str, gpgmegtk_sig_status_to_string (sig, TRUE), uid);
+ g_free(uid);
g_string_append (str, "\n");
user = user->next;
while (user) {
+ uid = conv_utf8_to_local_with_escapes(user->uid);
g_string_sprintfa
- (str, _(" aka \"%s\"\n"), user->uid);
- user = user->next;
+ (str, _(" aka \"%s\"\n"), uid);
+ g_free(uid);
+ user = user->next;
}
}
@@ -693,11 +698,18 @@ GSList *rfc2015_create_signers_list (con
GSList *p;
gpgme_error_t err;
gpgme_key_t key;
+ char *keyid_utf8;
+ keyid_utf8 = conv_codeset_strdup(keyid, conv_get_current_charset_str(),
+ CS_UTF_8);
+ if (!keyid_utf8) {
+ debug_print("cannot convert keyid \"%s\" to UTF-8", keyid);
+ return NULL;
+ }
err = gpgme_new (&list_ctx);
if (err)
goto leave;
- err = gpgme_op_keylist_start (list_ctx, keyid, 1);
+ err = gpgme_op_keylist_start (list_ctx, keyid_utf8, 1);
if (err)
goto leave;
while ( !(err = gpgme_op_keylist_next (list_ctx, &key)) ) {
@@ -719,6 +731,7 @@ leave:
}
if (list_ctx)
gpgme_release (list_ctx);
+ g_free(keyid_utf8);
return err ? NULL : key_list;
}
--- sylpheed-1.0.4/src/select-keys.c.alt-gpg_utf8 2005-01-28 12:51:15 +0300
+++ sylpheed-1.0.4/src/select-keys.c 2005-06-08 19:52:19 +0400
@@ -46,6 +46,7 @@
#include "inputdialog.h"
#include "manage_window.h"
#include "alertpanel.h"
+#include "codeconv.h"
#define DIM(v) (sizeof(v)/sizeof((v)[0]))
#define DIMof(type,member) DIM(((type *)0)->member)
@@ -184,10 +185,10 @@ set_row (GtkCList *clist, gpgme_key_t ke
text[COL_KEYID] = s;
s = key->uids->name;
- text[COL_NAME] = s;
+ text[COL_NAME] = conv_utf8_to_local_with_escapes(s);
s = key->uids->email;
- text[COL_EMAIL] = s;
+ text[COL_EMAIL] = conv_utf8_to_local_with_escapes(s);
switch (key->uids->validity)
{
@@ -214,6 +215,8 @@ set_row (GtkCList *clist, gpgme_key_t ke
text[COL_VALIDITY] = s;
row = gtk_clist_append (clist, (gchar**)text);
+ g_free (text[COL_NAME]);
+ g_free (text[COL_EMAIL]);
g_free (algo_buf);
gtk_clist_set_row_data_full (clist, row, key, destroy_key);
@@ -226,6 +229,7 @@ fill_clist (struct select_keys_s *sk, co
gpgme_ctx_t ctx;
gpgme_error_t err;
gpgme_key_t key;
+ gchar *pattern_utf8;
int running=0;
g_return_if_fail (sk);
@@ -244,7 +248,16 @@ fill_clist (struct select_keys_s *sk, co
while (gtk_events_pending ())
gtk_main_iteration ();
- err = gpgme_op_keylist_start (ctx, pattern, 0);
+ pattern_utf8 = conv_codeset_strdup(pattern, conv_get_current_charset_str(),
+ CS_UTF_8);
+ if (!pattern_utf8) {
+ debug_print ("cannot convert pattern \"%s\" to UTF-8", pattern);
+ sk->select_ctx = NULL;
+ gpgme_release(ctx);
+ return;
+ }
+ err = gpgme_op_keylist_start (ctx, pattern_utf8, 0);
+ g_free(pattern_utf8);
if (err) {
debug_print ("** gpgme_op_keylist_start(%s) failed: %s",
pattern, gpgme_strerror (err));
--- sylpheed-1.0.4/src/sigstatus.c.alt-gpg_utf8 2005-06-06 19:05:45 +0400
+++ sylpheed-1.0.4/src/sigstatus.c 2005-06-08 19:55:46 +0400
@@ -182,19 +182,21 @@ void gpgmegtk_sig_status_update(Gpgmegtk
sig = result->signatures;
while (sig) {
gchar *tmp;
- const gchar *userid;
+ const gchar *userid_utf8, *userid;
gpgme_key_t key = NULL;
if (!gpgme_get_key(ctx, sig->fpr, &key, 0)) {
- userid = key->uids->uid;
+ userid_utf8 = key->uids->uid;
} else {
- userid = "[?]";
+ userid_utf8 = "[?]";
}
+ userid = conv_utf8_to_local_with_escapes(userid_utf8);
tmp = g_strdup_printf(_("%s%s%s from \"%s\""),
text ? text : "",
text ? "\n" : "",
- gpgmegtk_sig_status_to_string(sig, FALSE),
+ gpgmegtk_sig_status_to_string(sig, FALSE),
userid);
+ g_free(userid);
g_free (text);
text = tmp;
gpgme_key_unref (key);