1 /* This is some funky code. It is still being developed by Rob Flynn - rob@linuxpimps.com
2 * I recommend not using this code right now. :)
11 #include <netinet/in.h>
12 #include <arpa/inet.h>
13 #include <sys/socket.h>
15 #include <netinet/in.h>
25 static void *handle
= NULL
;
26 extern GtkWidget
*buddies
;
45 sin
= (struct in_addr
*)get_address(mailhost
);
46 fd
= connect_address(sin
->s_addr
, mailport
);
47 while ((len
= read(fd
, recv
, 1023))>0) {
49 if (!strncmp(recv
, "-ERR", strlen("-ERR"))) { step
= 4; break;
50 } else if (!strncmp(recv
, "+OK", strlen("+OK"))) {
52 if (sscanf(recv
, "+OK %d %d\n", &num
, &step
) != 2)
54 g_snprintf(command
, sizeof(command
), "QUIT\n");
55 write(fd
, command
, strlen(command
));
57 printf("DEBUG: Num is %d\n", num
);
62 g_snprintf(command
, sizeof(command
), "USER %s\n", username
);
63 write(fd
, command
, strlen(command
));
65 } else if (step
== 1) {
66 g_snprintf(command
, sizeof(command
), "PASS %s\n", password
);
67 write(fd
, command
, strlen(command
));
69 } else if (step
== 2) {
70 g_snprintf(command
, sizeof(command
), "STAT\n");
71 write(fd
, command
, strlen(command
));
80 void destroy_mail_list()
85 list
= GTK_TREE(buddies
)->children
;
88 w
= (GtkWidget
*)list
->data
;
89 if (!strcmp(GTK_LABEL(GTK_BIN(w
)->child
)->label
, "Mail Server")) {
90 gtk_tree_remove_items(GTK_TREE(buddies
), list
);
91 list
= GTK_TREE(buddies
)->children
;
100 void setup_mail_list()
108 list
= GTK_TREE(buddies
)->children
;
111 w
= (GtkWidget
*)list
->data
;
112 if (!strcmp(GTK_LABEL(GTK_BIN(w
)->child
)->label
, "Mail Server")) {
113 gtk_tree_remove_items(GTK_TREE(buddies
), list
);
114 list
= GTK_TREE(buddies
)->children
;
121 item
= gtk_tree_item_new_with_label("Mail Server");
122 tree
= gtk_tree_new();
123 gtk_widget_show(item
);
124 gtk_widget_show(tree
);
125 gtk_tree_append(GTK_TREE(buddies
), item
);
126 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item
), tree
);
127 gtk_tree_item_expand(GTK_TREE_ITEM(item
));
129 buf
= g_malloc(BUF_LONG
);
131 g_snprintf(buf
, BUF_LONG
, "%s (%d new/%d total)", mailhost
, lastnum
- orig
, lastnum
);
132 item
= gtk_tree_item_new_with_label(buf
);
135 gtk_tree_append(GTK_TREE(tree
), item
);
136 gtk_widget_show(item
);
139 void gaim_plugin_init(void *h
) {
145 gaim_signal_connect(handle
, event_blist_update
, setup_mail_list
, NULL
);
148 mytimer
= g_timeout_add(30000, check_mail
, NULL
);
152 pthread_t mail_thread
;
155 printf("Looping in: State = %d\n", state
);
159 pthread_attr_init(&attr
);
160 pthread_create(&mail_thread
, &attr
, (void *)&update_mail
, NULL
);
163 printf("Bouncing out, state = %d\n", state
);
166 void update_mail () {
170 g_source_remove(mytimer
);
176 if ( (newnum
>= lastnum
) && (newnum
> 0)) {
177 newnum
= newnum
- lastnum
;
182 if (newnum
< lastnum
) {
187 mytimer
= g_timeout_add(30000, check_mail
, NULL
);
195 void gaim_plugin_remove() {
196 g_source_remove(mytimer
);
197 while (state
== 1) { }
206 char *description() {
207 return "Check email every X seconds.\n";