# HG changeset patch # User Eric Warmenhoven # Date 989021723 0 # Node ID d36f759df56dbf81782d7b9d2432c833742b2244 # Parent 44e9d786a28c833dfc0057d10ed76c0c82132744 [gaim-migrate @ 1813] mailcheck plugin committer: Tailor Script diff -r 44e9d786a28c -r d36f759df56d TODO --- a/TODO Fri May 04 23:27:23 2001 +0000 +++ b/TODO Sat May 05 00:15:23 2001 +0000 @@ -20,11 +20,6 @@ it (and also move Yahoo/MSN dialog to prpl.c and have both of them use it (is this doable? Yahoo only gives message count, what does MSN give?)) - Ha. Maybe we should also add OPT_GEN_MAILCHECK to check $MAIL (or - /var/spool/mail/$USER if that fails). If we did that I could get rid - of one more applet on my gnome panel and make it almost completely - for the sole purpose of gaim_applet. (Maybe this could be a plugin? - What should the UI be for this?) Away needs to be modified to include "show" and "status", i.e. you can have an away state, and an away message. This is exactly what ICQ does - you're "N/A" (show in Jabber) and your away message is "I'm gone." diff -r 44e9d786a28c -r d36f759df56d plugins/Makefile.am --- a/plugins/Makefile.am Fri May 04 23:27:23 2001 +0000 +++ b/plugins/Makefile.am Sat May 05 00:15:23 2001 +0000 @@ -48,4 +48,4 @@ EXTRA_DIST = ChangeLog PERL-HOWTO CRAZY HOWTO SIGNALS autorecon.c error.c filectl.c \ gaiminc.c iconaway.c lagmeter.c notify.c simple.c spellchk.c \ - toc_commands.c events.c gaim.pl irc.c napster.c + toc_commands.c events.c gaim.pl irc.c napster.c mailchk.c diff -r 44e9d786a28c -r d36f759df56d plugins/mailchk.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/mailchk.c Sat May 05 00:15:23 2001 +0000 @@ -0,0 +1,128 @@ +#define GAIM_PLUGINS +#include "gaim.h" +#include +#include +#include + +#define ANY_MAIL 0x01 +#define UNREAD_MAIL 0x02 +#define NEW_MAIL 0x04 + +static guint32 timer = 0; +static GtkWidget *mail = NULL; + +static gint check_mail() +{ + static off_t oldsize = 0; + gchar *filename; + off_t newsize; + struct stat s; + gint ret = 0; + + filename = g_getenv("MAIL"); + if (!filename) + filename = g_strconcat("/var/spool/mail/", g_get_user_name(), NULL); + else + filename = g_strdup(filename); + + if (stat(filename, &s) < 0) { + g_free(filename); + return -1; + } + + newsize = s.st_size; + if (newsize) ret |= ANY_MAIL; + if (s.st_mtime > s.st_atime && newsize) ret |= UNREAD_MAIL; + if (newsize != oldsize && (ret & UNREAD_MAIL)) ret |= NEW_MAIL; + oldsize = newsize; + + g_free(filename); + + return ret; +} + +static void maildes() +{ + mail = NULL; +} + +static gboolean check_timeout(gpointer data) +{ + gint count = check_mail(); + char buf[256]; + + if (count == -1) + return FALSE; + + if (!blist) + return TRUE; + + if (!mail) { + /* guess we better build it then :P */ + GList *tmp = gtk_container_children(GTK_CONTAINER(blist)); + GtkWidget *vbox2 = (GtkWidget *)tmp->data; + + mail = gtk_label_new("No mail messages."); + gtk_label_set_justify(GTK_LABEL(mail), GTK_JUSTIFY_LEFT); + gtk_box_pack_start(GTK_BOX(vbox2), mail, FALSE, FALSE, 0); + gtk_box_reorder_child(GTK_BOX(vbox2), mail, 1); + gtk_signal_connect(GTK_OBJECT(mail), "destroy", GTK_SIGNAL_FUNC(maildes), NULL); + gtk_widget_show(mail); + } + + if (count & NEW_MAIL) + play_sound(POUNCE_DEFAULT); + + if (count & UNREAD_MAIL) + gtk_label_set_text(GTK_LABEL(mail), "You have new mail!"); + else if (count & ANY_MAIL) + gtk_label_set_text(GTK_LABEL(mail), "You have mail."); + else + gtk_label_set_text(GTK_LABEL(mail), "No mail messages."); + + return TRUE; +} + +static void mail_signon(struct gaim_connection *gc) +{ + if (blist && !timer) + timer = gtk_timeout_add(2000, check_timeout, NULL); +} + +static void mail_signoff(struct gaim_connection *gc) +{ + if (timer) + gtk_timeout_remove(timer); + timer = 0; +} + +char *gaim_plugin_init(GModule *m) +{ + if (!check_timeout(NULL)) + return "Could not read $MAIL or /var/spool/mail/$USER"; + if (blist) + timer = gtk_timeout_add(2000, check_timeout, NULL); + gaim_signal_connect(m, event_signon, mail_signon, NULL); + gaim_signal_connect(m, event_signoff, mail_signoff, NULL); + return NULL; +} + +void gaim_plugin_remove() +{ + if (timer) + gtk_timeout_remove(timer); + timer = 0; + if (mail) + gtk_widget_destroy(mail); + mail = NULL; +} + +char *name() +{ + return "Mail Check"; +} + +char *description() +{ + return "Checks for new local mail"; +}