COMPOSE_QUOTE_SKIP
} ComposeQuoteMode;
+typedef enum {
+ TO_FIELD_PRESENT,
+ SUBJECT_FIELD_PRESENT,
+ BODY_FIELD_PRESENT,
+ NO_FIELD_PRESENT
+} MailField;
+
#define B64_LINE_SIZE 57
#define B64_BUFFSIZE 77
static void compose_set_template_menu (Compose *compose);
static void compose_destroy (Compose *compose);
-static void compose_entries_set (Compose *compose,
+static MailField compose_entries_set (Compose *compose,
const gchar *mailto,
ComposeEntryType to_type);
static gint compose_parse_header (Compose *compose,
gchar *mailto_from = NULL;
PrefsAccount *mailto_account = NULL;
MsgInfo* dummyinfo = NULL;
+ MailField mfield = NO_FIELD_PRESENT;
+ gchar* buf;
+ GtkTextMark *mark;
/* check if mailto defines a from */
if (mailto && *mailto != '\0') {
if (account->protocol != A_NNTP) {
if (mailto && *mailto != '\0') {
- compose_entries_set(compose, mailto, COMPOSE_TO);
+ mfield = compose_entries_set(compose, mailto, COMPOSE_TO);
} else if (item && item->prefs) {
if (item->prefs->enable_default_bcc) {
} else {
if (mailto && *mailto != '\0') {
if (!strchr(mailto, '@'))
- compose_entries_set(compose, mailto, COMPOSE_NEWSGROUPS);
+ mfield = compose_entries_set(compose, mailto, COMPOSE_NEWSGROUPS);
else
- compose_entries_set(compose, mailto, COMPOSE_TO);
+ mfield = compose_entries_set(compose, mailto, COMPOSE_TO);
} else if (item && FOLDER_CLASS(item->folder) == news_get_class()) {
compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS, PREF_FOLDER);
}
compose_set_save_to(compose, folderidentifier);
g_free(folderidentifier);
}
-
- gtk_widget_grab_focus(compose->header_last->entry);
+
+ /* Place cursor according to provided input (mfield) */
+ switch (mfield) {
+ case NO_FIELD_PRESENT:
+ gtk_widget_grab_focus(compose->header_last->entry);
+ break;
+ case TO_FIELD_PRESENT:
+ buf = g_strdup("");
+ gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
+ gtk_widget_grab_focus(compose->subject_entry);
+ break;
+ case SUBJECT_FIELD_PRESENT:
+ textview = GTK_TEXT_VIEW(compose->text);
+ textbuf = gtk_text_view_get_buffer(textview);
+ mark = gtk_text_buffer_get_insert(textbuf);
+ gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
+ gtk_text_buffer_insert(textbuf, &iter, "", -1);
+ /*
+ * SUBJECT_FIELD_PRESENT and BODY_FIELD_PRESENT
+ * only defers where it comes to the variable body
+ * is not null. If no body is present compose->text
+ * will be null in which case you cannot place the
+ * cursor inside the component so. An empty component
+ * is therefore created before placing the cursor
+ */
+ case BODY_FIELD_PRESENT:
+ gtk_widget_grab_focus(compose->text);
+ break;
+ }
undo_unblock(compose->undostruct);
}
}
-static void compose_entries_set(Compose *compose, const gchar *mailto, ComposeEntryType to_type)
+static MailField compose_entries_set(Compose *compose, const gchar *mailto, ComposeEntryType to_type)
{
gchar *to = NULL;
gchar *cc = NULL;
gchar *temp = NULL;
gsize len = 0;
gchar **attach = NULL;
+ MailField mfield = NO_FIELD_PRESENT;
/* get mailto parts but skip from */
scan_mailto_url(mailto, NULL, &to, &cc, &bcc, &subject, &body, &attach);
- if (to)
+ if (to) {
compose_entry_append(compose, to, to_type, PREF_MAILTO);
+ mfield = TO_FIELD_PRESENT;
+ }
if (cc)
compose_entry_append(compose, cc, COMPOSE_CC, PREF_MAILTO);
if (bcc)
} else {
gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
}
+ mfield = SUBJECT_FIELD_PRESENT;
}
if (body) {
GtkTextView *text = GTK_TEXT_VIEW(compose->text);
compose->autowrap = prev_autowrap;
if (compose->autowrap)
compose_wrap_all(compose);
+ mfield = BODY_FIELD_PRESENT;
}
if (attach) {
g_free(subject);
g_free(body);
g_strfreev(attach);
+
+ return mfield;
}
static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
static void compose_add_header_entry(Compose *compose, const gchar *header,
gchar *text, ComposePrefType pref_type)
{
- ComposeHeaderEntry *last_header;
+ ComposeHeaderEntry *last_header = compose->header_last;
+ gchar *tmp = g_strdup(text), *email;
+
+ extract_address(tmp);
+ email = g_utf8_strdown(tmp, -1);
+
+ if (g_hash_table_lookup(compose->email_hashtable, email) != NULL) {
+ debug_print("Ignoring duplicate address - %s %s, pref_type: %d\n",
+ header, text, (gint) pref_type);
+ g_free(email);
+ g_free(tmp);
+ return;
+ }
- last_header = compose->header_last;
-
combobox_select_by_text(GTK_COMBO_BOX(last_header->combo), header);
gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
last_header->type = pref_type;
+
+ g_hash_table_insert(compose->email_hashtable, email,
+ GUINT_TO_POINTER(1));
+ g_free(tmp);
}
-static void compose_destroy_headerentry(ComposeHeaderEntry *headerentry)
+static void compose_destroy_headerentry(Compose *compose,
+ ComposeHeaderEntry *headerentry)
{
+ gchar *text = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
+ gchar *email;
+
+ extract_address(text);
+ email = g_utf8_strdown(text, -1);
+ g_hash_table_remove(compose->email_hashtable, email);
+ g_free(text);
+ g_free(email);
+
gtk_widget_destroy(headerentry->combo);
gtk_widget_destroy(headerentry->entry);
gtk_widget_destroy(headerentry->button);
{
GSList *list;
for (list = compose->header_list; list; list = list->next)
- compose_destroy_headerentry((ComposeHeaderEntry *)list->data);
+ compose_destroy_headerentry(compose, (ComposeHeaderEntry *)list->data);
compose->header_last = NULL;
g_slist_free(compose->header_list);
compose->replyinfo = NULL;
compose->fwdinfo = NULL;
+ compose->email_hashtable = g_hash_table_new_full(g_str_hash,
+ g_str_equal, (GDestroyNotify) g_free, NULL);
+
compose->replyto = NULL;
compose->cc = NULL;
compose->bcc = NULL;
slist_free_strings(compose->header_list);
g_slist_free(compose->header_list);
+ g_hash_table_destroy(compose->email_hashtable);
+
procmsg_msginfo_free(compose->targetinfo);
procmsg_msginfo_free(compose->replyinfo);
procmsg_msginfo_free(compose->fwdinfo);
ComposeHeaderEntry *hentry=(ComposeHeaderEntry *)list->data;
if (hentry->type == PREF_ACCOUNT || !list->next) {
- compose_destroy_headerentry(hentry);
+ compose_destroy_headerentry(compose, hentry);
continue;
}
&style->base[GTK_STATE_NORMAL]);
saved_list = g_slist_append(saved_list, state);
- compose_destroy_headerentry(hentry);
+ compose_destroy_headerentry(compose, hentry);
}
compose->header_last = NULL;