[Commits] compose.c 1.382.2.594 1.382.2.595 procheader.c 1.47.2.54 1.47.2.55 procheader.h 1.11.2.12 1.11.2.13

mones at claws-mail.org mones at claws-mail.org
Fri Nov 18 20:36:57 CET 2011


Update of /home/claws-mail/claws/src
In directory claws-mail:/tmp/cvs-serv18925/src

Modified Files:
      Tag: gtk2
	compose.c procheader.c procheader.h 
Log Message:
2011-11-18 [mones]	3.7.10cvs87

	* src/compose.c
	* src/procheader.c
	* src/procheader.h
		Fixes bug #2509, "manually added headers are lost unless
		mail is sent inmediately" 

Index: compose.c
===================================================================
RCS file: /home/claws-mail/claws/src/compose.c,v
retrieving revision 1.382.2.594
retrieving revision 1.382.2.595
diff -u -d -r1.382.2.594 -r1.382.2.595
--- compose.c	13 Nov 2011 14:09:01 -0000	1.382.2.594
+++ compose.c	18 Nov 2011 19:36:54 -0000	1.382.2.595
@@ -220,6 +220,9 @@
 						 ComposeEntryType to_type);
 static gint compose_parse_header		(Compose	*compose,
 						 MsgInfo	*msginfo);
+static gint compose_parse_manual_headers	(Compose	*compose,
+						 MsgInfo	*msginfo,
+						 HeaderEntry	*entries);
 static gchar *compose_parse_references		(const gchar	*ref,
 						 const gchar	*msgid);
 
@@ -291,6 +294,7 @@
 static int compose_add_attachments		(Compose	*compose,
 						 MimeInfo	*parent);
 static gchar *compose_get_header		(Compose	*compose);
+static gchar *compose_get_manual_headers_info	(Compose	*compose);
 
 static void compose_convert_header		(Compose	*compose,
 						 gchar		*dest,
@@ -2125,6 +2129,7 @@
 	MsgInfo *replyinfo = NULL, *fwdinfo = NULL;
 	gboolean autowrap = prefs_common.autowrap;
 	gboolean autoindent = prefs_common.auto_indent;
+	HeaderEntry *manual_headers = NULL;
 
 	cm_return_val_if_fail(msginfo != NULL, NULL);
 	cm_return_val_if_fail(msginfo->folder != NULL, NULL);
@@ -2231,6 +2236,15 @@
 			}
 			g_strfreev(tokens);
 		}
+		/* Get manual headers */
+		if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "X-Claws-Manual-Headers:")) {
+			gchar *listmh = g_strdup(&queueheader_buf[strlen("X-Claws-Manual-Headers:")]);
+			if (*listmh != '\0') {
+				debug_print("Got manual headers: %s\n", listmh);
+				manual_headers = procheader_entries_from_str(listmh);
+			}
+			g_free(listmh);
+		}
 	} else {
 		account = msginfo->folder->folder->account;
 	}
@@ -2339,6 +2353,16 @@
 					G_CALLBACK(compose_changed_cb),
 					compose);
 
+	if (manual_headers != NULL) {
+		if (compose_parse_manual_headers(compose, msginfo, manual_headers) < 0) {
+			procheader_entries_free(manual_headers);
+			compose->updating = FALSE;
+			compose_destroy(compose);
+			return NULL;
+		}
+		procheader_entries_free(manual_headers);
+	}
+
 	gtk_widget_grab_focus(compose->text);
 
         if (prefs_common.auto_exteditor) {
@@ -2879,6 +2903,33 @@
 	return 0;
 }
 
+static gint compose_parse_manual_headers(Compose *compose, MsgInfo *msginfo, HeaderEntry *entries)
+{
+	FILE *fp;
+	HeaderEntry *he;
+
+	cm_return_val_if_fail(msginfo != NULL, -1);
+
+	if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
+	procheader_get_header_fields(fp, entries);
+	fclose(fp);
+
+	he = entries;
+	while (he != NULL && he->name != NULL) {
+		GtkTreeIter iter;
+		GtkListStore *model = NULL;
+
+		debug_print("Adding manual header: %s with value %s\n", he->name, he->body);
+		model = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(compose->header_last->combo)));
+		COMBOBOX_ADD(model, he->name, COMPOSE_TO);
+		gtk_combo_box_set_active_iter(GTK_COMBO_BOX(compose->header_last->combo), &iter);
+		gtk_entry_set_text(GTK_ENTRY(compose->header_last->entry), he->body);
+		++he;
+	}
+
+	return 0;
+}
+
 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
 {
 	GSList *ref_id_list, *cur;
@@ -6106,6 +6157,55 @@
 	return;
 }
 
+static gchar *compose_get_manual_headers_info(Compose *compose)
+{
+	GString *sh_header = g_string_new(" ");
+	GSList *list;
+	gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
+
+	for (list = compose->header_list; list; list = list->next) {
+    		ComposeHeaderEntry *headerentry;
+		gchar *tmp;
+		gchar *headername;
+		gchar *headername_wcolon;
+		const gchar *headername_trans;
+		gchar **string;
+		gboolean standard_header = FALSE;
+
+		headerentry = ((ComposeHeaderEntry *)list->data);
+
+		tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((headerentry->combo))))));
+		g_strstrip(tmp);
+		if (*tmp == '\0' || strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
+			g_free(tmp);
+			continue;
+		}
+
+		if (!strstr(tmp, ":")) {
+			headername_wcolon = g_strconcat(tmp, ":", NULL);
+			headername = g_strdup(tmp);
+		} else {
+			headername_wcolon = g_strdup(tmp);
+			headername = g_strdup(strtok(tmp, ":"));
+		}
+		g_free(tmp);
+		
+		string = std_headers;
+		while (*string != NULL) {
+			headername_trans = prefs_common_translated_header_name(*string);
+			if (!strcmp(headername_trans, headername_wcolon))
+				standard_header = TRUE;
+			string++;
+		}
+		if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
+			g_string_append_printf(sh_header, "%s ", headername);
+		g_free(headername);
+		g_free(headername_wcolon);
+	}
+	g_string_truncate(sh_header, strlen(sh_header->str) - 1); /* remove last space */
+	return g_string_free(sh_header, FALSE);
+}
+
 static gchar *compose_get_header(Compose *compose)
 {
 	gchar buf[BUFFSIZE];
@@ -9412,6 +9512,7 @@
 	Compose *compose = (Compose *)data;
 	FolderItem *draft;
 	gchar *tmp;
+	gchar *sheaders;
 	gint msgnum;
 	MsgFlags flag = {0, 0};
 	static gboolean lock = FALSE;
@@ -9492,6 +9593,10 @@
 	err |= (fprintf(fp, "X-Claws-Auto-Wrapping:%d\n", compose->autowrap) < 0);
 	err |= (fprintf(fp, "X-Claws-Auto-Indent:%d\n", compose->autoindent) < 0);
 
+	sheaders = compose_get_manual_headers_info(compose);
+	err |= (fprintf(fp, "X-Claws-Manual-Headers:%s\n", sheaders) < 0);
+	g_free(sheaders);
+
 	/* end of headers */
 	err |= (fprintf(fp, "X-Claws-End-Special-Headers: 1\n") < 0);
 

Index: procheader.h
===================================================================
RCS file: /home/claws-mail/claws/src/procheader.h,v
retrieving revision 1.11.2.12
retrieving revision 1.11.2.13
diff -u -d -r1.11.2.12 -r1.11.2.13
--- procheader.h	16 Feb 2011 07:16:15 -0000	1.11.2.12
+++ procheader.h	18 Nov 2011 19:36:55 -0000	1.11.2.13
@@ -89,5 +89,11 @@
 gboolean procheader_headername_equal    (char * hdr1, char * hdr2);
 void procheader_header_free             (Header * header);
 
-gint procheader_get_header_from_msginfo(MsgInfo *msginfo, gchar *buf, gint len,gchar *header);
+gint procheader_get_header_from_msginfo	(MsgInfo	*msginfo,
+					 gchar		*buf,
+					 gint 		len,
+					 gchar 		*header);
+
+HeaderEntry *procheader_entries_from_str(const gchar	*str);
+void procheader_entries_free		(HeaderEntry	*entries);
 #endif /* __PROCHEADER_H__ */

Index: procheader.c
===================================================================
RCS file: /home/claws-mail/claws/src/procheader.c,v
retrieving revision 1.47.2.54
retrieving revision 1.47.2.55
diff -u -d -r1.47.2.54 -r1.47.2.55
--- procheader.c	16 Feb 2011 07:16:15 -0000	1.47.2.54
+++ procheader.c	18 Nov 2011 19:36:55 -0000	1.47.2.55
@@ -1033,3 +1033,51 @@
 
 	return 0;
 }
+
+HeaderEntry *procheader_entries_from_str(const gchar *str)
+{
+	HeaderEntry *entries = NULL, *he;
+	int numh = 0, i = 0;
+	gchar **names = NULL;
+	gchar *s = str;
+
+	if (s == NULL) {
+		return NULL;
+	}
+	while (*s != '\0') {
+		if (*s == ' ') ++numh;
+		++s;
+	}
+	if (numh == 0) {
+		return NULL;
+	}
+	entries = g_new0(HeaderEntry, numh + 1); /* room for last NULL */
+	s = str;
+	++s; /* skip first space */
+	names = g_strsplit(s, " ", numh);
+	he = entries;
+	while (names[i]) {
+		he->name = g_strdup_printf("%s:", names[i]);
+		he->body = NULL;
+		he->unfold = FALSE;
+		++i, ++he;
+	}
+	he->name = NULL;
+	g_strfreev(names);
+	return entries;
+}
+
+void procheader_entries_free (HeaderEntry *entries)
+{
+	if (entries != NULL) {
+		HeaderEntry *he = entries;
+		while (he->name != NULL) {
+			g_free(he->name);
+			if (he->body != NULL)
+				g_free(he->body);
+			++he;			
+		}
+		g_free(entries);
+	}
+}
+



More information about the Commits mailing list