comparison plugins/chkmail.c @ 127:1330d0c8b1ff

[gaim-migrate @ 137] Hmm committer: Tailor Script <tailor@pidgin.im>
author Rob Flynn <gaim@robflynn.com>
date Mon, 17 Apr 2000 05:47:20 +0000
parents b4cd83f1d0b8
children ebfb80bbe1ed
comparison
equal deleted inserted replaced
126:b4cd83f1d0b8 127:1330d0c8b1ff
11 #include <netinet/in.h> 11 #include <netinet/in.h>
12 #include <arpa/inet.h> 12 #include <arpa/inet.h>
13 #include <sys/socket.h> 13 #include <sys/socket.h>
14 #include <netdb.h> 14 #include <netdb.h>
15 #include <netinet/in.h> 15 #include <netinet/in.h>
16 #include <pthread.h>
16 #include "gaim.h" 17 #include "gaim.h"
17 18
18 char username[] = ""; 19 char username[] = "";
19 char password[] = ""; 20 char password[] = "";
20 char mailhost[] = ""; 21 char mailhost[] = "";
21 int mailport = 110; 22 int mailport = 110;
23 int state = 0;
22 24
23 static void *handle = NULL; 25 static void *handle = NULL;
24 extern GtkWidget *blist;
25 extern GtkWidget *buddies; 26 extern GtkWidget *buddies;
26 27
27 GList *tmp;
28 int lastnum = 0; 28 int lastnum = 0;
29 int orig = 0; 29 int orig = 0;
30 int mytimer; 30 int mytimer;
31 31
32 void update_mail(); 32 void update_mail();
33 void check_mail();
33 34
34 int num_msgs() 35 int num_msgs()
35 { 36 {
36 struct in_addr *sin; 37 struct in_addr *sin;
37 char recv[1024]; 38 char recv[1024];
51 if (sscanf(recv, "+OK %d %d\n", &num, &step) != 2) 52 if (sscanf(recv, "+OK %d %d\n", &num, &step) != 2)
52 break; 53 break;
53 g_snprintf(command, sizeof(command), "QUIT\n"); 54 g_snprintf(command, sizeof(command), "QUIT\n");
54 write(fd, command, strlen(command)); 55 write(fd, command, strlen(command));
55 close(fd); 56 close(fd);
57 printf("DEBUG: Num is %d\n", num);
56 return num; 58 return num;
57 } 59 }
58 60
59 if (step == 0) { 61 if (step == 0) {
60 g_snprintf(command, sizeof(command), "USER %s\n", username); 62 g_snprintf(command, sizeof(command), "USER %s\n", username);
124 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), tree); 126 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), tree);
125 gtk_tree_item_expand(GTK_TREE_ITEM(item)); 127 gtk_tree_item_expand(GTK_TREE_ITEM(item));
126 128
127 buf = g_malloc(BUF_LONG); 129 buf = g_malloc(BUF_LONG);
128 130
129 g_snprintf(buf, BUF_LONG, "%s (%d/%d)", mailhost, lastnum - orig, orig); 131 g_snprintf(buf, BUF_LONG, "%s (%d new/%d total)", mailhost, lastnum - orig, lastnum);
130 item = gtk_tree_item_new_with_label(buf); 132 item = gtk_tree_item_new_with_label(buf);
131 g_free(buf); 133 g_free(buf);
132 134
133 gtk_tree_append(GTK_TREE(tree), item); 135 gtk_tree_append(GTK_TREE(tree), item);
134 gtk_widget_show(item); 136 gtk_widget_show(item);
135 } 137 }
136 138
137 void gaim_plugin_init(void *h) { 139 void gaim_plugin_init(void *h) {
138 handle = h; 140 handle = h;
139 tmp = gtk_container_children(GTK_CONTAINER(blist));
140 141
141 orig = num_msgs(); 142 orig = num_msgs();
142 lastnum = orig; 143 lastnum = orig;
143 144
144 gaim_signal_connect(handle, event_blist_update, setup_mail_list, NULL); 145 gaim_signal_connect(handle, event_blist_update, setup_mail_list, NULL);
145 setup_mail_list(); 146 setup_mail_list();
146 147
147 mytimer = gtk_timeout_add(30000, (GtkFunction)update_mail, NULL); 148 mytimer = gtk_timeout_add(30000, (GtkFunction)check_mail, NULL);
149 }
150
151 void check_mail() {
152 pthread_t mail_thread;
153 pthread_attr_t attr;
154
155 printf("Looping in: State = %d\n", state);
156 if (state == 0) {
157 state = 1;
158 printf("Before\n");
159 pthread_attr_init(&attr);
160 pthread_create(&mail_thread, &attr, (void *)&update_mail, NULL);
161 printf("After\n");
162 }
163 printf("Bouncing out, state = %d\n", state);
148 } 164 }
149 165
150 void update_mail () { 166 void update_mail () {
151 int newnum; 167 int newnum;
152 168
169 printf("um\n");
153 gtk_timeout_remove(mytimer); 170 gtk_timeout_remove(mytimer);
154 171
172 printf("nm1\n");
155 newnum = num_msgs(); 173 newnum = num_msgs();
156 174
175 printf("nm2\n");
157 if ( (newnum >= lastnum) && (newnum > 0)) { 176 if ( (newnum >= lastnum) && (newnum > 0)) {
158 newnum = newnum - orig; 177 newnum = newnum - lastnum;
159 } else { 178 } else {
160 newnum = 0; 179 newnum = 0;
161 } 180 }
162 181
163 if (newnum < lastnum) { 182 if (newnum < lastnum) {
164 orig = 0; 183 orig = lastnum;
165 } 184 }
166 185
167 lastnum = newnum; 186 lastnum = newnum;
168 mytimer = gtk_timeout_add(30000, (GtkFunction)update_mail, NULL); 187 mytimer = gtk_timeout_add(30000, (GtkFunction)check_mail, NULL);
188 printf("sml1\n");
169 setup_mail_list(); 189 setup_mail_list();
190 printf("sml2\n");
191 state = 0;
170 } 192 }
171 193
172 194
173 void gaim_plugin_remove() { 195 void gaim_plugin_remove() {
174 gtk_timeout_remove(mytimer); 196 gtk_timeout_remove(mytimer);
197 while (state == 1) { }
175 destroy_mail_list(); 198 destroy_mail_list();
176 handle = NULL; 199 handle = NULL;
177 } 200 }
178 201
179 char *name() { 202 char *name() {