annotate plugins/chkmail.c @ 1581:0d101ec1f68e

[gaim-migrate @ 1591] hi again committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Thu, 15 Mar 2001 16:50:45 +0000
parents 1330d0c8b1ff
children ebfb80bbe1ed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
1 /* This is some funky code. It is still being developed by Rob Flynn - rob@linuxpimps.com
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
2 * I recommend not using this code right now. :)
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
3 */
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
4
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
5 #define GAIM_PLUGINS
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
6
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
7 #include <stdio.h>
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
8 #include <stdlib.h>
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
9 #include <unistd.h>
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
10 #include <string.h>
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
11 #include <netinet/in.h>
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
12 #include <arpa/inet.h>
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
13 #include <sys/socket.h>
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
14 #include <netdb.h>
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
15 #include <netinet/in.h>
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
16 #include <pthread.h>
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
17 #include "gaim.h"
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
18
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
19 char username[] = "";
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
20 char password[] = "";
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
21 char mailhost[] = "";
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
22 int mailport = 110;
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
23 int state = 0;
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
24
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
25 static void *handle = NULL;
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
26 extern GtkWidget *buddies;
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
27
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
28 int lastnum = 0;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
29 int orig = 0;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
30 int mytimer;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
31
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
32 void update_mail();
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
33 void check_mail();
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
34
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
35 int num_msgs()
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
36 {
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
37 struct in_addr *sin;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
38 char recv[1024];
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
39 char command[256];
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
40 int fd;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
41 int num = 0;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
42 int step = 0;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
43 int len;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
44
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
45 sin = (struct in_addr *)get_address(mailhost);
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
46 fd = connect_address(sin->s_addr, mailport);
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
47 while ((len = read(fd, recv, 1023))>0) {
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
48 recv[len] = 0;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
49 if (!strncmp(recv, "-ERR", strlen("-ERR"))) { step = 4; break;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
50 } else if (!strncmp(recv, "+OK", strlen("+OK"))) {
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
51 if (step == 3) {
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
52 if (sscanf(recv, "+OK %d %d\n", &num, &step) != 2)
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
53 break;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
54 g_snprintf(command, sizeof(command), "QUIT\n");
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
55 write(fd, command, strlen(command));
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
56 close(fd);
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
57 printf("DEBUG: Num is %d\n", num);
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
58 return num;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
59 }
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
60
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
61 if (step == 0) {
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
62 g_snprintf(command, sizeof(command), "USER %s\n", username);
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
63 write(fd, command, strlen(command));
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
64 step = 1;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
65 } else if (step == 1) {
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
66 g_snprintf(command, sizeof(command), "PASS %s\n", password);
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
67 write(fd, command, strlen(command));
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
68 step = 2;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
69 } else if (step == 2) {
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
70 g_snprintf(command, sizeof(command), "STAT\n");
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
71 write(fd, command, strlen(command));
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
72 step = 3;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
73 }
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
74 }
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
75 }
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
76 close(fd);
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
77 return 0;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
78 }
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
79
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
80 void destroy_mail_list()
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
81 {
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
82 GList *list;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
83 GtkWidget *w;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
84
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
85 list = GTK_TREE(buddies)->children;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
86
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
87 while (list) {
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
88 w = (GtkWidget *)list->data;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
89 if (!strcmp(GTK_LABEL(GTK_BIN(w)->child)->label, "Mail Server")) {
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
90 gtk_tree_remove_items(GTK_TREE(buddies), list);
126
b4cd83f1d0b8 [gaim-migrate @ 136]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 124
diff changeset
91 list = GTK_TREE(buddies)->children;
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
92 if (!list)
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
93 break;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
94 }
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
95 list = list->next;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
96 }
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
97 }
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
98
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
99
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
100 void setup_mail_list()
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
101 {
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
102 GList *list;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
103 GtkWidget *w;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
104 GtkWidget *item;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
105 GtkWidget *tree;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
106 gchar *buf;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
107
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
108 list = GTK_TREE(buddies)->children;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
109
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
110 while (list) {
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
111 w = (GtkWidget *)list->data;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
112 if (!strcmp(GTK_LABEL(GTK_BIN(w)->child)->label, "Mail Server")) {
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
113 gtk_tree_remove_items(GTK_TREE(buddies), list);
126
b4cd83f1d0b8 [gaim-migrate @ 136]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 124
diff changeset
114 list = GTK_TREE(buddies)->children;
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
115 if (!list)
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
116 break;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
117 }
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
118 list = list->next;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
119 }
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
120
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
121 item = gtk_tree_item_new_with_label("Mail Server");
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
122 tree = gtk_tree_new();
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
123 gtk_widget_show(item);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
124 gtk_widget_show(tree);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
125 gtk_tree_append(GTK_TREE(buddies), item);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
126 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), tree);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
127 gtk_tree_item_expand(GTK_TREE_ITEM(item));
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
128
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
129 buf = g_malloc(BUF_LONG);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
130
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
131 g_snprintf(buf, BUF_LONG, "%s (%d new/%d total)", mailhost, lastnum - orig, lastnum);
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
132 item = gtk_tree_item_new_with_label(buf);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
133 g_free(buf);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
134
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
135 gtk_tree_append(GTK_TREE(tree), item);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
136 gtk_widget_show(item);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
137 }
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
138
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
139 void gaim_plugin_init(void *h) {
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
140 handle = h;
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
141
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
142 orig = num_msgs();
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
143 lastnum = orig;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
144
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
145 gaim_signal_connect(handle, event_blist_update, setup_mail_list, NULL);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
146 setup_mail_list();
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
147
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
148 mytimer = gtk_timeout_add(30000, (GtkFunction)check_mail, NULL);
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
149 }
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
150
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
151 void check_mail() {
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
152 pthread_t mail_thread;
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
153 pthread_attr_t attr;
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
154
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
155 printf("Looping in: State = %d\n", state);
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
156 if (state == 0) {
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
157 state = 1;
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
158 printf("Before\n");
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
159 pthread_attr_init(&attr);
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
160 pthread_create(&mail_thread, &attr, (void *)&update_mail, NULL);
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
161 printf("After\n");
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
162 }
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
163 printf("Bouncing out, state = %d\n", state);
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
164 }
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
165
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
166 void update_mail () {
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
167 int newnum;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
168
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
169 printf("um\n");
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
170 gtk_timeout_remove(mytimer);
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
171
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
172 printf("nm1\n");
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
173 newnum = num_msgs();
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
174
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
175 printf("nm2\n");
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
176 if ( (newnum >= lastnum) && (newnum > 0)) {
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
177 newnum = newnum - lastnum;
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
178 } else {
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
179 newnum = 0;
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
180 }
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
181
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
182 if (newnum < lastnum) {
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
183 orig = lastnum;
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
184 }
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
185
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
186 lastnum = newnum;
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
187 mytimer = gtk_timeout_add(30000, (GtkFunction)check_mail, NULL);
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
188 printf("sml1\n");
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
189 setup_mail_list();
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
190 printf("sml2\n");
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
191 state = 0;
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
192 }
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
193
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
194
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
195 void gaim_plugin_remove() {
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
196 gtk_timeout_remove(mytimer);
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
197 while (state == 1) { }
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
198 destroy_mail_list();
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
199 handle = NULL;
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
200 }
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
201
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
202 char *name() {
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
203 return "Check Mail";
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
204 }
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
205
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
206 char *description() {
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
207 return "Check email every X seconds.\n";
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
208 }