annotate plugins/mailchk.c @ 1951:44eeb8828198

[gaim-migrate @ 1961] rob, your formatting seems off today.... committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Sat, 02 Jun 2001 00:17:38 +0000
parents c7b288ea3892
children 866bf3ced1bc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1803
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1 #define GAIM_PLUGINS
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2 #include "gaim.h"
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3 #include <sys/stat.h>
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4 #include <sys/types.h>
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
5 #include <unistd.h>
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
6
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7 #define ANY_MAIL 0x01
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8 #define UNREAD_MAIL 0x02
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9 #define NEW_MAIL 0x04
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11 static guint32 timer = 0;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12 static GtkWidget *mail = NULL;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
13
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
14 static gint check_mail()
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15 {
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16 static off_t oldsize = 0;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
17 gchar *filename;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
18 off_t newsize;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
19 struct stat s;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
20 gint ret = 0;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
21
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
22 filename = g_getenv("MAIL");
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
23 if (!filename)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
24 filename = g_strconcat("/var/spool/mail/", g_get_user_name(), NULL);
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
25 else
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
26 filename = g_strdup(filename);
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
27
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
28 if (stat(filename, &s) < 0) {
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
29 g_free(filename);
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
30 return -1;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
31 }
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
32
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
33 newsize = s.st_size;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
34 if (newsize) ret |= ANY_MAIL;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35 if (s.st_mtime > s.st_atime && newsize) ret |= UNREAD_MAIL;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36 if (newsize != oldsize && (ret & UNREAD_MAIL)) ret |= NEW_MAIL;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37 oldsize = newsize;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
38
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
39 g_free(filename);
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
40
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
41 return ret;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
42 }
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
43
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
44 static void maildes()
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
45 {
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
46 mail = NULL;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
47 }
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
48
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49 static gboolean check_timeout(gpointer data)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50 {
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
51 gint count = check_mail();
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52 char buf[256];
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
53
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
54 if (count == -1)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
55 return FALSE;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
56
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
57 if (!blist)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
58 return TRUE;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
59
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
60 if (!mail) {
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
61 /* guess we better build it then :P */
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
62 GList *tmp = gtk_container_children(GTK_CONTAINER(blist));
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
63 GtkWidget *vbox2 = (GtkWidget *)tmp->data;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
64
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
65 mail = gtk_label_new("No mail messages.");
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
66 gtk_box_pack_start(GTK_BOX(vbox2), mail, FALSE, FALSE, 0);
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
67 gtk_box_reorder_child(GTK_BOX(vbox2), mail, 1);
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
68 gtk_signal_connect(GTK_OBJECT(mail), "destroy", GTK_SIGNAL_FUNC(maildes), NULL);
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
69 gtk_widget_show(mail);
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
70 }
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
71
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
72 if (count & NEW_MAIL)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
73 play_sound(POUNCE_DEFAULT);
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
74
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
75 if (count & UNREAD_MAIL)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
76 gtk_label_set_text(GTK_LABEL(mail), "You have new mail!");
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
77 else if (count & ANY_MAIL)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
78 gtk_label_set_text(GTK_LABEL(mail), "You have mail.");
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
79 else
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
80 gtk_label_set_text(GTK_LABEL(mail), "No mail messages.");
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
81
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
82 return TRUE;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
83 }
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
84
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
85 static void mail_signon(struct gaim_connection *gc)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
86 {
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
87 if (blist && !timer)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
88 timer = gtk_timeout_add(2000, check_timeout, NULL);
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
89 }
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
90
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
91 static void mail_signoff(struct gaim_connection *gc)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
92 {
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
93 if (timer)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
94 gtk_timeout_remove(timer);
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
95 timer = 0;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
96 }
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
97
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
98 char *gaim_plugin_init(GModule *m)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
99 {
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
100 if (!check_timeout(NULL))
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
101 return "Could not read $MAIL or /var/spool/mail/$USER";
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
102 if (blist)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
103 timer = gtk_timeout_add(2000, check_timeout, NULL);
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
104 gaim_signal_connect(m, event_signon, mail_signon, NULL);
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
105 gaim_signal_connect(m, event_signoff, mail_signoff, NULL);
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
106 return NULL;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
107 }
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
108
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
109 void gaim_plugin_remove()
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
110 {
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
111 if (timer)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
112 gtk_timeout_remove(timer);
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
113 timer = 0;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
114 if (mail)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
115 gtk_widget_destroy(mail);
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
116 mail = NULL;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
117 }
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
118
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
119 char *name()
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
120 {
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
121 return "Mail Check";
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
122 }
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
123
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
124 char *description()
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
125 {
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
126 return "Checks for new local mail";
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
127 }