GString *str;
gchar *start, *cur;
+ if (!addresses)
+ return;
+
+ if (strlen (addresses) == 0)
+ return;
+
str = g_string_new ("");
start = (gchar*) addresses;
cur = (gchar*) addresses;
for (cur = start; *cur != '\0'; cur = g_utf8_next_char (cur)) {
if (*cur == ',' || *cur == ';') {
- if (!g_utf8_strchr (start, (cur - start + 1), g_utf8_get_char ("@")))
+ gint *start_index, *end_index;
+ gchar *next_char = g_utf8_next_char (cur);
+
+ if (!g_utf8_strchr (start, (cur - start + 1), g_utf8_get_char ("@")) &&
+ next_char && *next_char != '\n')
continue;
- {
- gint *start_index, *end_index;
- start_index = g_new0 (gint, 1);
- end_index = g_new0 (gint, 1);
- *start_index = g_utf8_pointer_to_offset (addresses, start);
- *end_index = g_utf8_pointer_to_offset (addresses, cur);;
- *start_indexes = g_slist_prepend (*start_indexes, start_index);
- *end_indexes = g_slist_prepend (*end_indexes, end_index);
- start = g_utf8_next_char (cur);
- }
+
+ start_index = g_new0 (gint, 1);
+ end_index = g_new0 (gint, 1);
+ *start_index = g_utf8_pointer_to_offset (addresses, start);
+ *end_index = g_utf8_pointer_to_offset (addresses, cur);;
+ *start_indexes = g_slist_prepend (*start_indexes, start_index);
+ *end_indexes = g_slist_prepend (*end_indexes, end_index);
+ start = g_utf8_next_char (cur);
}
}
- *start_indexes = g_slist_reverse (*start_indexes);
- *end_indexes = g_slist_reverse (*end_indexes);
+ if (start != cur) {
+ gint *start_index, *end_index;
+ start_index = g_new0 (gint, 1);
+ end_index = g_new0 (gint, 1);
+ *start_index = g_utf8_pointer_to_offset (addresses, start);
+ *end_index = g_utf8_pointer_to_offset (addresses, cur);;
+ *start_indexes = g_slist_prepend (*start_indexes, start_index);
+ *end_indexes = g_slist_prepend (*end_indexes, end_index);
+ }
+
+ if (*start_indexes)
+ *start_indexes = g_slist_reverse (*start_indexes);
+ if (*end_indexes)
+ *end_indexes = g_slist_reverse (*end_indexes);
}
}
}
if (last_quote)
- current = last_quote;
+ current = g_utf8_next_char (last_quote);
} else {
has_error = TRUE;
for (current = stripped ; *current != '\0'; current = g_utf8_next_char (current)) {
if (blank && (blank != *start)) {
if (is_quoted (*start, blank - 1)) {
*str = g_string_append_len (*str, *start, str_len);
- *str = g_string_append (*str, "; ");
+ *str = g_string_append (*str, ";");
*start = g_utf8_next_char (*cur);
} else {
*str = g_string_append_c (*str, '"');
*str = g_string_append_len (*str, blank,
(g_utf8_pointer_to_offset (*start, *cur) -
g_utf8_pointer_to_offset (*start, blank)));
- *str = g_string_append (*str, "; ");
+ *str = g_string_append (*str, ";");
*start = g_utf8_next_char (*cur);
}
} else {
*str = g_string_append_len (*str, *start, str_len);
- *str = g_string_append (*str, "; ");
+ *str = g_string_append (*str, ";");
*start = g_utf8_next_char (*cur);
}
}
gtk_text_buffer_get_bounds (buffer, &start, &end);
buffer_contents = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
+ g_strstrip (buffer_contents);
if (!g_str_has_suffix (buffer_contents, "\n")) {
if (g_str_has_suffix (buffer_contents, ";")||(g_str_has_suffix (buffer_contents, ",")))
gtk_text_buffer_insert (buffer, &end, "\n", -1);
- else
+ else
gtk_text_buffer_insert (buffer, &end, ";\n", -1);
}
g_free (buffer_contents);
if ((recipient) && (strlen (recipient) != 0)) {
if (!is_first_recipient)
- gtk_text_buffer_insert (buffer, &iter, "\n", -1);
+ gtk_text_buffer_insert (buffer, &iter, "\n", -1);
gtk_text_buffer_insert (buffer, &iter, recipient, -1);
gtk_text_buffer_insert (buffer, &iter, ";", -1);
ModestRecptEditorPrivate *priv;
GtkTextBuffer *buffer = NULL;
GtkTextIter start, end;
- gchar *c;
g_return_val_if_fail (MODEST_IS_RECPT_EDITOR (recpt_editor), NULL);
priv = MODEST_RECPT_EDITOR_GET_PRIVATE (recpt_editor);
gtk_text_buffer_get_end_iter (buffer, &end);
priv->recipients = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
- for (c = priv->recipients; *c != '\0'; c = g_utf8_next_char (c)) {
- if (*c == '\n') {
- *c = ' ';
- }
- }
return priv->recipients;
if (last_separator) {
gchar *last_at = g_utf8_strrchr (str->str, -1, g_utf8_get_char ("@"));
if (last_at) {
- if (last_at > last_separator)
+ if (last_at < last_separator)
str = g_string_append_c (str, '\n');
}
} else {
ModestRecptEditorPrivate *priv = MODEST_RECPT_EDITOR_GET_PRIVATE (editor);
prev = *location;
- if (!gtk_text_iter_backward_char (&prev))
+ /* We must go backwards twice as location points to the next
+ valid position to insert text */
+ if (!gtk_text_iter_backward_chars (&prev, 2))
return;
prev_char = gtk_text_iter_get_char (&prev);
g_signal_handlers_block_by_func (buffer, modest_recpt_editor_on_insert_text, editor);
g_signal_handlers_block_by_func (buffer, modest_recpt_editor_on_insert_text_after, editor);
- if ((prev_char == ';'||prev_char == ',')&&(!quote_opened(location))) {
+ if ((prev_char == ';'||prev_char == ',')&&(!quote_opened(&prev))) {
GtkTextMark *insert;
- gtk_text_buffer_insert (buffer, location, "\n",-1);
+ gtk_text_iter_forward_char (&prev);
+ gtk_text_buffer_insert (buffer, &prev, "\n",-1);
insert = gtk_text_buffer_get_insert (buffer);
- gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (priv->text_view), location, 0.0,TRUE, 0.0, 1.0);
+ gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (priv->text_view), &prev, 0.0,TRUE, 0.0, 1.0);
}
g_signal_handlers_unblock_by_func (buffer, modest_recpt_editor_on_insert_text, editor);
g_signal_handlers_unblock_by_func (buffer, modest_recpt_editor_on_insert_text_after, editor);