Index: mail/ChangeLog
===================================================================
--- mail/ChangeLog	(revision 34476)
+++ mail/ChangeLog	(working copy)
@@ -1,3 +1,10 @@
+2007-11-01  Milan Crha  <mcrha@redhat.com>
+
+	** Part of fix for bug #271551
+
+	* evolution-mail.schemas.in:
+	New key "/apps/evolution/mail/composer/current_folder".
+
 2007-10-31  Priit Laes  <plaes@svn.gnome.org>
 	
 	* em-format-html-display.c: Fix typo in documentation.
Index: mail/evolution-mail.schemas.in
===================================================================
--- mail/evolution-mail.schemas.in	(revision 34476)
+++ mail/evolution-mail.schemas.in	(working copy)
@@ -1101,5 +1101,18 @@
       </locale>
     </schema>
 
+    <schema>
+      <key>/schemas/apps/evolution/mail/composer/current_folder</key>
+      <applyto>/apps/evolution/mail/composer/current_folder</applyto>
+      <owner>evolution-mail</owner>
+      <type>string</type>
+      <locale name="C">
+         <short>Composer load/attach directory</short>
+         <long>
+           Directory for loading/attaching files to composer
+         </long>
+      </locale>
+    </schema>
+
   </schemalist>
 </gconfschemafile>
Index: composer/e-msg-composer.h
===================================================================
--- composer/e-msg-composer.h	(revision 34477)
+++ composer/e-msg-composer.h	(working copy)
@@ -196,6 +196,10 @@
 
 struct _EAttachmentBar*          e_msg_composer_get_attachment_bar                (EMsgComposer *composer);
 
+void                     e_msg_composer_set_attach_path                  (EMsgComposer *composer, const gchar *path);
+const gchar *            e_msg_composer_get_attach_path                  (EMsgComposer *composer);
+
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
Index: composer/ChangeLog
===================================================================
--- composer/ChangeLog	(revision 34477)
+++ composer/ChangeLog	(working copy)
@@ -1,3 +1,21 @@
+2007-11-01  Milan Crha  <mcrha@redhat.com>
+
+	** Part of fix for bug #271551
+
+	* e-msg-composer.h: (e_msg_composer_set_attach_path),
+	(e_msg_composer_get_attach_path):
+	* e-msg-composer.c: (e_msg_composer_set_attach_path),
+	(e_msg_composer_get_attach_path):
+	Functions to set/get attach path to both composer and editor.
+	* e-msg-composer.c: (prepare_engine):
+	Set last used path right after creation of the engine.
+	* e-msg-composer-select-file.c: (get_selector), (select_file_response),
+	(select_attach_response): Using new functions.
+	* listener.c: (impl_event): Store new file path when received event
+	about its change.
+
+	* e-msg-composer.c: (set_signature_gui): Leak fix.
+
 2007-11-01  Milan Crha  <mcrha@redhat.com>
 
 	** Fix for bug #318592
Index: composer/listener.c
===================================================================
--- composer/listener.c	(revision 34477)
+++ composer/listener.c	(working copy)
@@ -119,6 +119,8 @@
 			
 	} else if (!strcmp (name, "link_clicked")) {
 		e_msg_composer_link_clicked (l->composer, BONOBO_ARG_GET_STRING (arg));
+	} else if (!strcmp (name, "file_path_changed")) {
+		e_msg_composer_set_attach_path (l->composer, e_msg_composer_get_attach_path (l->composer));
 	}
 
 	return rv ? rv : get_any_null ();
Index: composer/e-msg-composer-select-file.c
===================================================================
--- composer/e-msg-composer-select-file.c	(revision 34476)
+++ composer/e-msg-composer-select-file.c	(working copy)
@@ -58,9 +58,9 @@
 	GtkWidget *selection;
 	GtkWidget *showinline = NULL;
 	GList *icon_list;
-	char *path;
+	const char *path;
 	
-	path = g_object_get_data ((GObject *) composer, "attach_path");
+	path = e_msg_composer_get_attach_path (composer);
 	
 	if (flags & SELECTOR_MODE_SAVE)
 		selection = gtk_file_chooser_dialog_new (title,
@@ -120,7 +120,8 @@
 
 		name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (selector));
 		path = g_path_get_dirname (gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (selector)));
-		g_object_set_data_full ((GObject *) composer, "attach_path", path, g_free);
+		e_msg_composer_set_attach_path (composer, path);
+		g_free (path);
 
 		func(composer, name);
 	}
@@ -172,7 +173,8 @@
 			g_free (filename);
 		}
 		if (path)
-			g_object_set_data_full ((GObject *) composer, "attach_path", path, g_free);
+			e_msg_composer_set_attach_path (composer, path);
+		g_free (path);
 
 		func(composer, names, gtk_toggle_button_get_active(showinline));
 		
Index: composer/e-msg-composer.c
===================================================================
--- composer/e-msg-composer.c	(revision 34477)
+++ composer/e-msg-composer.c	(working copy)
@@ -86,6 +86,7 @@
 #include "misc/e-expander.h"
 #include "e-util/e-error.h"
 #include "e-util/e-util-private.h"
+#include "e-util/e-util.h"
 #include <mail/em-event.h> 
 
 #include <camel/camel-session.h>
@@ -1058,6 +1059,12 @@
 
 			p->eeditor_engine = CORBA_OBJECT_NIL;
 			g_warning ("Can't establish Editor Listener\n");
+		} else {
+			gchar *path = e_file_get_composer_path ();
+
+			if (path)
+				e_msg_composer_set_attach_path (composer, path);
+			g_free (path);
 		}
 	} else {
 		p->eeditor_engine = CORBA_OBJECT_NIL;
@@ -1067,6 +1074,61 @@
 	CORBA_exception_free (&ev);
 }
 
+/**
+ * e_msg_composer_set_attach_path
+ * Attach path is used to be preset when choosing files. This function ensures same path
+ * in editor and in composer.
+ * @param composer Composer.
+ * @param path Path to be used.
+ **/
+void
+e_msg_composer_set_attach_path (EMsgComposer *composer, const gchar *path)
+{
+	g_return_if_fail (composer != NULL);
+
+	e_file_set_composer_path (path);
+	g_object_set_data_full ((GObject *) composer, "attach_path", g_strdup (path), g_free);
+
+	if (composer->priv->eeditor_engine) {
+		CORBA_Environment ev;
+
+		CORBA_exception_init (&ev);
+	
+		GNOME_GtkHTML_Editor_Engine_setFilePath (composer->priv->eeditor_engine, path, &ev);
+
+		CORBA_exception_free (&ev);
+	}
+}
+
+/**
+ * e_msg_composer_get_attach_path
+ * Last path, if any, used to select file.
+ * @param composer Composer.
+ * @return Last used path, or NULL when not set yet.
+ **/
+const gchar *
+e_msg_composer_get_attach_path (EMsgComposer *composer)
+{
+	g_return_val_if_fail (composer != NULL, NULL);
+
+	if (composer->priv->eeditor_engine) {
+		char *str;
+		CORBA_Environment ev;
+
+		CORBA_exception_init (&ev);
+
+		str = GNOME_GtkHTML_Editor_Engine_getFilePath (composer->priv->eeditor_engine, &ev);
+		if (ev._major == CORBA_NO_EXCEPTION && str)
+			e_msg_composer_set_attach_path (composer, str);
+		if (str)
+			CORBA_free (str);
+
+		CORBA_exception_free (&ev);
+	}
+
+	return g_object_get_data ((GObject *) composer, "attach_path");
+}
+
 static char *
 encode_signature_name (const char *name)
 {
@@ -4504,6 +4566,7 @@
 				p->signature = mail_config_get_signature_by_name (name);
 				g_free (name);
 			}
+			CORBA_free (str);
 		}
 		
 		sig_select_item (composer);
Index: e-util/ChangeLog
===================================================================
--- e-util/ChangeLog	(revision 34476)
+++ e-util/ChangeLog	(working copy)
@@ -1,3 +1,11 @@
+2007-11-01  Milan Crha  <mcrha@redhat.com>
+
+	** Part of fix for bug #271551
+
+	* e-util.h: (e_file_set_composer_path), (e_file_get_composer_path):
+	* e-util.c: (e_file_set_composer_path), (e_file_get_composer_path):
+	New functions to store/restore last path used in composer.
+
 2007-10-26  Sankar P  <psankar@novell.com>
 
 	** Fix for bug #461272
Index: e-util/e-util.c
===================================================================
--- e-util/e-util.c	(revision 34476)
+++ e-util/e-util.c	(working copy)
@@ -912,3 +912,43 @@
 	return (uri);
 }
 
+/**
+ * e_file_set_composer_path
+ * Stores last used path used in composer to attach files or images.
+ * Pair function for this is @ref e_file_get_composer_path.
+ *
+ * @param new_path New path to store, can be NULL, which will erase last stored path.
+ **/
+void
+e_file_set_composer_path (const gchar *new_path)
+{
+	GConfClient *gconf = gconf_client_get_default ();
+
+	gconf_client_set_string (gconf, "/apps/evolution/mail/composer/current_folder", new_path ? new_path : "", NULL);
+	g_object_unref (gconf);
+}
+
+/**
+ * e_file_get_composer_path
+ * Reads last stored path, or NULL if none set. Returned pointer should be freed with g_free.
+ * Pair function for this is @ref e_file_set_composer_path.
+ *
+ * @return Newly allocated string with last used patch or NULL if none.
+ *         Returned pointer should be freed with g_free.
+ **/
+gchar *
+e_file_get_composer_path (void)
+{
+	GConfClient *gconf = gconf_client_get_default ();
+	gchar *path;
+
+	path = gconf_client_get_string (gconf, "/apps/evolution/mail/composer/current_folder", NULL);
+	g_object_unref (gconf);
+
+	if (path && !*path) {
+		g_free (path);
+		path = NULL;
+	}
+
+	return path;
+}
Index: e-util/e-util.h
===================================================================
--- e-util/e-util.h	(revision 34476)
+++ e-util/e-util.h	(working copy)
@@ -107,6 +107,9 @@
 						 gboolean free);
 gchar *		e_file_get_save_path		(void);
 
+void		e_file_set_composer_path	(const gchar *new_path);
+gchar *		e_file_get_composer_path	(void);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
