8 #define UNREAD_MAIL 0x02
11 static guint32 timer
= 0;
12 static GtkWidget
*mail
= NULL
;
14 static gint
check_mail()
16 static off_t oldsize
= 0;
22 filename
= g_getenv("MAIL");
24 filename
= g_strconcat("/var/spool/mail/", g_get_user_name(), NULL
);
26 filename
= g_strdup(filename
);
28 if (stat(filename
, &s
) < 0) {
34 if (newsize
) ret
|= ANY_MAIL
;
35 if (s
.st_mtime
> s
.st_atime
&& newsize
) ret
|= UNREAD_MAIL
;
36 if (newsize
!= oldsize
&& (ret
& UNREAD_MAIL
)) ret
|= NEW_MAIL
;
49 static gboolean
check_timeout(gpointer data
)
51 gint count
= check_mail();
60 /* guess we better build it then :P */
61 GList
*tmp
= gtk_container_children(GTK_CONTAINER(blist
));
62 GtkWidget
*vbox2
= (GtkWidget
*)tmp
->data
;
64 mail
= gtk_label_new("No mail messages.");
65 gtk_box_pack_start(GTK_BOX(vbox2
), mail
, FALSE
, FALSE
, 0);
66 gtk_box_reorder_child(GTK_BOX(vbox2
), mail
, 1);
67 gtk_signal_connect(GTK_OBJECT(mail
), "destroy", GTK_SIGNAL_FUNC(maildes
), NULL
);
68 gtk_widget_show(mail
);
72 play_sound(POUNCE_DEFAULT
);
74 if (count
& UNREAD_MAIL
)
75 gtk_label_set_text(GTK_LABEL(mail
), "You have new mail!");
76 else if (count
& ANY_MAIL
)
77 gtk_label_set_text(GTK_LABEL(mail
), "You have mail.");
79 gtk_label_set_text(GTK_LABEL(mail
), "No mail messages.");
84 static void mail_signon(struct gaim_connection
*gc
)
87 timer
= gtk_timeout_add(2000, check_timeout
, NULL
);
90 static void mail_signoff(struct gaim_connection
*gc
)
92 if (!blist
&& timer
) {
93 gtk_timeout_remove(timer
);
98 char *gaim_plugin_init(GModule
*m
)
100 if (!check_timeout(NULL
))
101 return "Could not read $MAIL or /var/spool/mail/$USER";
103 timer
= gtk_timeout_add(2000, check_timeout
, NULL
);
104 gaim_signal_connect(m
, event_signon
, mail_signon
, NULL
);
105 gaim_signal_connect(m
, event_signoff
, mail_signoff
, NULL
);
109 void gaim_plugin_remove()
112 gtk_timeout_remove(timer
);
115 gtk_widget_destroy(mail
);
126 return "Checks for new local mail";