Mercurial > pidgin.yaz
annotate plugins/chkmail.c @ 126:b4cd83f1d0b8
[gaim-migrate @ 136]
I think this fixed the segfaults.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Sun, 16 Apr 2000 03:14:33 +0000 |
parents | 5f294f7c4f2e |
children | 1330d0c8b1ff |
rev | line source |
---|---|
114 | 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. :) | |
3 */ | |
4 | |
105 | 5 #define GAIM_PLUGINS |
6 | |
7 #include <stdio.h> | |
114 | 8 #include <stdlib.h> |
9 #include <unistd.h> | |
10 #include <string.h> | |
11 #include <netinet/in.h> | |
12 #include <arpa/inet.h> | |
13 #include <sys/socket.h> | |
14 #include <netdb.h> | |
15 #include <netinet/in.h> | |
105 | 16 #include "gaim.h" |
17 | |
114 | 18 char username[] = ""; |
19 char password[] = ""; | |
20 char mailhost[] = ""; | |
21 int mailport = 110; | |
22 | |
105 | 23 static void *handle = NULL; |
24 extern GtkWidget *blist; | |
124 | 25 extern GtkWidget *buddies; |
114 | 26 |
105 | 27 GList *tmp; |
114 | 28 int lastnum = 0; |
29 int orig = 0; | |
30 int mytimer; | |
31 | |
32 void update_mail(); | |
33 | |
34 int num_msgs() | |
35 { | |
36 struct in_addr *sin; | |
37 char recv[1024]; | |
38 char command[256]; | |
39 int fd; | |
40 int num = 0; | |
41 int step = 0; | |
42 int len; | |
43 | |
44 sin = (struct in_addr *)get_address(mailhost); | |
45 fd = connect_address(sin->s_addr, mailport); | |
46 while ((len = read(fd, recv, 1023))>0) { | |
47 recv[len] = 0; | |
48 if (!strncmp(recv, "-ERR", strlen("-ERR"))) { step = 4; break; | |
49 } else if (!strncmp(recv, "+OK", strlen("+OK"))) { | |
50 if (step == 3) { | |
51 if (sscanf(recv, "+OK %d %d\n", &num, &step) != 2) | |
52 break; | |
53 g_snprintf(command, sizeof(command), "QUIT\n"); | |
54 write(fd, command, strlen(command)); | |
55 close(fd); | |
56 return num; | |
57 } | |
58 | |
59 if (step == 0) { | |
60 g_snprintf(command, sizeof(command), "USER %s\n", username); | |
61 write(fd, command, strlen(command)); | |
62 step = 1; | |
63 } else if (step == 1) { | |
64 g_snprintf(command, sizeof(command), "PASS %s\n", password); | |
65 write(fd, command, strlen(command)); | |
66 step = 2; | |
67 } else if (step == 2) { | |
68 g_snprintf(command, sizeof(command), "STAT\n"); | |
69 write(fd, command, strlen(command)); | |
70 step = 3; | |
71 } | |
72 } | |
73 } | |
74 close(fd); | |
75 return 0; | |
76 } | |
105 | 77 |
124 | 78 void destroy_mail_list() |
79 { | |
80 GList *list; | |
81 GtkWidget *w; | |
82 | |
83 list = GTK_TREE(buddies)->children; | |
84 | |
85 while (list) { | |
86 w = (GtkWidget *)list->data; | |
87 if (!strcmp(GTK_LABEL(GTK_BIN(w)->child)->label, "Mail Server")) { | |
88 gtk_tree_remove_items(GTK_TREE(buddies), list); | |
126
b4cd83f1d0b8
[gaim-migrate @ 136]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
124
diff
changeset
|
89 list = GTK_TREE(buddies)->children; |
124 | 90 if (!list) |
91 break; | |
92 } | |
93 list = list->next; | |
94 } | |
95 } | |
96 | |
97 | |
98 void setup_mail_list() | |
99 { | |
100 GList *list; | |
101 GtkWidget *w; | |
102 GtkWidget *item; | |
103 GtkWidget *tree; | |
104 gchar *buf; | |
105 | |
106 list = GTK_TREE(buddies)->children; | |
107 | |
108 while (list) { | |
109 w = (GtkWidget *)list->data; | |
110 if (!strcmp(GTK_LABEL(GTK_BIN(w)->child)->label, "Mail Server")) { | |
111 gtk_tree_remove_items(GTK_TREE(buddies), list); | |
126
b4cd83f1d0b8
[gaim-migrate @ 136]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
124
diff
changeset
|
112 list = GTK_TREE(buddies)->children; |
124 | 113 if (!list) |
114 break; | |
115 } | |
116 list = list->next; | |
117 } | |
118 | |
119 item = gtk_tree_item_new_with_label("Mail Server"); | |
120 tree = gtk_tree_new(); | |
121 gtk_widget_show(item); | |
122 gtk_widget_show(tree); | |
123 gtk_tree_append(GTK_TREE(buddies), item); | |
124 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), tree); | |
125 gtk_tree_item_expand(GTK_TREE_ITEM(item)); | |
126 | |
127 buf = g_malloc(BUF_LONG); | |
128 | |
129 g_snprintf(buf, BUF_LONG, "%s (%d/%d)", mailhost, lastnum - orig, orig); | |
130 item = gtk_tree_item_new_with_label(buf); | |
131 g_free(buf); | |
132 | |
133 gtk_tree_append(GTK_TREE(tree), item); | |
134 gtk_widget_show(item); | |
135 } | |
136 | |
105 | 137 void gaim_plugin_init(void *h) { |
138 handle = h; | |
139 tmp = gtk_container_children(GTK_CONTAINER(blist)); | |
140 | |
114 | 141 orig = num_msgs(); |
142 lastnum = orig; | |
143 | |
124 | 144 gaim_signal_connect(handle, event_blist_update, setup_mail_list, NULL); |
145 setup_mail_list(); | |
146 | |
114 | 147 mytimer = gtk_timeout_add(30000, (GtkFunction)update_mail, NULL); |
105 | 148 } |
149 | |
114 | 150 void update_mail () { |
151 int newnum; | |
152 | |
153 gtk_timeout_remove(mytimer); | |
154 | |
155 newnum = num_msgs(); | |
156 | |
157 if ( (newnum >= lastnum) && (newnum > 0)) { | |
124 | 158 newnum = newnum - orig; |
114 | 159 } else { |
124 | 160 newnum = 0; |
114 | 161 } |
162 | |
163 if (newnum < lastnum) { | |
164 orig = 0; | |
165 } | |
166 | |
167 lastnum = newnum; | |
168 mytimer = gtk_timeout_add(30000, (GtkFunction)update_mail, NULL); | |
124 | 169 setup_mail_list(); |
114 | 170 } |
171 | |
172 | |
105 | 173 void gaim_plugin_remove() { |
124 | 174 gtk_timeout_remove(mytimer); |
175 destroy_mail_list(); | |
105 | 176 handle = NULL; |
177 } | |
178 | |
179 char *name() { | |
180 return "Check Mail"; | |
181 } | |
182 | |
183 char *description() { | |
184 return "Check email every X seconds.\n"; | |
185 } |