aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
Diffstat (limited to 'mail')
-rw-r--r--mail/ChangeLog13
-rw-r--r--mail/Makefile.am10
-rw-r--r--mail/folder-browser-factory.c24
-rw-r--r--mail/mail-ops.c185
-rw-r--r--mail/mail-ops.h1
5 files changed, 215 insertions, 18 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 6877b6f8f9..04252f2d55 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,16 @@
+2000-04-07 Dan Winship <danw@helixcode.com>
+
+ * mail-ops.c: new file, for toolbar/menu callbacks
+ (fetch_mail): fetch mail. Doesn't do mbox locking. Many kludges.
+
+ * folder-browser-factory.c (control_activate): use new fetch_mail
+ function as the callback for the "New mail" icon. Rename check_cb
+ to random_cb.
+
+ * Makefile.am: don't build test-sources since the version in
+ CVS doesn't do much and once I've fixed it it won't be a separate
+ program. Add mail-ops.[ch].
+
2000-04-06 Miguel de Icaza <miguel@gnu.org>
* message-list.c: Stick pixmaps here.
diff --git a/mail/Makefile.am b/mail/Makefile.am
index 707d514af3..189faf1dcd 100644
--- a/mail/Makefile.am
+++ b/mail/Makefile.am
@@ -1,4 +1,4 @@
-bin_PROGRAMS = evolution-mail test-mail test-sources
+bin_PROGRAMS = evolution-mail test-mail
providerdir = $(libdir)/evolution/camel-providers/$(VERSION)
@@ -33,6 +33,8 @@ evolution_mail_SOURCES = \
html-stream.h \
mail-display.h \
mail-display.c \
+ mail-ops.c \
+ mail-ops.h \
main.c \
message-list.c \
message-list.h \
@@ -60,12 +62,6 @@ test_mail_LDADD = \
$(BONOBO_HTML_GNOME_LIBS)
-test_sources_SOURCES = \
- mail-sources.c
-
-test_sources_LDADD = \
- $(BONOBO_HTML_GNOME_LIBS)
-
gnorbadir = $(sysconfdir)/CORBA/servers
gnorba_DATA = evolution-mail.gnorba
diff --git a/mail/folder-browser-factory.c b/mail/folder-browser-factory.c
index 787e504693..8e2b7ec8f7 100644
--- a/mail/folder-browser-factory.c
+++ b/mail/folder-browser-factory.c
@@ -21,6 +21,7 @@
#include "shell/evolution-service-repository.h"
#include "composer/e-msg-composer.h"
#include <camel/camel-stream-fs.h>
+#include "mail-ops.h"
static void
@@ -133,7 +134,7 @@ msg_composer_cb (BonoboUIHandler *uih, void *user_data, const char *path)
}
static void
-check_cb (BonoboUIHandler *uih, void *user_data, const char *path)
+random_cb (GtkWidget *button, gpointer user_data)
{
printf ("Yow! I am called back!\n");
}
@@ -143,7 +144,7 @@ static void
control_activate (BonoboControl *control, BonoboUIHandler *uih)
{
Bonobo_UIHandler remote_uih;
- GtkWidget *toolbar;
+ GtkWidget *toolbar, *folder_browser;
remote_uih = bonobo_control_get_remote_ui_handler (control);
bonobo_ui_handler_set_container (uih, remote_uih);
@@ -155,45 +156,46 @@ control_activate (BonoboControl *control, BonoboUIHandler *uih)
toolbar = gtk_toolbar_new (GTK_ORIENTATION_HORIZONTAL,
GTK_TOOLBAR_BOTH);
+ folder_browser = bonobo_control_get_widget (control);
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "New mail",
"Check for new mail", NULL,
gnome_stock_new_with_icon (GNOME_STOCK_PIXMAP_MAIL_RCV),
- check_cb, NULL);
+ fetch_mail, folder_browser);
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Send",
"Send a new message", NULL,
gnome_stock_new_with_icon (GNOME_STOCK_PIXMAP_MAIL_SND),
- check_cb, NULL);
+ random_cb, folder_browser);
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Find",
"Find messages", NULL,
gnome_stock_new_with_icon (GNOME_STOCK_PIXMAP_SEARCH),
- check_cb, NULL);
+ random_cb, folder_browser);
gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Reply",
"Reply to the sender of this message", NULL,
gnome_stock_new_with_icon (GNOME_STOCK_PIXMAP_MAIL_RPL),
- check_cb, NULL);
+ random_cb, folder_browser);
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Reply to All",
"Reply to all recipients of this message", NULL,
gnome_stock_new_with_icon (GNOME_STOCK_PIXMAP_MAIL_RPL),
- check_cb, NULL);
+ random_cb, folder_browser);
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Forward",
"Forward this message", NULL,
gnome_stock_new_with_icon (GNOME_STOCK_PIXMAP_MAIL_FWD),
- check_cb, NULL);
+ random_cb, folder_browser);
gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Print",
"Print the selected message", NULL,
gnome_stock_new_with_icon (GNOME_STOCK_PIXMAP_PRINT),
- check_cb, NULL);
+ random_cb, folder_browser);
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Delete",
"Delete this message", NULL,
gnome_stock_new_with_icon (GNOME_STOCK_PIXMAP_TRASH),
- check_cb, NULL);
+ random_cb, folder_browser);
gtk_widget_show_all (toolbar);
bonobo_ui_handler_dock_add (uih, "/Toolbar",
- bonobo_object_corba_objref (bonobo_control_new (toolbar)),
+ bonobo_object_corba_objref (BONOBO_OBJECT (bonobo_control_new (toolbar))),
GNOME_DOCK_ITEM_BEH_LOCKED |
GNOME_DOCK_ITEM_BEH_EXCLUSIVE,
GNOME_DOCK_TOP,
diff --git a/mail/mail-ops.c b/mail/mail-ops.c
new file mode 100644
index 0000000000..405eddec4b
--- /dev/null
+++ b/mail/mail-ops.c
@@ -0,0 +1,185 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* mail-ops.c: callbacks for the mail toolbar/menus */
+
+/*
+ * Author :
+ * Dan Winship <danw@helixcode.com>
+ *
+ * Copyright 2000 Helix Code, Inc. (http://www.helixcode.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#include <config.h>
+#include <gnome.h>
+#include "camel/camel.h"
+#include "mail-ops.h"
+#include "folder-browser.h"
+#include "session.h"
+#include "e-util/e-setup.h"
+
+static void
+mail_exception_dialog (char *head, CamelException *ex, GtkWindow *window)
+{
+ char *msg;
+
+ msg = g_strdup_printf ("%s:\n%s", head,
+ camel_exception_get_description (ex));
+ gnome_error_dialog_parented (msg, window);
+ g_free (msg);
+}
+
+void
+fetch_mail (GtkWidget *button, gpointer user_data)
+{
+ FolderBrowser *fb = FOLDER_BROWSER (user_data);
+ GtkWindow *window;
+ CamelException *ex;
+ CamelStore *store = NULL;
+ CamelFolder *folder = NULL, *outfolder = NULL;
+ int nmsgs, i;
+ CamelMimeMessage *msg = NULL;
+ char *path, *url = NULL, *provider;
+ gboolean get_remote;
+
+ window = GTK_WINDOW (gtk_widget_get_ancestor (GTK_WIDGET (fb),
+ GTK_TYPE_WINDOW));
+
+ /* FIXME: We want a better config solution than this. */
+ path = g_strdup_printf ("=%s/config=/mail/get_remote", evolution_dir);
+ get_remote = gnome_config_get_bool_with_default (path, FALSE);
+ g_free (path);
+ path = g_strdup_printf ("=%s/config=/mail/remote_url", evolution_dir);
+ url = gnome_config_get_string_with_default (path, NULL);
+ g_free (path);
+ if (!get_remote || !url) {
+ if (url)
+ g_free (url);
+ gnome_error_dialog_parented ("You have no remote mail source "
+ "configured", window);
+ return;
+ }
+
+ /* FIXME: this should go away when the provider situation is
+ * improved.
+ */
+ path = g_strdup_printf ("=%s/config=/mail/remote_provider",
+ evolution_dir);
+ provider = gnome_config_get_string_with_default (path, NULL);
+ g_free (path);
+ if (provider) {
+ camel_provider_register_as_module (provider);
+ g_free (provider);
+ }
+
+ ex = camel_exception_new ();
+ store = camel_session_get_store (default_session->session, url, ex);
+ if (!store) {
+ mail_exception_dialog ("Unable to get new mail", ex, window);
+ goto cleanup;
+ }
+ camel_service_connect_with_url (CAMEL_SERVICE (store), url, ex);
+ if (camel_exception_get_id (ex) != CAMEL_EXCEPTION_NONE) {
+ mail_exception_dialog ("Unable to get new mail", ex, window);
+ goto cleanup;
+ }
+
+ folder = camel_store_get_folder (store, "inbox", ex);
+ if (!folder) {
+ mail_exception_dialog ("Unable to get new mail", ex, window);
+ goto cleanup;
+ }
+ camel_folder_open (folder, FOLDER_OPEN_READ, ex);
+ if (camel_exception_get_id (ex) != CAMEL_EXCEPTION_NONE) {
+ mail_exception_dialog ("Unable to get new mail", ex, window);
+ goto cleanup;
+ }
+
+ nmsgs = camel_folder_get_message_count (folder, ex);
+ if (camel_exception_get_id (ex) != CAMEL_EXCEPTION_NONE) {
+ mail_exception_dialog ("Unable to get new mail", ex, window);
+ goto cleanup;
+ }
+
+ if (nmsgs == 0)
+ goto cleanup;
+
+ outfolder = camel_store_get_folder (default_session->store,
+ "inbox", ex);
+ if (camel_exception_get_id (ex) != CAMEL_EXCEPTION_NONE) {
+ mail_exception_dialog ("Unable to open inbox to store mail",
+ ex, window);
+ goto cleanup;
+ }
+ camel_folder_open (outfolder, FOLDER_OPEN_WRITE, ex);
+ if (camel_exception_get_id (ex) != CAMEL_EXCEPTION_NONE) {
+ mail_exception_dialog ("Unable to open inbox to store mail",
+ ex, window);
+ goto cleanup;
+ }
+
+ for (i = 1; i <= nmsgs; i++) {
+ msg = camel_folder_get_message_by_number (folder, i, ex);
+ if (camel_exception_get_id (ex) != CAMEL_EXCEPTION_NONE) {
+ mail_exception_dialog ("Unable to read message",
+ ex, window);
+ goto cleanup;
+ }
+
+ camel_folder_append_message (outfolder, msg, ex);
+ if (camel_exception_get_id (ex) != CAMEL_EXCEPTION_NONE) {
+ mail_exception_dialog ("Unable to write message",
+ ex, window);
+ goto cleanup;
+ }
+
+ camel_folder_delete_message_by_number (folder, i, ex);
+ if (camel_exception_get_id (ex) != CAMEL_EXCEPTION_NONE) {
+ mail_exception_dialog ("Unable to delete message",
+ ex, window);
+ goto cleanup;
+ }
+ }
+ msg = NULL;
+
+ folder_browser_set_uri (fb, "inbox"); /* FIXME */
+
+ cleanup:
+ if (url)
+ g_free (url);
+ if (folder) {
+ if (camel_folder_is_open (folder))
+ camel_folder_close (folder, TRUE, ex);
+ gtk_object_unref (GTK_OBJECT (folder));
+ }
+ if (store) {
+ camel_service_disconnect (CAMEL_SERVICE (store), ex);
+ gtk_object_unref (GTK_OBJECT (store));
+ }
+#if 0
+ /* FIXME: we'll want to do this when the rest of the mail
+ * stuff is refcounting things properly.
+ */
+ if (outfolder) {
+ if (camel_folder_is_open (outfolder))
+ camel_folder_close (outfolder, FALSE, ex);
+ gtk_object_unref (GTK_OBJECT (outfolder));
+ }
+#endif
+ camel_exception_free (ex);
+ if (msg)
+ gtk_object_unref (GTK_OBJECT (msg));
+}
diff --git a/mail/mail-ops.h b/mail/mail-ops.h
new file mode 100644
index 0000000000..ed85f4d5a0
--- /dev/null
+++ b/mail/mail-ops.h
@@ -0,0 +1 @@
+void fetch_mail (GtkWidget *button, gpointer user_data);