aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2006-02-21 03:22:46 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2006-02-21 03:22:46 +0000
commitde44b9bbce799a4f4308809e53c30b52aa67b786 (patch)
tree273e4632d8d02f0964468050696dff344e914cab
parentc8054e822df9cdfe8ca186e107f77ef867895f47 (diff)
use filename-safe string for UIDL file.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@1003 ee746299-78ed-0310-b773-934348b2243d
-rw-r--r--ChangeLog7
-rw-r--r--ChangeLog.ja7
-rw-r--r--libsylph/pop.c12
-rw-r--r--libsylph/utils.c40
-rw-r--r--libsylph/utils.h3
5 files changed, 64 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index e36fb9ea..8aaa05b8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2006-02-21
+
+ * libsylph/utils.[ch]: uriencode_for_filename(): creates filename-safe
+ string by URI encode (except space).
+ * libsylph/pop.c: use filename-safe string for UIDL file (might break
+ backward compatibility on Unix).
+
2006-02-14
* libsylph/session.c
diff --git a/ChangeLog.ja b/ChangeLog.ja
index b3e01f1a..28f3496a 100644
--- a/ChangeLog.ja
+++ b/ChangeLog.ja
@@ -1,3 +1,10 @@
+2006-02-21
+
+ * libsylph/utils.[ch]: uriencode_for_filename(): ファイル名セーフな
+ 文字列を URI エンコードで生成(空白を除く)。
+ * libsylph/pop.c: UIDL ファイルにファイル名セーフな文字列を使用する
+ ようにした(Unix 上で後方互換性を失う可能性あり)。
+
2006-02-14
* libsylph/session.c
diff --git a/libsylph/pop.c b/libsylph/pop.c
index 8b110b3e..ed5edee3 100644
--- a/libsylph/pop.c
+++ b/libsylph/pop.c
@@ -464,12 +464,15 @@ GHashTable *pop3_get_uidl_table(PrefsAccount *ac_prefs)
gchar uidl[POPBUFSIZE];
time_t recv_time;
time_t now;
+ gchar *uid;
table = g_hash_table_new(g_str_hash, g_str_equal);
+ uid = uriencode_for_filename(ac_prefs->userid);
path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
UIDL_DIR, G_DIR_SEPARATOR_S, ac_prefs->recv_server,
- "-", ac_prefs->userid, NULL);
+ "-", uid, NULL);
+ g_free(uid);
if ((fp = g_fopen(path, "rb")) == NULL) {
if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
g_free(path);
@@ -504,13 +507,16 @@ gint pop3_write_uidl_list(Pop3Session *session)
FILE *fp;
Pop3MsgInfo *msg;
gint n;
+ gchar *uid;
if (!session->uidl_is_valid) return 0;
+ uid = uriencode_for_filename(session->ac_prefs->userid);
path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
- "uidl", G_DIR_SEPARATOR_S,
+ UIDL_DIR, G_DIR_SEPARATOR_S,
session->ac_prefs->recv_server,
- "-", session->ac_prefs->userid, NULL);
+ "-", uid, NULL);
+ g_free(uid);
if ((fp = g_fopen(path, "wb")) == NULL) {
FILE_OP_ERROR(path, "fopen");
g_free(path);
diff --git a/libsylph/utils.c b/libsylph/utils.c
index e99f3d3a..296cd8d9 100644
--- a/libsylph/utils.c
+++ b/libsylph/utils.c
@@ -1,6 +1,6 @@
/*
* LibSylph -- E-Mail client library
- * Copyright (C) 1999-2005 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2006 Hiroyuki Yamamoto
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1532,6 +1532,14 @@ GList *uri_list_extract_filenames(const gchar *uri_list)
} \
}
+#define INT_TO_HEX(hex, val) \
+{ \
+ if ((val) < 10) \
+ hex = '0' + (val); \
+ else \
+ hex = 'a' + (val) - 10; \
+}
+
/* Converts two-digit hexadecimal to decimal. Used for unescaping escaped
* characters.
*/
@@ -1545,6 +1553,16 @@ static gint axtoi(const gchar *hex_str)
return (hi << 4) + lo;
}
+static void get_hex_str(gchar *out, guchar ch)
+{
+ gchar hex;
+
+ INT_TO_HEX(hex, ch >> 4);
+ *out++ = hex;
+ INT_TO_HEX(hex, ch & 0x0f);
+ *out++ = hex;
+}
+
gboolean is_uri_string(const gchar *str)
{
return (g_ascii_strncasecmp(str, "http://", 7) == 0 ||
@@ -1622,6 +1640,26 @@ gchar *encode_uri(const gchar *filename)
return uri;
}
+gchar *uriencode_for_filename(const gchar *filename)
+{
+ const gchar *p = filename;
+ gchar *enc, *outp;
+
+ outp = enc = g_malloc(strlen(filename) * 3 + 1);
+
+ for (p = filename; *p != '\0'; p++) {
+ if (strchr("\t\r\n\"'\\/:;*?<>|", *p)) {
+ *outp++ = '%';
+ get_hex_str(outp, *p);
+ outp += 2;
+ } else
+ *outp++ = *p;
+ }
+
+ *outp = '\0';
+ return enc;
+}
+
gint scan_mailto_url(const gchar *mailto, gchar **to, gchar **cc, gchar **bcc,
gchar **subject, gchar **body)
{
diff --git a/libsylph/utils.h b/libsylph/utils.h
index 92fd831e..e5251991 100644
--- a/libsylph/utils.h
+++ b/libsylph/utils.h
@@ -1,6 +1,6 @@
/*
* LibSylph -- E-Mail client library
- * Copyright (C) 1999-2005 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2006 Hiroyuki Yamamoto
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -346,6 +346,7 @@ gint get_uri_len (const gchar *str);
void decode_uri (gchar *decoded_uri,
const gchar *encoded_uri);
gchar *encode_uri (const gchar *filename);
+gchar *uriencode_for_filename (const gchar *filename);
gint scan_mailto_url (const gchar *mailto,
gchar **to,
gchar **cc,