diff --git a/mail/importers/Makefile.am b/mail/importers/Makefile.am
index d9beee9..9b112b3 100644
--- a/mail/importers/Makefile.am
+++ b/mail/importers/Makefile.am
@@ -13,6 +13,9 @@ libevolution_mail_importers_la_CPPFLAGS = \
 	$(NULL)
 
 libevolution_mail_importers_la_SOURCES =	\
+	kmail-importer.c                        \
+	kmail-libs.c                            \
+	kmail-libs.h                            \
 	mail-importer.c				\
 	mail-importer.h				\
 	elm-importer.c				\
diff --git a/mail/importers/mail-importer.c b/mail/importers/mail-importer.c
index aad2754..598f200 100644
--- a/mail/importers/mail-importer.c
+++ b/mail/importers/mail-importer.c
@@ -21,6 +21,7 @@
  */
 
 #include "mail-importer.h"
+#include "kmail-libs.h"
 
 #include <config.h>
 #include <errno.h>
@@ -35,6 +36,10 @@
 
 #include "e-util/e-util-private.h"
 #include "shell/e-shell-backend.h"
+#include "libemail-engine/mail-mt.h"
+#include "libemail-engine/mail-tools.h"
+#include "libemail-engine/e-mail-session.h"
+
 
 struct _import_mbox_msg {
 	MailMsg base;
@@ -54,6 +59,12 @@ import_mbox_desc (struct _import_mbox_msg *m)
 	return g_strdup (_("Importing mailbox"));
 }
 
+static gchar *
+import_maildir_desc (struct _import_mbox_msg *m)
+{
+	return g_strdup (_("Importing maildir"));
+}
+
 static struct {
 	gchar tag;
 	guint32 mozflag;
@@ -95,10 +106,147 @@ decode_mozilla_status (const gchar *tmp)
 	return flags;
 }
 
+ static void
+import_maildir_folder (struct _import_mbox_msg *m,
+		 gchar *k_path,
+		  GCancellable *cancellable,
+		  GError **error)
+{
+	const gchar *special_folders []= {"cur", "tmp", "new", NULL};
+       gchar *special_path;
+	const CamelStore *store;
+       CamelFolder *folder;
+       CamelMimeParser *mp = NULL;
+       CamelMessageInfo *info;
+       CamelMimeMessage *msg;
+       guint32 flags = 0;
+
+       gchar *e_uri, *e_path;
+
+       const gchar *d;
+       gchar *mail_url;
+       GDir *dir;
+       struct stat st;
+       gint fd, i;
+
+       e_uri = kuri_to_euri (k_path);
+       /* we need to drop some folders, like: Trash */
+       if (!e_uri)
+	       return;
+
+       store = evolution_get_local_store ();
+       e_path = e_uri + strlen (EVOLUTION_LOCAL_BASE) + 1;
+       e_mail_store_create_folder_sync ((CamelStore *)store, e_path, NULL, NULL);
+
+       folder = e_mail_session_uri_to_folder_sync (
+		       m->session, e_uri, CAMEL_STORE_FOLDER_CREATE,
+		       cancellable, NULL);
+
+       if (folder == NULL) {
+	       g_warning ("evolution error: cannot get the folder\n");
+	       return;
+	}
+
+
+       camel_operation_push_message (
+		       m->cancellable, _("Importing '%s'"),
+		       camel_folder_get_display_name (folder));
+       camel_folder_freeze (folder);
+
+       for (i = 0; special_folders [i]; i++) {
+	       camel_operation_progress (m->cancellable, 100*i/3);
+	       special_path = g_build_filename (k_path, special_folders[i], NULL);
+	       dir = g_dir_open (special_path, 0, NULL);
+	       while ((d = g_dir_read_name (dir))) {
+		       if ((strcmp (d, ".") == 0) || (strcmp (d, "..") == 0)) {
+			       continue;
+		       }
+			mail_url = g_build_filename (special_path, d, NULL);
+			if (g_stat (mail_url, &st) == -1) {
+				g_free (mail_url);
+				continue;
+			}
+			if (S_ISREG (st.st_mode)) {
+			       fd = g_open (mail_url, O_RDONLY | O_BINARY, 0);
+			       g_free (mail_url);
+			       if (fd == -1) {
+				       continue;
+			       }
+			       mp = camel_mime_parser_new ();
+			       camel_mime_parser_scan_from (mp, FALSE);
+			       if (camel_mime_parser_init_with_fd (mp, fd) == -1) {
+				       /* will never happen - 0 is unconditionally returned */
+				       g_object_unref (mp);
+				       continue;
+			       }
+
+			       msg = camel_mime_message_new ();
+			       if (!camel_mime_part_construct_from_parser_sync (
+				       (CamelMimePart *) msg, mp, NULL, NULL)) {
+				       /* set exception? */
+				       g_object_unref (mp);
+				       g_object_unref (msg);
+				       continue;
+				       
+			       }
+			       info = camel_message_info_new (NULL);
+			       if (strcmp (special_folders[i], "cur") == 0) {
+				       flags |= CAMEL_MESSAGE_SEEN;
+			       } else if (strcmp (special_folders[i], "tmp") == 0) {
+				       flags |= CAMEL_MESSAGE_DELETED; /* FIXME */
+			       }
+			       camel_message_info_set_flags (info, flags, ~0);
+			       camel_folder_append_message_sync (
+				       folder, msg, info, NULL,
+				       cancellable, error);
+
+			       camel_message_info_free (info);
+			       g_object_unref (msg);
+			       g_object_unref (mp);
+		       } else {
+			       g_free (mail_url);
+		       }
+	       }
+       }
+       camel_operation_progress (m->cancellable, 100);
+       camel_folder_synchronize_sync (folder, FALSE, NULL, NULL);
+       camel_folder_thaw (folder);
+       camel_operation_pop_message (m->cancellable);
+}
+
+static void
+import_maildir_exec (struct _import_mbox_msg *m,
+		  GCancellable *cancellable,
+		  GError **error)
+{
+       GSList *list, *l;
+       gchar *folder;
+       struct stat st;
+
+       if (g_stat (m->path, &st) == -1) {
+	       g_warning (
+		       "cannot find source file to import '%s': %s",
+		       m->path, g_strerror (errno));
+	       return;
+       }
+       if (!S_ISDIR (st.st_mode)) {
+	       g_warning (
+		       "the source path '%s' is not a directory.",
+		       m->path);
+	       return;
+       }
+
+       list = get_kmail_folders (m->path);
+       for (l = list; l; l = l->next) {
+	       folder = (gchar *) l->data;
+	       import_maildir_folder (m, folder, cancellable, NULL);
+       }
+}
+
 static void
 import_mbox_exec (struct _import_mbox_msg *m,
-                  GCancellable *cancellable,
-                  GError **error)
+		  GCancellable *cancellable,
+		  GError **error)
 {
 	CamelFolder *folder;
 	CamelMimeParser *mp = NULL;
@@ -222,6 +370,84 @@ import_mbox_free (struct _import_mbox_msg *m)
 	g_free (m->path);
 }
 
+static void
+import_maildir_done (struct _import_mbox_msg *m)
+{
+       if (m->done)
+	       m->done (m->done_data, &m->base.error);
+}
+
+static void
+import_maildir_free (struct _import_mbox_msg *m)
+{
+       g_object_unref (m->session);
+       if (m->cancellable)
+	       g_object_unref (m->cancellable);
+       g_free (m->uri);
+       g_free (m->path);
+}
+
+/*only difference with mbox_info is: _exec
+  but I put it into to different info. */
+static MailMsgInfo import_maildir_info = {
+       sizeof (struct _import_mbox_msg),
+       (MailMsgDescFunc) import_maildir_desc,
+       (MailMsgDescFunc) import_maildir_exec,
+       (MailMsgDoneFunc) import_maildir_done,
+       (MailMsgFreeFunc) import_maildir_free
+};
+
+gint
+mail_importer_import_maildir (EMailSession *session,
+			   const gchar *path,	  /* path is basedir */
+			   const gchar *folderuri,     /* not used now, use it when the user want to port to a certain folder */
+			   GCancellable *cancellable,
+			   void (*done) (gpointer data,
+					 GError **error),
+			   gpointer data)
+{
+       struct _import_mbox_msg *m;
+       gint id;
+
+       m = mail_msg_new (&import_maildir_info);
+       m->session = g_object_ref (session);
+       m->path = g_strdup (path);
+       m->uri = g_strdup (folderuri);
+       m->done = done;
+       m->done_data = data;
+       if (cancellable)
+	       m->cancellable = g_object_ref (cancellable);
+
+       id = m->base.seq;
+       mail_msg_fast_ordered_push (m);
+
+       return id;
+}
+
+void
+mail_importer_import_maildir_sync (EMailSession *session,
+				const gchar *path,
+				const gchar *folderuri,
+				GCancellable *cancellable)
+{
+       struct _import_mbox_msg *m;
+
+       m = mail_msg_new (&import_maildir_info);
+       m->session = g_object_ref (session);
+       m->path = g_strdup (path);
+       if (folderuri)
+	       m->uri = g_strdup (folderuri);
+       else
+	       m->uri = NULL;
+       if (cancellable)
+	       m->base.cancellable = cancellable;
+
+       cancellable = m->base.cancellable;
+       import_maildir_exec (m, cancellable, &m->base.error);
+       import_maildir_done (m);
+       mail_msg_unref (m);
+}
+
 static MailMsgInfo import_mbox_info = {
 	sizeof (struct _import_mbox_msg),
 	(MailMsgDescFunc) import_mbox_desc,
diff --git a/mail/importers/mail-importer.h b/mail/importers/mail-importer.h
index fe2a1e3..a650ef5 100644
--- a/mail/importers/mail-importer.h
+++ b/mail/importers/mail-importer.h
@@ -38,6 +38,7 @@ void mbox_importer_set_preview_funcs (MboxImporterCreatePreviewFunc create_func,
 
 EImportImporter *elm_importer_peek (void);
 EImportImporter *pine_importer_peek (void);
+EImportImporter *kmail_importer_peek (void);
 
 /* Defines copied from nsMsgMessageFlags.h in Mozilla source. */
 /* Evolution only cares about these headers I think */
@@ -56,6 +57,16 @@ void		mail_importer_import_mbox_sync	(EMailSession *session,
 						 const gchar *path,
 						 const gchar *folderuri,
 						 GCancellable *cancellable);
+gint            mail_importer_import_maildir    (EMailSession *session,
+                                                 const gchar *path,
+                                                 const gchar *folderuri,
+                                                 GCancellable *cancellable,
+                                                 void (*done)(gpointer data, GError **),
+                                                 gpointer data);
+void            mail_importer_import_maildir_sync       (EMailSession *session,
+                                                 const gchar *path,
+                                                 const gchar *folderuri,
+                                                 GCancellable *cancellable);
 
 struct _MailImporterSpecial {
 	const gchar *orig, *new;
