aboutsummaryrefslogtreecommitdiffstats
path: root/composer
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2012-01-01 03:43:58 +0800
committerMatthew Barnes <mbarnes@redhat.com>2012-01-01 03:57:30 +0800
commit70b27af74ecaf38a1567ff1a7d483f7a65d7f2fe (patch)
treea389e21805c4e1909f0c3bdd21de57f36e60c648 /composer
parenta7abe3ac594dd3324f473b8200641e03cf64f774 (diff)
downloadgsoc2013-evolution-70b27af74ecaf38a1567ff1a7d483f7a65d7f2fe.tar.gz
gsoc2013-evolution-70b27af74ecaf38a1567ff1a7d483f7a65d7f2fe.tar.zst
gsoc2013-evolution-70b27af74ecaf38a1567ff1a7d483f7a65d7f2fe.zip
Move gtkhtml data encoding/decoding to e-composer-private.c.
Simplify the algorithms, trading efficiency for readability.
Diffstat (limited to 'composer')
-rw-r--r--composer/e-composer-private.c81
-rw-r--r--composer/e-composer-private.h2
-rw-r--r--composer/e-msg-composer.c103
3 files changed, 89 insertions, 97 deletions
diff --git a/composer/e-composer-private.c b/composer/e-composer-private.c
index a5282afe2b..b35c84d4c8 100644
--- a/composer/e-composer-private.c
+++ b/composer/e-composer-private.c
@@ -639,6 +639,87 @@ e_composer_get_default_charset (void)
return charset;
}
+gchar *
+e_composer_decode_clue_value (const gchar *encoded_value)
+{
+ GString *buffer;
+ const gchar *cp;
+
+ /* Decode a GtkHtml "ClueFlow" value. */
+
+ g_return_val_if_fail (encoded_value != NULL, NULL);
+
+ buffer = g_string_sized_new (strlen (encoded_value));
+
+ /* Copy the value, decoding escaped characters as we go. */
+ cp = encoded_value;
+ while (*cp != '\0') {
+ if (*cp == '.') {
+ cp++;
+ switch (*cp) {
+ case '.':
+ g_string_append_c (buffer, '.');
+ break;
+ case '1':
+ g_string_append_c (buffer, '"');
+ break;
+ case '2':
+ g_string_append_c (buffer, '=');
+ break;
+ default:
+ /* Invalid escape sequence. */
+ g_string_free (buffer, TRUE);
+ return NULL;
+ }
+ } else
+ g_string_append_c (buffer, *cp);
+ cp++;
+ }
+
+ return g_string_free (buffer, FALSE);
+}
+
+gchar *
+e_composer_encode_clue_value (const gchar *decoded_value)
+{
+ gchar *encoded_value;
+ gchar **strv;
+
+ /* Encode a GtkHtml "ClueFlow" value. */
+
+ g_return_val_if_fail (decoded_value != NULL, NULL);
+
+ /* XXX This is inefficient but easy to understand. */
+
+ encoded_value = g_strdup (decoded_value);
+
+ /* Substitution: '.' --> '..' (do this first) */
+ if (strchr (encoded_value, '.') != NULL) {
+ strv = g_strsplit (encoded_value, ".", 0);
+ g_free (encoded_value);
+ encoded_value = g_strjoinv ("..", strv);
+ g_strfreev (strv);
+ }
+
+ /* Substitution: '"' --> '.1' */
+ if (strchr (encoded_value, '"') != NULL) {
+ strv = g_strsplit (encoded_value, """", 0);
+ g_free (encoded_value);
+ encoded_value = g_strjoinv (".1", strv);
+ g_strfreev (strv);
+ }
+
+ /* Substitution: '=' --> '.2' */
+ if (strchr (encoded_value, '=') != NULL) {
+ strv = g_strsplit (encoded_value, "=", 0);
+ g_free (encoded_value);
+ encoded_value = g_strjoinv (".2", strv);
+ g_strfreev (strv);
+ }
+
+ return encoded_value;
+}
+
gboolean
e_composer_paste_html (EMsgComposer *composer,
GtkClipboard *clipboard)
diff --git a/composer/e-composer-private.h b/composer/e-composer-private.h
index 3a3bf62128..4282d57920 100644
--- a/composer/e-composer-private.h
+++ b/composer/e-composer-private.h
@@ -128,6 +128,8 @@ void e_composer_private_finalize (EMsgComposer *composer);
void e_composer_actions_init (EMsgComposer *composer);
gchar * e_composer_find_data_file (const gchar *basename);
gchar * e_composer_get_default_charset (void);
+gchar * e_composer_decode_clue_value (const gchar *encoded_value);
+gchar * e_composer_encode_clue_value (const gchar *decoded_value);
gboolean e_composer_paste_html (EMsgComposer *composer,
GtkClipboard *clipboard);
gboolean e_composer_paste_image (EMsgComposer *composer,
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index 7ff8b487ef..a7250a7d7d 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -1389,99 +1389,6 @@ composer_build_message_finish (EMsgComposer *composer,
/* Signatures */
-static gchar *
-encode_signature_uid (ESignature *signature)
-{
- const gchar *uid;
- const gchar *s;
- gchar *ename, *e;
- gint len = 0;
-
- uid = e_signature_get_uid (signature);
-
- s = uid;
- while (*s) {
- len++;
- if (*s == '"' || *s == '.' || *s == '=')
- len++;
- s++;
- }
-
- ename = g_new (gchar, len + 1);
-
- s = uid;
- e = ename;
- while (*s) {
- if (*s == '"') {
- *e = '.';
- e++;
- *e = '1';
- e++;
- } else if (*s == '=') {
- *e = '.';
- e++;
- *e = '2';
- e++;
- } else {
- *e = *s;
- e++;
- }
- if (*s == '.') {
- *e = '.';
- e++;
- }
- s++;
- }
- *e = 0;
-
- return ename;
-}
-
-static gchar *
-decode_signature_name (const gchar *name)
-{
- const gchar *s;
- gchar *dname, *d;
- gint len = 0;
-
- s = name;
- while (*s) {
- len++;
- if (*s == '.') {
- s++;
- if (!*s || !(*s == '.' || *s == '1' || *s == '2'))
- return NULL;
- }
- s++;
- }
-
- dname = g_new (char, len + 1);
-
- s = name;
- d = dname;
- while (*s) {
- if (*s == '.') {
- s++;
- if (!*s || !(*s == '.' || *s == '1' || *s == '2')) {
- g_free (dname);
- return NULL;
- }
- if (*s == '1')
- *d = '"';
- else if (*s == '2')
- *d = '=';
- else
- *d = '.';
- } else
- *d = *s;
- d++;
- s++;
- }
- *d = 0;
-
- return dname;
-}
-
static gboolean
is_top_signature (EMsgComposer *composer)
{
@@ -1600,8 +1507,10 @@ get_signature_html (EMsgComposer *composer)
const gchar *sig_delim = format_html ? "-- \n<BR>" : "-- \n";
const gchar *sig_delim_ent = format_html ? "\n-- \n<BR>" : "\n-- \n";
- if (signature)
- encoded_uid = encode_signature_uid (signature);
+ if (signature != NULL) {
+ const gchar *uid = e_signature_get_uid (signature);
+ encoded_uid = e_composer_encode_clue_value (uid);
+ }
/* The signature dash convention ("-- \n") is specified
* in the "Son of RFC 1036", section 4.3.2.
@@ -3113,11 +3022,11 @@ set_signature_gui (EMsgComposer *composer)
data = gtkhtml_editor_get_paragraph_data (editor, "signature_name");
if (g_str_has_prefix (data, "uid:")) {
- decoded = decode_signature_name (data + 4);
+ decoded = e_composer_decode_clue_value (data + 4);
signature = e_get_signature_by_uid (decoded);
g_free (decoded);
} else if (g_str_has_prefix (data, "name:")) {
- decoded = decode_signature_name (data + 5);
+ decoded = e_composer_decode_clue_value (data + 5);
signature = e_get_signature_by_name (decoded);
g_free (decoded);
}